diff options
| author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-08-24 10:31:38 +0100 |
|---|---|---|
| committer | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-08-24 10:31:38 +0100 |
| commit | c0d9f43bcd3140fb4213d57675ae9beaec5607a3 (patch) | |
| tree | d7f177bc1ee048b86d4b09cdec12ed945d7be8dd /setuptools | |
| parent | af1ff35b3715b5f2baf4b2fbe22a818b471b4513 (diff) | |
| parent | 52bf418dedc7fa9a7fa2e3c641b414eda67f5c3c (diff) | |
| download | python-setuptools-git-c0d9f43bcd3140fb4213d57675ae9beaec5607a3.tar.gz | |
Prevent accidental name matching in editable hooks (#3562)
Diffstat (limited to 'setuptools')
| -rw-r--r-- | setuptools/command/editable_wheel.py | 2 | ||||
| -rw-r--r-- | setuptools/tests/test_editable_install.py | 24 |
2 files changed, 25 insertions, 1 deletions
diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py index b908298f..d05c3a75 100644 --- a/setuptools/command/editable_wheel.py +++ b/setuptools/command/editable_wheel.py @@ -758,7 +758,7 @@ class _EditableFinder: # MetaPathFinder @classmethod def find_spec(cls, fullname, path=None, target=None): for pkg, pkg_path in reversed(list(MAPPING.items())): - if fullname.startswith(pkg): + if fullname == pkg or fullname.startswith(f"{{pkg}}."): rest = fullname.replace(pkg, "", 1).strip(".").split(".") return cls._find_spec(fullname, Path(pkg_path, *rest)) diff --git a/setuptools/tests/test_editable_install.py b/setuptools/tests/test_editable_install.py index 4a2ceb12..c8ee7477 100644 --- a/setuptools/tests/test_editable_install.py +++ b/setuptools/tests/test_editable_install.py @@ -515,6 +515,30 @@ class TestFinderTemplate: with pytest.raises(ImportError, match="pkg"): import_module("pkg") + def test_similar_name(self, tmp_path): + files = { + "foo": { + "__init__.py": "", + "bar": { + "__init__.py": "", + } + }, + } + jaraco.path.build(files, prefix=tmp_path) + + mapping = { + "foo": str(tmp_path / "foo"), + } + template = _finder_template(str(uuid4()), mapping, {}) + + with contexts.save_paths(), contexts.save_sys_modules(): + sys.modules.pop("foo", None) + sys.modules.pop("foo.bar", None) + + self.install_finder(template) + with pytest.raises(ImportError, match="foobar"): + import_module("foobar") + def test_pkg_roots(tmp_path): """This test focus in getting a particular implementation detail right. |
