summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.d/3561.misc.rst1
-rw-r--r--setuptools/command/editable_wheel.py2
-rw-r--r--setuptools/tests/test_editable_install.py24
3 files changed, 26 insertions, 1 deletions
diff --git a/changelog.d/3561.misc.rst b/changelog.d/3561.misc.rst
new file mode 100644
index 00000000..12158e40
--- /dev/null
+++ b/changelog.d/3561.misc.rst
@@ -0,0 +1 @@
+Fix accidental name matching in editable hooks.
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.