Skip to content

Commit d651344

Browse files
committed
Explicitly add legacy namespaces to package mapping in editable_wheel
This seems to be necessary to ensure modules inside legacy namespaces import correctly even if another distribution that shares the same namespace is installed conventionally.
1 parent 6818948 commit d651344

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

setuptools/command/editable_wheel.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,19 @@ def __call__(self, wheel: "WheelFile", files: List[str], mapping: Dict[str, str]
505505
)
506506
)
507507

508+
legacy_namespaces = {
509+
pkg: find_package_path(pkg, roots, self.dist.src_root or "")
510+
for pkg in self.dist.namespace_packages or []
511+
}
512+
513+
mapping = {**roots, **legacy_namespaces}
514+
# ^-- We need to explicitly add the legacy_namespaces to the mapping to be
515+
# able to import their modules even if another package sharing the same
516+
# namespace is installed in a conventional (non-editable) way.
517+
508518
name = f"__editable__.{self.name}.finder"
509519
finder = _normalization.safe_identifier(name)
510-
content = bytes(_finder_template(name, roots, namespaces_), "utf-8")
520+
content = bytes(_finder_template(name, mapping, namespaces_), "utf-8")
511521
wheel.writestr(f"{finder}.py", content)
512522

513523
content = _encode_pth(f"import {finder}; {finder}.install()")

0 commit comments

Comments
 (0)