From 9f8dfd924a03aeeea19ba270e75e56b1bbebaff1 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Sun, 22 Jan 2017 15:00:48 -0600 Subject: [PATCH] Return similarly named, non-submodule modules In our setuptools integration command, we were attempting to avoid checking each submodule in the packages list. This was done without recognizing that two modules may start with the same prefix, e.g., - foo - foo_bar - foo_biz In this case, we only ever checked ``foo``. By appending a '.' to the end of each package name, we avoid this since we only care about deduplicating submodules, e.g., - foo - foo.sub - foo.sub.sub Closes #295 --- src/flake8/main/setuptools_command.py | 2 +- tests/unit/test_setuptools_command.py | 34 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/unit/test_setuptools_command.py diff --git a/src/flake8/main/setuptools_command.py b/src/flake8/main/setuptools_command.py index ba5a260..a5d23a5 100644 --- a/src/flake8/main/setuptools_command.py +++ b/src/flake8/main/setuptools_command.py @@ -66,7 +66,7 @@ class Flake8(setuptools.Command): if package_directory.startswith(seen_package_directories): continue - seen_package_directories += (package_directory,) + seen_package_directories += (package_directory + '.',) yield package_directory def module_files(self): diff --git a/tests/unit/test_setuptools_command.py b/tests/unit/test_setuptools_command.py new file mode 100644 index 0000000..40c9733 --- /dev/null +++ b/tests/unit/test_setuptools_command.py @@ -0,0 +1,34 @@ +"""Module containing tests for the setuptools command integration.""" +import pytest + +from setuptools import dist + +from flake8.main import setuptools_command + + +@pytest.fixture +def distribution(): + """Create a setuptools Distribution object.""" + return dist.Distribution({ + 'name': 'foo', + 'packages': [ + 'foo', + 'foo.bar', + 'foo_biz', + ], + }) + + +@pytest.fixture +def command(distribution): + """Create an instance of Flake8's setuptools command.""" + return setuptools_command.Flake8(distribution) + + +def test_package_files_removes_submodules(command): + """Verify that we collect all package files.""" + package_files = list(command.package_files()) + assert sorted(package_files) == [ + 'foo', + 'foo_biz', + ]