Skip to content

Commit

Permalink
Normalize path before checking if path should be ignored (#7080)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Sassoulas <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 28, 2022
1 parent c603f0e commit c74493b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/whatsnew/2/2.14/full.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ What's New in Pylint 2.14.4?
----------------------------
Release date: TBA

* Fixed an issue where scanning `.` directory recursively with ``--ignore-path=^path/to/dir`` is not
ignoring the `path/to/dir` directory.

Closes #6964

* Fixed regression that didn't allow quoted ``init-hooks`` in option files.

Closes #7006
Expand Down
1 change: 1 addition & 0 deletions pylint/lint/expand_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def _is_ignored_file(
ignore_list_re: list[Pattern[str]],
ignore_list_paths_re: list[Pattern[str]],
) -> bool:
element = os.path.normpath(element)
basename = os.path.basename(element)
return (
basename in ignore_list
Expand Down
21 changes: 21 additions & 0 deletions tests/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,27 @@ def test_recursive_current_dir(self):
code=0,
)

def test_ignore_path_recursive_current_dir(self) -> None:
"""Tests that path is normalized before checked that is ignored. GitHub issue #6964"""
with _test_sys_path():
# pytest is including directory HERE/regrtest_data to sys.path which causes
# astroid to believe that directory is a package.
sys.path = [
path
for path in sys.path
if not os.path.basename(path) == "regrtest_data"
]
with _test_cwd():
os.chdir(join(HERE, "regrtest_data", "directory"))
self._runtest(
[
".",
"--recursive=y",
"--ignore-paths=^ignored_subdirectory/.*",
],
code=0,
)

def test_regression_recursive_current_dir(self):
with _test_sys_path():
# pytest is including directory HERE/regrtest_data to sys.path which causes
Expand Down

0 comments on commit c74493b

Please sign in to comment.