From 1ba56b9056fd60dbb0f991fe5a4ac0bb6ad85cb9 Mon Sep 17 00:00:00 2001 From: "Eric N. Vander Weele" Date: Sun, 28 Jul 2019 10:39:27 -0400 Subject: [PATCH] utils: Change `normalize_paths()` contract MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `normalize_paths()` utility was doing too much — parsing unstructured configuration path data and dispatching the scrubbed paths to be normalized. Towards moving the parsing of unstructured configuration path data closer towards were configuration occurs, have the utility accept only structured input for normalizing paths. --- docs/source/internal/utils.rst | 6 +++--- src/flake8/utils.py | 8 +++----- tests/unit/test_utils.py | 7 +++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/docs/source/internal/utils.rst b/docs/source/internal/utils.rst index 2b2638e..fed9a47 100644 --- a/docs/source/internal/utils.rst +++ b/docs/source/internal/utils.rst @@ -45,9 +45,9 @@ path if the string has a ``/`` in it. It also removes trailing ``/``\ s. .. autofunction:: flake8.utils.normalize_paths -This function utilizes :func:`~flake8.utils.parse_comma_separated_list` and -:func:`~flake8.utils.normalize_path` to normalize its input to a list of -strings that should be paths. +This function utilizes :func:`~flake8.utils.normalize_path` to normalize a +sequence of paths. See :func:`~flake8.utils.normalize_path` for what defines a +normalized path. .. autofunction:: flake8.utils.stdin_get_value diff --git a/src/flake8/utils.py b/src/flake8/utils.py index bb6ba2e..5ed78e1 100644 --- a/src/flake8/utils.py +++ b/src/flake8/utils.py @@ -160,8 +160,8 @@ def parse_files_to_codes_mapping(value_): # noqa: C901 def normalize_paths(paths, parent=os.curdir): - # type: (Union[Sequence[str], str], str) -> List[str] - """Parse a comma-separated list of paths. + # type: (Sequence[str], str) -> List[str] + """Normalize a list of paths relative to a parent directory. :returns: The normalized paths. @@ -169,9 +169,7 @@ def normalize_paths(paths, parent=os.curdir): [str] """ assert isinstance(paths, list), paths # nosec (for bandit) - return [ - normalize_path(p, parent) for p in parse_comma_separated_list(paths) - ] + return [normalize_path(p, parent) for p in paths] def normalize_path(path, parent=os.curdir): diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index b4bd1a1..9fd03b2 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -127,14 +127,13 @@ def test_normalize_path(value, expected): @pytest.mark.parametrize("value,expected", [ - ("flake8,pep8,pyflakes,mccabe", ["flake8", "pep8", "pyflakes", "mccabe"]), - ("flake8,\n\tpep8,\n pyflakes,\n\n mccabe", + (["flake8", "pep8", "pyflakes", "mccabe"], ["flake8", "pep8", "pyflakes", "mccabe"]), - ("../flake8,../pep8,../pyflakes,../mccabe", + (["../flake8", "../pep8", "../pyflakes", "../mccabe"], [os.path.abspath("../" + p) for p in RELATIVE_PATHS]), ]) def test_normalize_paths(value, expected): - """Verify we normalize comma-separated paths provided to the tool.""" + """Verify we normalizes a sequence of paths provided to the tool.""" assert utils.normalize_paths(value) == expected