detect-shadowed-modules 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- detect_shadowed_modules-0.2.0/README.md → detect_shadowed_modules-0.2.1/PKG-INFO +33 -5
- detect_shadowed_modules-0.2.0/PKG-INFO → detect_shadowed_modules-0.2.1/README.md +15 -16
- {detect_shadowed_modules-0.2.0 → detect_shadowed_modules-0.2.1}/detect_shadowed_modules/__init__.py +9 -2
- {detect_shadowed_modules-0.2.0 → detect_shadowed_modules-0.2.1}/detect_shadowed_modules/editable.py +2 -1
- detect_shadowed_modules-0.2.1/detect_shadowed_modules/version.py +34 -0
- detect_shadowed_modules-0.2.1/pyproject.toml +68 -0
- detect_shadowed_modules-0.2.1/pyproject.toml.orig +57 -0
- detect_shadowed_modules-0.2.0/pyproject.toml +0 -31
|
@@ -1,7 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: detect-shadowed-modules
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Detect conflicting directory names across Python's sys.path that shadow installed packages
|
|
5
|
+
Keywords: import,shadowing,diagnostics
|
|
6
|
+
Author: Michael Bianco
|
|
7
|
+
Author-email: Michael Bianco <mike@mikebian.co>
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Project-URL: Repository, https://github.com/iloveitaly/detect-shadowed-modules
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# Detect Python Shadowed Modules
|
|
2
20
|
|
|
3
21
|
Detect conflicting directory names across Python's `sys.path` that may be shadowing your installed packages.
|
|
4
22
|
|
|
23
|
+
Common cases where this happened:
|
|
24
|
+
|
|
25
|
+
* Using an editable package. All folders within the editable package dir (including `tests`) are
|
|
26
|
+
added to `sys.path` and there is no way to define precedence (at least, as of 2026-01-24 when using `uv`)
|
|
27
|
+
* A package that has been improperly packaged with something like a `tests` directory.
|
|
28
|
+
* There are two different types of Python package distributions: a source distribution and a built distribution.
|
|
29
|
+
A source distribution can be downloaded on PyPy using the tar.gzip, where a built distribution is the wheel with the extension `whl`.
|
|
30
|
+
These distributions may not use the same distribution script and can contain different contents.
|
|
31
|
+
|
|
32
|
+
If you like this project, you'll probably enjoy [uv-development-toggle](https://github.com/iloveitaly/uv-development-toggle)
|
|
5
33
|
## Problem
|
|
6
34
|
|
|
7
35
|
When Python imports a module, it searches directories in `sys.path` order. If the same directory name exists in multiple `sys.path` entries, only the first one is used—potentially shadowing packages you intended to import. This can lead to confusing import errors and unexpected behavior.
|
|
@@ -9,7 +37,7 @@ When Python imports a module, it searches directories in `sys.path` order. If th
|
|
|
9
37
|
### Example Conflict Scenario
|
|
10
38
|
|
|
11
39
|
```python
|
|
12
|
-
sys.path = [
|
|
40
|
+
sys.path = ["/project", "/usr/lib/python3/site-packages"]
|
|
13
41
|
```
|
|
14
42
|
|
|
15
43
|
If both paths contain a `requests/` directory:
|
|
@@ -38,11 +66,10 @@ uvx detect-shadowed-modules@latest --help
|
|
|
38
66
|
# Print conflicts to stdout with scanning progress
|
|
39
67
|
detect-shadowed-modules
|
|
40
68
|
|
|
69
|
+
detect-shadowed-modules --json
|
|
70
|
+
|
|
41
71
|
# Quiet mode (conflicts only, no progress messages)
|
|
42
72
|
detect-shadowed-modules -q
|
|
43
|
-
|
|
44
|
-
# Output as JSON
|
|
45
|
-
detect-shadowed-modules --json
|
|
46
73
|
```
|
|
47
74
|
|
|
48
75
|
### As a Python Module
|
|
@@ -122,6 +149,7 @@ The tool scans all directories in `sys.path` and:
|
|
|
122
149
|
6. Attempts to identify the installed package that owns each directory
|
|
123
150
|
|
|
124
151
|
Excluded from scanning:
|
|
152
|
+
|
|
125
153
|
- Hidden directories (starting with `.`)
|
|
126
154
|
- `__pycache__` directories
|
|
127
155
|
- Package metadata directories (`.dist-info`, `.egg-info`)
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
Name: detect-shadowed-modules
|
|
3
|
-
Version: 0.2.0
|
|
4
|
-
Summary: Detect conflicting directory names across Python's sys.path that shadow installed packages
|
|
5
|
-
Keywords: import,shadowing,diagnostics
|
|
6
|
-
Author: Michael Bianco
|
|
7
|
-
Author-email: Michael Bianco <mike@mikebian.co>
|
|
8
|
-
Requires-Python: >=3.11
|
|
9
|
-
Project-URL: Repository, https://github.com/iloveitaly/detect-shadowed-modules
|
|
10
|
-
Description-Content-Type: text/markdown
|
|
11
|
-
|
|
12
|
-
# detect-shadowed-modules
|
|
1
|
+
# Detect Python Shadowed Modules
|
|
13
2
|
|
|
14
3
|
Detect conflicting directory names across Python's `sys.path` that may be shadowing your installed packages.
|
|
15
4
|
|
|
5
|
+
Common cases where this happened:
|
|
6
|
+
|
|
7
|
+
* Using an editable package. All folders within the editable package dir (including `tests`) are
|
|
8
|
+
added to `sys.path` and there is no way to define precedence (at least, as of 2026-01-24 when using `uv`)
|
|
9
|
+
* A package that has been improperly packaged with something like a `tests` directory.
|
|
10
|
+
* There are two different types of Python package distributions: a source distribution and a built distribution.
|
|
11
|
+
A source distribution can be downloaded on PyPy using the tar.gzip, where a built distribution is the wheel with the extension `whl`.
|
|
12
|
+
These distributions may not use the same distribution script and can contain different contents.
|
|
13
|
+
|
|
14
|
+
If you like this project, you'll probably enjoy [uv-development-toggle](https://github.com/iloveitaly/uv-development-toggle)
|
|
16
15
|
## Problem
|
|
17
16
|
|
|
18
17
|
When Python imports a module, it searches directories in `sys.path` order. If the same directory name exists in multiple `sys.path` entries, only the first one is used—potentially shadowing packages you intended to import. This can lead to confusing import errors and unexpected behavior.
|
|
@@ -20,7 +19,7 @@ When Python imports a module, it searches directories in `sys.path` order. If th
|
|
|
20
19
|
### Example Conflict Scenario
|
|
21
20
|
|
|
22
21
|
```python
|
|
23
|
-
sys.path = [
|
|
22
|
+
sys.path = ["/project", "/usr/lib/python3/site-packages"]
|
|
24
23
|
```
|
|
25
24
|
|
|
26
25
|
If both paths contain a `requests/` directory:
|
|
@@ -49,11 +48,10 @@ uvx detect-shadowed-modules@latest --help
|
|
|
49
48
|
# Print conflicts to stdout with scanning progress
|
|
50
49
|
detect-shadowed-modules
|
|
51
50
|
|
|
51
|
+
detect-shadowed-modules --json
|
|
52
|
+
|
|
52
53
|
# Quiet mode (conflicts only, no progress messages)
|
|
53
54
|
detect-shadowed-modules -q
|
|
54
|
-
|
|
55
|
-
# Output as JSON
|
|
56
|
-
detect-shadowed-modules --json
|
|
57
55
|
```
|
|
58
56
|
|
|
59
57
|
### As a Python Module
|
|
@@ -133,6 +131,7 @@ The tool scans all directories in `sys.path` and:
|
|
|
133
131
|
6. Attempts to identify the installed package that owns each directory
|
|
134
132
|
|
|
135
133
|
Excluded from scanning:
|
|
134
|
+
|
|
136
135
|
- Hidden directories (starting with `.`)
|
|
137
136
|
- `__pycache__` directories
|
|
138
137
|
- Package metadata directories (`.dist-info`, `.egg-info`)
|
{detect_shadowed_modules-0.2.0 → detect_shadowed_modules-0.2.1}/detect_shadowed_modules/__init__.py
RENAMED
|
@@ -33,6 +33,8 @@ from pathlib import Path
|
|
|
33
33
|
|
|
34
34
|
from detect_shadowed_modules.editable import get_editable_paths
|
|
35
35
|
|
|
36
|
+
from .version import __version__
|
|
37
|
+
|
|
36
38
|
logger = logging.getLogger(__name__)
|
|
37
39
|
|
|
38
40
|
|
|
@@ -70,8 +72,7 @@ def get_subdirectories(path: Path) -> list[str]:
|
|
|
70
72
|
if (
|
|
71
73
|
name.startswith(".")
|
|
72
74
|
or name == "__pycache__"
|
|
73
|
-
or name.endswith(".dist-info")
|
|
74
|
-
or name.endswith(".egg-info")
|
|
75
|
+
or name.endswith((".dist-info", ".egg-info"))
|
|
75
76
|
):
|
|
76
77
|
logger.debug(f" Skipping: {name}/")
|
|
77
78
|
continue
|
|
@@ -295,6 +296,12 @@ def main() -> int:
|
|
|
295
296
|
dest="json_output",
|
|
296
297
|
help="Output as JSON",
|
|
297
298
|
)
|
|
299
|
+
parser.add_argument(
|
|
300
|
+
"-V",
|
|
301
|
+
"--version",
|
|
302
|
+
action="version",
|
|
303
|
+
version=f"detect-shadowed-modules version {__version__}",
|
|
304
|
+
)
|
|
298
305
|
args = parser.parse_args()
|
|
299
306
|
|
|
300
307
|
setup_logging(quiet=args.quiet or args.json_output)
|
{detect_shadowed_modules-0.2.0 → detect_shadowed_modules-0.2.1}/detect_shadowed_modules/editable.py
RENAMED
|
@@ -32,6 +32,7 @@ def get_editable_paths() -> list[Path]:
|
|
|
32
32
|
capture_output=True,
|
|
33
33
|
text=True,
|
|
34
34
|
timeout=10,
|
|
35
|
+
check=False,
|
|
35
36
|
)
|
|
36
37
|
|
|
37
38
|
if result.returncode != 0:
|
|
@@ -61,6 +62,6 @@ def get_editable_paths() -> list[Path]:
|
|
|
61
62
|
except subprocess.TimeoutExpired:
|
|
62
63
|
logger.debug("uv pip list timed out")
|
|
63
64
|
return []
|
|
64
|
-
except Exception as e:
|
|
65
|
+
except Exception as e: # noqa: BLE001
|
|
65
66
|
logger.debug(f"Unexpected error getting editable paths: {e}")
|
|
66
67
|
return []
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Version handling for detect-shadowed-modules."""
|
|
2
|
+
|
|
3
|
+
import importlib.metadata
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def is_local_source_checkout() -> bool:
|
|
8
|
+
"""Check if the code is running from a local source checkout."""
|
|
9
|
+
package_dir = Path(__file__).resolve().parent
|
|
10
|
+
# Since this is a flat layout (module-root = ""), repo root is the parent of the package dir
|
|
11
|
+
repo_root = package_dir.parent
|
|
12
|
+
|
|
13
|
+
return (repo_root / ".git").exists() and (repo_root / "pyproject.toml").exists()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def get_version() -> str:
|
|
17
|
+
"""Get the version string, appending .dev if running from source."""
|
|
18
|
+
try:
|
|
19
|
+
# Try to get the version of the installed package
|
|
20
|
+
version = importlib.metadata.version("detect-shadowed-modules")
|
|
21
|
+
except importlib.metadata.PackageNotFoundError:
|
|
22
|
+
# Fallback for local development if not installed
|
|
23
|
+
version = "0.1.0"
|
|
24
|
+
|
|
25
|
+
if not is_local_source_checkout():
|
|
26
|
+
return version
|
|
27
|
+
|
|
28
|
+
if version.endswith(".dev"):
|
|
29
|
+
return version
|
|
30
|
+
|
|
31
|
+
return f"{version}.dev"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
__version__ = get_version()
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "detect-shadowed-modules"
|
|
3
|
+
version = "0.2.1"
|
|
4
|
+
description = "Detect conflicting directory names across Python's sys.path that shadow installed packages"
|
|
5
|
+
keywords = [
|
|
6
|
+
"import",
|
|
7
|
+
"shadowing",
|
|
8
|
+
"diagnostics",
|
|
9
|
+
]
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
15
|
+
"Programming Language :: Python :: 3.11",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
17
|
+
"Programming Language :: Python :: 3.13",
|
|
18
|
+
"Programming Language :: Python :: 3.14",
|
|
19
|
+
"Programming Language :: Python :: 3.15",
|
|
20
|
+
]
|
|
21
|
+
dependencies = []
|
|
22
|
+
|
|
23
|
+
[[project.authors]]
|
|
24
|
+
name = "Michael Bianco"
|
|
25
|
+
email = "mike@mikebian.co"
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Repository = "https://github.com/iloveitaly/detect-shadowed-modules"
|
|
29
|
+
|
|
30
|
+
[project.scripts]
|
|
31
|
+
detect-shadowed-modules = "detect_shadowed_modules:main"
|
|
32
|
+
|
|
33
|
+
[build-system]
|
|
34
|
+
requires = ["uv_build>=0.11.0,<0.14"]
|
|
35
|
+
build-backend = "uv_build"
|
|
36
|
+
|
|
37
|
+
[tool.uv.build-backend]
|
|
38
|
+
module-root = ""
|
|
39
|
+
|
|
40
|
+
[tool.pyright]
|
|
41
|
+
exclude = [
|
|
42
|
+
"examples/",
|
|
43
|
+
"playground/",
|
|
44
|
+
"tmp/",
|
|
45
|
+
".venv/",
|
|
46
|
+
"tests/",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[tool.pytest.ini_options]
|
|
50
|
+
addopts = "--cov --cov-report=term-missing --cov-report=html:tmp/htmlcov"
|
|
51
|
+
|
|
52
|
+
[tool.coverage.run]
|
|
53
|
+
plugins = ["covdefaults"]
|
|
54
|
+
source = ["detect_shadowed_modules"]
|
|
55
|
+
|
|
56
|
+
[tool.coverage.report]
|
|
57
|
+
fail_under = 50
|
|
58
|
+
|
|
59
|
+
[dependency-groups]
|
|
60
|
+
dev = [
|
|
61
|
+
"pytest>=8.3.4",
|
|
62
|
+
"pyright[nodejs]>=1.1.408",
|
|
63
|
+
"ruff>=0.15.0",
|
|
64
|
+
"coverage>=7.13.4",
|
|
65
|
+
"pytest-cov>=7.0.0",
|
|
66
|
+
"covdefaults>=2.3.0",
|
|
67
|
+
"beautiful-traceback>=1.0.2; python_version >= '3.12'",
|
|
68
|
+
]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "detect-shadowed-modules"
|
|
3
|
+
version = "0.2.1"
|
|
4
|
+
description = "Detect conflicting directory names across Python's sys.path that shadow installed packages"
|
|
5
|
+
keywords = ["import", "shadowing", "diagnostics"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
requires-python = ">=3.11"
|
|
8
|
+
classifiers = [
|
|
9
|
+
"Programming Language :: Python :: 3",
|
|
10
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
11
|
+
"Programming Language :: Python :: 3.11",
|
|
12
|
+
"Programming Language :: Python :: 3.12",
|
|
13
|
+
"Programming Language :: Python :: 3.13",
|
|
14
|
+
"Programming Language :: Python :: 3.14",
|
|
15
|
+
"Programming Language :: Python :: 3.15",
|
|
16
|
+
]
|
|
17
|
+
dependencies = []
|
|
18
|
+
authors = [{ name = "Michael Bianco", email = "mike@mikebian.co" }]
|
|
19
|
+
urls = { "Repository" = "https://github.com/iloveitaly/detect-shadowed-modules" }
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# additional packaging information: https://packaging.python.org/en/latest/specifications/core-metadata/#license
|
|
23
|
+
[project.scripts]
|
|
24
|
+
detect-shadowed-modules = "detect_shadowed_modules:main"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
[build-system]
|
|
28
|
+
requires = ["uv_build>=0.11.0,<0.14"]
|
|
29
|
+
build-backend = "uv_build"
|
|
30
|
+
|
|
31
|
+
[tool.uv.build-backend]
|
|
32
|
+
# avoids the src/ directory structure
|
|
33
|
+
module-root = ""
|
|
34
|
+
|
|
35
|
+
[dependency-groups]
|
|
36
|
+
dev = [
|
|
37
|
+
"pytest>=8.3.4",
|
|
38
|
+
"pyright[nodejs]>=1.1.408",
|
|
39
|
+
"ruff>=0.15.0",
|
|
40
|
+
"coverage>=7.13.4",
|
|
41
|
+
"pytest-cov>=7.0.0",
|
|
42
|
+
"covdefaults>=2.3.0",
|
|
43
|
+
"beautiful-traceback>=1.0.2; python_version >= '3.12'",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[tool.pyright]
|
|
47
|
+
exclude = ["examples/", "playground/", "tmp/", ".venv/", "tests/"]
|
|
48
|
+
|
|
49
|
+
[tool.pytest.ini_options]
|
|
50
|
+
addopts = "--cov --cov-report=term-missing --cov-report=html:tmp/htmlcov"
|
|
51
|
+
|
|
52
|
+
[tool.coverage.run]
|
|
53
|
+
plugins = ["covdefaults"]
|
|
54
|
+
source = ["detect_shadowed_modules"]
|
|
55
|
+
|
|
56
|
+
[tool.coverage.report]
|
|
57
|
+
fail_under = 50
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
[project]
|
|
2
|
-
name = "detect-shadowed-modules"
|
|
3
|
-
version = "0.2.0"
|
|
4
|
-
description = "Detect conflicting directory names across Python's sys.path that shadow installed packages"
|
|
5
|
-
keywords = ["import", "shadowing", "diagnostics"]
|
|
6
|
-
readme = "README.md"
|
|
7
|
-
requires-python = ">=3.11"
|
|
8
|
-
dependencies = []
|
|
9
|
-
authors = [{ name = "Michael Bianco", email = "mike@mikebian.co" }]
|
|
10
|
-
urls = { "Repository" = "https://github.com/iloveitaly/detect-shadowed-modules" }
|
|
11
|
-
|
|
12
|
-
# additional packaging information: https://packaging.python.org/en/latest/specifications/core-metadata/#license
|
|
13
|
-
[project.scripts]
|
|
14
|
-
detect-shadowed-modules = "detect_shadowed_modules:main"
|
|
15
|
-
|
|
16
|
-
[build-system]
|
|
17
|
-
requires = ["uv_build>=0.9.0,<0.10.0"]
|
|
18
|
-
build-backend = "uv_build"
|
|
19
|
-
|
|
20
|
-
[tool.uv.build-backend]
|
|
21
|
-
# avoids the src/ directory structure
|
|
22
|
-
module-root = ""
|
|
23
|
-
|
|
24
|
-
[dependency-groups]
|
|
25
|
-
dev = ["pytest>=8.3.3","pyright[nodejs]>=1.1.380","ruff>=0.8.0"]
|
|
26
|
-
|
|
27
|
-
[tool.pyright]
|
|
28
|
-
exclude = ["examples/", "playground/", "tmp/", ".venv/", "tests/"]
|
|
29
|
-
|
|
30
|
-
[tool.ruff]
|
|
31
|
-
extend-exclude = ["playground.py", "playground/"]
|