Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PathEntryFinder / MetaPathFinder in editable_wheel #4278

Merged
merged 4 commits into from
Apr 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for issue 4248
  • Loading branch information
abravalheri committed Apr 21, 2024
commit a39d3623f2d9088a6914cfa833838ceac182af57
44 changes: 44 additions & 0 deletions setuptools/tests/test_editable_install.py
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
from setuptools.command.editable_wheel import (
_DebuggingTips,
_LinkTree,
_TopLevelFinder,
_encode_pth,
_find_virtual_namespaces,
_find_namespaces,
@@ -530,6 +531,49 @@ def test_combine_namespaces(self, tmp_path):
assert pkgA.a == 13
assert mod2.b == 37

def test_combine_namespaces_nested(self, tmp_path):
"""
Users may attempt to combine namespace packages in a nested way via
``package_dir`` as shown in pypa/setuptools#4248.
"""

files = {
"src": {"my_package": {"my_module.py": "a = 13"}},
"src2": {"my_package2": {"my_module2.py": "b = 37"}},
}

stack = jaraco.path.DirectoryStack()
with stack.context(tmp_path):
jaraco.path.build(files)
attrs = {
"script_name": "%PEP 517%",
"package_dir": {
"different_name": "src/my_package",
"different_name.subpkg": "src2/my_package2",
},
"packages": ["different_name", "different_name.subpkg"],
}
dist = Distribution(attrs)
finder = _TopLevelFinder(dist, str(uuid4()))
code = next(v for k, v in finder.get_implementation() if k.endswith(".py"))

with contexts.save_paths(), contexts.save_sys_modules():
for mod in attrs["packages"]:
sys.modules.pop(mod, None)

self.install_finder(code)
mod1 = import_module("different_name.my_module")
mod2 = import_module("different_name.subpkg.my_module2")

expected = str((tmp_path / "src/my_package/my_module.py").resolve())
assert str(Path(mod1.__file__).resolve()) == expected

expected = str((tmp_path / "src2/my_package2/my_module2.py").resolve())
assert str(Path(mod2.__file__).resolve()) == expected

assert mod1.a == 13
assert mod2.b == 37

def test_dynamic_path_computation(self, tmp_path):
# Follows the example in PEP 420
files = {