|
24 | 24 | from setuptools.command.editable_wheel import (
|
25 | 25 | _DebuggingTips,
|
26 | 26 | _LinkTree,
|
| 27 | + _TopLevelFinder, |
27 | 28 | _encode_pth,
|
28 | 29 | _find_virtual_namespaces,
|
29 | 30 | _find_namespaces,
|
@@ -530,6 +531,49 @@ def test_combine_namespaces(self, tmp_path):
|
530 | 531 | assert pkgA.a == 13
|
531 | 532 | assert mod2.b == 37
|
532 | 533 |
|
| 534 | + def test_combine_namespaces_nested(self, tmp_path): |
| 535 | + """ |
| 536 | + Users may attempt to combine namespace packages in a nested way via |
| 537 | + ``package_dir`` as shown in pypa/setuptools#4248. |
| 538 | + """ |
| 539 | + |
| 540 | + files = { |
| 541 | + "src": {"my_package": {"my_module.py": "a = 13"}}, |
| 542 | + "src2": {"my_package2": {"my_module2.py": "b = 37"}}, |
| 543 | + } |
| 544 | + |
| 545 | + stack = jaraco.path.DirectoryStack() |
| 546 | + with stack.context(tmp_path): |
| 547 | + jaraco.path.build(files) |
| 548 | + attrs = { |
| 549 | + "script_name": "%PEP 517%", |
| 550 | + "package_dir": { |
| 551 | + "different_name": "src/my_package", |
| 552 | + "different_name.subpkg": "src2/my_package2", |
| 553 | + }, |
| 554 | + "packages": ["different_name", "different_name.subpkg"], |
| 555 | + } |
| 556 | + dist = Distribution(attrs) |
| 557 | + finder = _TopLevelFinder(dist, str(uuid4())) |
| 558 | + code = next(v for k, v in finder.get_implementation() if k.endswith(".py")) |
| 559 | + |
| 560 | + with contexts.save_paths(), contexts.save_sys_modules(): |
| 561 | + for mod in attrs["packages"]: |
| 562 | + sys.modules.pop(mod, None) |
| 563 | + |
| 564 | + self.install_finder(code) |
| 565 | + mod1 = import_module("different_name.my_module") |
| 566 | + mod2 = import_module("different_name.subpkg.my_module2") |
| 567 | + |
| 568 | + expected = str((tmp_path / "src/my_package/my_module.py").resolve()) |
| 569 | + assert str(Path(mod1.__file__).resolve()) == expected |
| 570 | + |
| 571 | + expected = str((tmp_path / "src2/my_package2/my_module2.py").resolve()) |
| 572 | + assert str(Path(mod2.__file__).resolve()) == expected |
| 573 | + |
| 574 | + assert mod1.a == 13 |
| 575 | + assert mod2.b == 37 |
| 576 | + |
533 | 577 | def test_dynamic_path_computation(self, tmp_path):
|
534 | 578 | # Follows the example in PEP 420
|
535 | 579 | files = {
|
|
0 commit comments