Skip to content

Commit

Permalink
fix: PDM does not detect namespace packages correctly
Browse files Browse the repository at this point in the history
Fixes #2378

Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Nov 8, 2023
1 parent 5f66b1d commit 9997f5c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/2378.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug that PDM cannot detect namespace packages correctly when creating symlinks. The package's `__init__.py` contains an unusual line.
4 changes: 3 additions & 1 deletion src/pdm/installers/installers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ def _is_python_package(root: str | Path) -> bool:
# pkg_resources style
"__import__('pkg_resources').declare_namespace(__name__)",
"pkg_resources.declare_namespace(__name__)",
"declare_namespace(__name__)",
# pkgutil style
"__path__ = __import__('pkgutil').extend_path(__path__, __name__)",
"__path__ = pkgutil.extend_path(__path__, __name__)",
"__path__ = extend_path(__path__, __name__)",
]
)
_namespace_package_lines = _namespace_package_lines.union(line.replace("'", '"') for line in _namespace_package_lines)
Expand Down Expand Up @@ -94,7 +96,7 @@ def _create_symlinks_recursively(source: str, destination: str) -> Iterable[str]
# for child directories
if os.path.exists(destination_root):
warnings.warn(f"Overwriting existing package: {destination_root}", PDMWarning, stacklevel=2)
if os.path.isdir(destination_root):
if os.path.isdir(destination_root) and not os.path.islink(destination_root):
shutil.rmtree(destination_root)
else:
os.remove(destination_root)
Expand Down

0 comments on commit 9997f5c

Please sign in to comment.