Repository: pypa/setuptools

Issue:
[BUG] Editable wheel match import paths that are not theirs
### setuptools version

65.2.0

### Python version

3.10.6

### OS

Ubuntu 20.04

### Additional environment information

_No response_

### Description

I'm currently working with two packages having names beginning the same, let's call them **foo** and **foobar** for example.
I install both of them using `pip install -e`, and both can be imported normally:
```python
#!/usr/bin/env python
import foo
import foobar
```

Now I add a module **bar** in the foo package, so I can import **foo**, **foobar** and **foo.bar**
But importing **foobar** now always result in importing **foo.bar**

```python
#!/usr/bin/env python
import foobar # PROBLEM this actually import foo.bar
```


### Expected behavior

Importing foobar should never result in importing foo.bar instead.

### How to Reproduce

```bash
#├── project1
#│   ├── foo
#│   │   ├── bar
#│   │   │   └── __init__.py
#│   │   └── __init__.py
#│   ├── pyproject.toml
#│   └── setup.cfg
#│
#├─ project2
#│   ├── foobar
#│   │   └── __init__.py
#│   ├── pyproject.toml
#│   └── setup.cfg

# Commands to reproduce the same layout
mkdir -p project1/foo/bar
mkdir -p project2/foobar
touch project1/pyproject.toml 
touch project1/pyproject.toml
touch project1/setup.cfg
touch project1/setup.cfg
echo print\(\"Hello from foo\"\) > project1/foo/__init__.py
echo print\(\"Hello from foo.bar\"\) > project1/foo/bar/__init__.py
echo print\(\"Hello from foobar\"\) > project2/foobar/__init__.py
```
```bash
# Commands to reproduce the error
pip install -e project1
pip install -e project2
python
>>> import foobar
Hello from foo.bar # ERROR it should be foobar, not foo.bar
```

### Output

```console
pip install -e project1
pip install -e project2
python
>>> import foobar
Hello from foobar # This is what we expect
```



Discussion:
With debugger I can see the moment when foo.bar is chosen in place of foobar: 
https://github.com/pypa/setuptools/blob/e551496e9948a272b42f4a654d722500149380d2/setuptools/command/editable_wheel.py#L761

When fullname is "foobar" and pkg is "foo", it enter the if while it should not.

Using `if fullname.split(".")[0] == pkg:` instead would fix the problem by only comparing pkg to the first path item.

Resolving patch:
diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py
--- 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))
 


Test patch:
diff --git a/setuptools/tests/test_editable_install.py b/setuptools/tests/test_editable_install.py
--- a/setuptools/tests/test_editable_install.py
+++ b/setuptools/tests/test_editable_install.py
@@ -515,6 +515,30 @@ def test_no_recursion(self, tmp_path):
             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.