Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate module file paths to prevent redundant scans. #7747

Merged
merged 20 commits into from Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9e345ba
Deduplicate module file paths to prevent redundant scans.
emcd Nov 11, 2022
cb1eaab
Merge branch 'PyCQA:main' into main
emcd Nov 12, 2022
0538ffd
Use dict for 'expand_modules' result rather than list.
emcd Nov 12, 2022
4bcbcc4
Update towncrier description for patch.
emcd Nov 12, 2022
387c240
Fix deduplication to account for CLI args marker. Add unit test for d…
emcd Nov 12, 2022
5a6d70b
Fix corner case with CLI arg flag handling during deduplication. Also…
emcd Nov 12, 2022
887eafb
Merge branch 'PyCQA:main' into main
emcd Nov 12, 2022
e2e326d
Factor out package module list for 'expand_modules' unit tests.
emcd Nov 13, 2022
08b9e1d
Add 'deduplication' to custom Pyenchant dict.
emcd Nov 13, 2022
2165ddf
Merge branch 'PyCQA:main' into main
emcd Nov 15, 2022
c59248b
Appease Mypy. Improve accuracy of comment.
emcd Nov 15, 2022
d0f66ef
Merge branch 'PyCQA:main' into main
emcd Nov 17, 2022
3d147e3
Integration Test: Pylint argument deduplication with highly constrain…
emcd Nov 17, 2022
dffd61d
Appease Pyenchant.
emcd Nov 17, 2022
e45a731
Use 'too-many-branches' functional test file as target for deduplicat…
emcd Nov 18, 2022
d641d69
Merge branch 'PyCQA:main' into main
emcd Nov 18, 2022
82948a0
Appease Pyenchant. Again.
emcd Nov 18, 2022
7a8fe98
Update tests/test_pylint_runners.py
Pierre-Sassoulas Nov 18, 2022
ae05856
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 18, 2022
c67f204
Update tests/test_pylint_runners.py
Pierre-Sassoulas Nov 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions pylint/lint/expand_modules.py
Expand Up @@ -120,13 +120,16 @@ def expand_modules(
is_namespace = modutils.is_namespace(spec)
is_directory = modutils.is_directory(spec)
if not is_namespace:
result[filepath] = {
"path": filepath,
"name": modname,
"isarg": True,
"basepath": filepath,
"basename": modname,
}
if filepath in result:
result[filepath]["isarg"] = True
else:
result[filepath] = {
"path": filepath,
"name": modname,
"isarg": True,
"basepath": filepath,
"basename": modname,
}
has_init = (
not (modname.endswith(".__init__") or modname == "__init__")
and os.path.basename(filepath) == "__init__.py"
Expand All @@ -149,7 +152,7 @@ def expand_modules(
result[subfilepath] = {
"path": subfilepath,
"name": submodname,
"isarg": False,
"isarg": subfilepath in result,
"basepath": filepath,
"basename": modname,
}
Expand Down
46 changes: 45 additions & 1 deletion tests/lint/unittest_expand_modules.py
Expand Up @@ -45,6 +45,14 @@ def test__is_in_ignore_list_re_match() -> None:
"path": EXPAND_MODULES,
}

this_file_from_init_deduplicated = {
"basename": "lint",
"basepath": INIT_PATH,
"isarg": True,
"name": "lint.unittest_expand_modules",
"path": EXPAND_MODULES,
}

unittest_lint = {
"basename": "lint",
"basepath": INIT_PATH,
Expand Down Expand Up @@ -123,7 +131,43 @@ class Checker(BaseChecker):
def test_expand_modules(
self, files_or_modules: list[str], expected: dict[str, ModuleDescriptionDict]
) -> None:
"""Test expand_modules with the default value of ignore-paths."""
"""Test expand_modules with deduplication and the default value of ignore-paths."""
ignore_list: list[str] = []
ignore_list_re: list[re.Pattern[str]] = []
modules, errors = expand_modules(
files_or_modules,
ignore_list,
ignore_list_re,
self.linter.config.ignore_paths,
)
assert modules == expected
assert not errors

@pytest.mark.parametrize(
"files_or_modules,expected",
[
([__file__, __file__], {this_file["path"]: this_file}),
(
[EXPAND_MODULES, str(Path(__file__).parent), EXPAND_MODULES],
{
module["path"]: module # pylint: disable=unsubscriptable-object
for module in (
init_of_package,
test_caching,
test_pylinter,
test_utils,
this_file_from_init_deduplicated,
unittest_lint,
)
},
),
emcd marked this conversation as resolved.
Show resolved Hide resolved
],
)
@set_config(ignore_paths="")
def test_expand_modules_deduplication(
self, files_or_modules: list[str], expected: dict[str, ModuleDescriptionDict]
) -> None:
"""Test expand_modules deduplication."""
ignore_list: list[str] = []
ignore_list_re: list[re.Pattern[str]] = []
modules, errors = expand_modules(
Expand Down