Repository: pypa/setuptools

Issue:
[BUG] setup.cfg + pyproject.toml + setup.py (with PBR) breaking.
### setuptools version

setuptools==64.0.0

### Python version

Python 3.8.5

### OS

macOS

### Additional environment information

_No response_

### Description

Reported originally in #3498. Unsure what is going on, but after the latest setuptools the following is thrown when using editable installs:

```
      distutils.errors.DistutilsSetupError: Error: setup script specifies an absolute path:
      
          /var/folders/r7/ggtlz3qs465bzrr2zjtf1h380000gp/T/tmpbr2b9x3w.build-temp/test.egg-info/SOURCES.txt
      
      setup() arguments must *always* be /-separated paths relative to the
      setup.py directory, *never* absolute paths.
      
      error: Support for editable installs via PEP 660 was recently introduced
      in `setuptools`. If you are seeing this error, please report to:
      
      https://github.com/pypa/setuptools/issues
      
      Meanwhile you can try the legacy behavior by setting an
      environment variable and trying to install again:
      
      SETUPTOOLS_ENABLE_FEATURES="legacy-editable"
      [end of output]
```

### Expected behavior

No error should be thrown, and the package should be installed.

### How to Reproduce


Here is a reproducible repo: https://github.com/synchronizing/setuptools-error

Running `pip install -e .` inside the folder will cause the error seen above. A few points:

* `SETUPTOOLS_ENABLE_FEATURES` flag _fixes_ the issue.
* Installing it without being editable (`pip install .`) _fixes_ the issue.
* Removing `pyproject.toml` _fixes_ the issue.
* Removing `pbr` _fixes_ the issue.
* Removing the `other` folder _fixes_ the issue.

### Output

See above.


Discussion:
Thank you very much for reporting this and for the reproducer.

I will investigate the issue and try to get back to you as soon as I can.
An interesting find. On the repo linked above, I added the following `Dockerfile`:

```Dockerfile
FROM python:3.8

RUN pip install --upgrade setuptools

WORKDIR /opt/
COPY . test
WORKDIR /opt/test
RUN pip install -e .

CMD ["/bin/bash"]
```

The above errors out with the same issue noted. Here are different version results:

Works:
* 3.8.0
* 3.8.1
* 3.8.5
* 3.8.10
* 3.8.11
* 3.8.12
* 3.9.0
* 3.9.1
* 3.9.4
* 3.9.5
* 3.9.9
* 3.9.10

Does not work:
* 3.8 (= 3.8.13)
* 3.9 (= 3.9.13)
* 3.9.12
* 3.9.11

Edit: See more below. This test doesn't seem solid enough.
I added `Dockerfile` and `docker-compose.yml` to the repo linked. Doing `docker-compose up` should result in the issue noted. 
I also can reproduce the error in my machine with Python 3.8.10
3.8.10 seems to be working with the Dockerfile above, weirdly enough.
It's dependent on the release, and which Python base image is getting pulled based on the tag. Using Github Actions with the matrix functionality fails on all versions: https://github.com/synchronizing/setuptools-error/actions/runs/2841720491

Super weird, but at least its more reassuring this is happening in every version.
Thank you very much for helping to investigate that. I really appreciate all the effort.
Of course. Version 3.6.x works due to it being tied to setuptools `59.6.0`. 
See: https://github.com/synchronizing/setuptools-error/actions/runs/2841783973

Resolving patch:
diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py
--- a/setuptools/command/build_py.py
+++ b/setuptools/command/build_py.py
@@ -11,7 +11,7 @@
 import stat
 import warnings
 from pathlib import Path
-from typing import Dict, Iterator, List, Optional, Tuple
+from typing import Dict, Iterable, Iterator, List, Optional, Tuple
 
 from setuptools._deprecation_warning import SetuptoolsDeprecationWarning
 from setuptools.extern.more_itertools import unique_everseen
@@ -175,15 +175,17 @@ def analyze_manifest(self):
             getattr(self, 'existing_egg_info_dir', None)
             and Path(self.existing_egg_info_dir, "SOURCES.txt").exists()
         ):
-            manifest = Path(self.existing_egg_info_dir, "SOURCES.txt")
+            egg_info_dir = self.existing_egg_info_dir
+            manifest = Path(egg_info_dir, "SOURCES.txt")
             files = manifest.read_text(encoding="utf-8").splitlines()
         else:
             self.run_command('egg_info')
             ei_cmd = self.get_finalized_command('egg_info')
+            egg_info_dir = ei_cmd.egg_info
             files = ei_cmd.filelist.files
 
         check = _IncludePackageDataAbuse()
-        for path in files:
+        for path in _filter_absolute_egg_info(files, egg_info_dir):
             d, f = os.path.split(assert_relative(path))
             prev = None
             oldf = f
@@ -346,3 +348,15 @@ def warn(self, importable):
             msg = textwrap.dedent(self.MESSAGE).format(importable=importable)
             warnings.warn(msg, SetuptoolsDeprecationWarning, stacklevel=2)
             self._already_warned.add(importable)
+
+
+def _filter_absolute_egg_info(files: Iterable[str], egg_info: str) -> Iterator[str]:
+    """
+    ``build_meta`` may try to create egg_info outside of the project directory,
+    and this can be problematic for certain plugins (reported in issue #3500).
+    This function should filter this case of invalid files out.
+    """
+    egg_info_name = Path(egg_info).name
+    for file in files:
+        if not (egg_info_name in file and os.path.isabs(file)):
+            yield file


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
@@ -685,6 +685,43 @@ def test_compat_install(tmp_path, venv):
     assert "cannot import name 'subpackage'" in out
 
 
+def test_pbr_integration(tmp_path, venv, editable_opts):
+    """Ensure editable installs work with pbr, issue #3500"""
+    files = {
+        "pyproject.toml": dedent("""\
+            [build-system]
+            requires = ["setuptools"]
+            build-backend = "setuptools.build_meta"
+            """),
+        "setup.py": dedent("""\
+            __import__('setuptools').setup(
+                pbr=True,
+                setup_requires=["pbr"],
+            )
+            """),
+        "setup.cfg": dedent("""\
+            [metadata]
+            name = mypkg
+
+            [files]
+            packages =
+                mypkg
+            """),
+        "mypkg": {
+            "__init__.py": "",
+            "hello.py": "print('Hello world!')",
+        },
+        "other": {"test.txt": "Another file in here."},
+    }
+    venv.run(["python", "-m", "pip", "install", "pbr"])
+
+    with contexts.environment(PBR_VERSION="0.42"):
+        install_project("mypkg", venv, tmp_path, files, *editable_opts)
+
+    out = venv.run(["python", "-c", "import mypkg.hello"])
+    assert b"Hello world!" in out
+
+
 def install_project(name, venv, tmp_path, files, *opts):
     project = tmp_path / name
     project.mkdir()