summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2022-05-09 09:05:56 +0200
committerGitHub <noreply@github.com>2022-05-09 09:05:56 +0200
commitf020b2f07361fa2b577bc07c4a68309905bd46ae (patch)
treea1d1880451fac270df94ce861677e736b2c9163c
parent40ddfabcb0afe5dadab3c4dcd890b8302db9edd0 (diff)
downloadpylint-git-f020b2f07361fa2b577bc07c4a68309905bd46ae.tar.gz
Revert "Do not append namespace packages to sys.path (#6405)" (#6548)
This reverts commit 603be8408a5d2d98283f41cfd9a94998fd7cfd3c.
-rw-r--r--ChangeLog10
-rw-r--r--doc/whatsnew/2.14.rst7
-rw-r--r--pylint/lint/utils.py19
-rw-r--r--tests/lint/test_namespace_packages.py25
-rw-r--r--tests/lint/unittest_expand_modules.py8
-rw-r--r--tests/regrtest_data/namespace_import_self/else/__init__.py0
-rw-r--r--tests/regrtest_data/namespace_import_self/pylint/__init__.py5
7 files changed, 0 insertions, 74 deletions
diff --git a/ChangeLog b/ChangeLog
index 245910e58..d03570e33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -25,16 +25,6 @@ Release date: TBA
Closes #4301
-* By default the similarity checker will now ignore imports and ignore function signatures when computing
- duplication. If you want to keep the previous behaviour set ``ignore-imports`` and ``ignore-signatures`` to ``False``.
-
-* Improved recognition of namespace packages. They should no longer be added to ``sys.path``
- which should prevent various issues with false positives.
- Because of the difficulties with mirroring the python import mechanics we would gladly
- hear feedback on this change.
-
- Closes #5226, Closes #2648
-
* ``BaseChecker`` classes now require the ``linter`` argument to be passed.
* Fix a failure to respect inline disables for ``fixme`` occurring on the last line
diff --git a/doc/whatsnew/2.14.rst b/doc/whatsnew/2.14.rst
index 4f8d8a126..b532e1dd1 100644
--- a/doc/whatsnew/2.14.rst
+++ b/doc/whatsnew/2.14.rst
@@ -129,13 +129,6 @@ Other Changes
Closes #4301
-* Improved recognition of namespace packages. They should no longer be added to ``sys.path``
- which should prevent various issues with false positives.
- Because of the difficulties with mirroring the python import mechanics we would gladly
- hear feedback on this change.
-
- Closes #5226, Closes #2648
-
* Update ``invalid-slots-object`` message to show bad object rather than its inferred value.
Closes #6101
diff --git a/pylint/lint/utils.py b/pylint/lint/utils.py
index a08cd6d2a..30694c25c 100644
--- a/pylint/lint/utils.py
+++ b/pylint/lint/utils.py
@@ -11,8 +11,6 @@ from collections.abc import Iterator, Sequence
from datetime import datetime
from pathlib import Path
-from astroid import modutils
-
from pylint.config import PYLINT_HOME
from pylint.lint.expand_modules import get_python_path
@@ -73,29 +71,12 @@ def get_fatal_error_message(filepath: str, issue_template_path: Path) -> str:
)
-def _is_part_of_namespace_package(filename: str) -> bool:
- """Check if a file is part of a namespace package."""
- try:
- modname = modutils.modpath_from_file(filename)
- except ImportError:
- modname = [Path(filename).stem]
-
- try:
- spec = modutils.file_info_from_modpath(modname)
- except ImportError:
- return False
-
- return modutils.is_namespace(spec)
-
-
def _patch_sys_path(args: Sequence[str]) -> list[str]:
original = list(sys.path)
changes = []
seen = set()
for arg in args:
path = get_python_path(arg)
- if _is_part_of_namespace_package(path):
- continue
if path not in seen:
changes.append(path)
seen.add(path)
diff --git a/tests/lint/test_namespace_packages.py b/tests/lint/test_namespace_packages.py
deleted file mode 100644
index 6ac96f09e..000000000
--- a/tests/lint/test_namespace_packages.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
-# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
-# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
-
-"""Tests related to linting of namespace packages."""
-
-from io import StringIO
-
-from pylint.reporters.text import TextReporter
-from pylint.testutils._run import _Run as Run
-
-
-def test_namespace_package_sys_path() -> None:
- """Test that we do not append namespace packages to sys.path.
-
- The test package is based on https://github.com/PyCQA/pylint/issues/2648.
- """
- pylint_output = StringIO()
- reporter = TextReporter(pylint_output)
- runner = Run(
- ["tests/regrtest_data/namespace_import_self/"],
- reporter=reporter,
- exit=False,
- )
- assert not runner.linter.stats.by_msg
diff --git a/tests/lint/unittest_expand_modules.py b/tests/lint/unittest_expand_modules.py
index 1ce5b6c4e..15f72d0c5 100644
--- a/tests/lint/unittest_expand_modules.py
+++ b/tests/lint/unittest_expand_modules.py
@@ -77,13 +77,6 @@ test_caching = {
"path": str(TEST_DIRECTORY / "lint/test_caching.py"),
}
-test_namespace_packages = {
- "basename": "lint",
- "basepath": INIT_PATH,
- "isarg": False,
- "name": "lint.test_namespace_packages",
- "path": str(TEST_DIRECTORY / "lint/test_namespace_packages.py"),
-}
init_of_package = {
"basename": "lint",
@@ -115,7 +108,6 @@ class TestExpandModules(CheckerTestCase):
[
init_of_package,
test_caching,
- test_namespace_packages,
test_pylinter,
test_utils,
this_file_from_init,
diff --git a/tests/regrtest_data/namespace_import_self/else/__init__.py b/tests/regrtest_data/namespace_import_self/else/__init__.py
deleted file mode 100644
index e69de29bb..000000000
--- a/tests/regrtest_data/namespace_import_self/else/__init__.py
+++ /dev/null
diff --git a/tests/regrtest_data/namespace_import_self/pylint/__init__.py b/tests/regrtest_data/namespace_import_self/pylint/__init__.py
deleted file mode 100644
index cce5e5302..000000000
--- a/tests/regrtest_data/namespace_import_self/pylint/__init__.py
+++ /dev/null
@@ -1,5 +0,0 @@
-"""Module that imports from its own namespace."""
-
-from pylint import run_pylint
-
-run_pylint()