Repository: pypa/setuptools

Issue:
Extra directories exposed by editable wheel for `setuptools` project itself
I noticed in `main` (5169a9b1f) that some extra directories of the `setuptools` project ended up exposed by the editable wheel. Specifically `launcher` and `newsfragments`. This is a quick reproducer:

```bash
git clone --depth 1 https://github.com/pypa/setuptools /tmp/test-setuptools
cd /tmp/test-setuptools
git reset --hard 5169a9b
python3.11 -m venv .venv
.venv/bin/python -m pip install -U 'pip==23.2.1'
.venv/bin/python -m pip install -e .
cat .venv/lib/python3.11/site-packages/__editable___setuptools_*_finder.py | head
```
```console
import sys
from importlib.machinery import ModuleSpec
from importlib.machinery import all_suffixes as module_suffixes
from importlib.util import spec_from_file_location
from itertools import chain
from pathlib import Path

MAPPING = {'_distutils_hack': '/tmp/test-setuptools/_distutils_hack', 'launcher': '/tmp/test-setuptools/launcher', 'newsfragments': '/tmp/test-setuptools/newsfragments', 'pkg_resources': '/tmp/test-setuptools/pkg_resources', 'setuptools': '/tmp/test-setuptools/setuptools'}
NAMESPACES = {'launcher': ['/tmp/test-setuptools/launcher'], 'newsfragments': ['/tmp/test-setuptools/newsfragments']}
PATH_PLACEHOLDER = '__editable__.setuptools-68.0.0.post20230808.finder' + ".__path_hook__"
```

This is likely caused by the way `packages = find_namespace:` is configured in `setup.cfg`.
We can check that by running:

```python
# Still inside /tmp/test-setuptools from the previous example
.venv/bin/python
Python 3.11.4 (main, Jun  7 2023, 12:45:49) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import setuptools
>>> from distutils.core import run_setup
>>> dist = run_setup("setup.py", stop_after="commandline")
>>> dist.packages
['launcher', 'newsfragments', 'pkg_resources', 'setuptools', '_distutils_hack', 'pkg_resources.extern', 'pkg_resources._vendor', 'pkg_resources._vendor.importlib_resources', 'pkg_resources._vendor.jaraco', 'pkg_resources._vendor.more_itertools', 'pkg_resources._vendor.packaging', 'pkg_resources._vendor.platformdirs', 'pkg_resources._vendor.jaraco.text', 'setuptools.command', 'setuptools.config', 'setuptools.extern', 'setuptools._distutils', 'setuptools._vendor', 'setuptools.config._validate_pyproject', 'setuptools._distutils.command', 'setuptools._vendor.importlib_metadata', 'setuptools._vendor.importlib_resources', 'setuptools._vendor.jaraco', 'setuptools._vendor.more_itertools', 'setuptools._vendor.packaging', 'setuptools._vendor.tomli', 'setuptools._vendor.jaraco.text']
>>> "newsfragments" in dist.packages
True
>>> "launcher" in dist.packages
True
```

I imagine that the reason why `newsfragments` and `launcher` are not included in the regular wheel is because `setup.cfg/setup.py` does not have `package_data = [...]` or `include_package_data = True`, so the  `.rst` and `.exe` files are excluded from the wheel, and therefore the `newsfragments` and `launcher` directories end up empty during the build, which will automatically remove them from the zip (zip files cannot contain empty directories right?)

The expectation would be that the `packages` configuration exclude these directories by default (even if they don't contain `.py` files) to prevent errors (e.g. in the future we could end up adding files to these directories that are captured by setuptools `package_data` or `include_package_data`).


Discussion:

Resolving patch:
diff --git a/setuptools/discovery.py b/setuptools/discovery.py
--- a/setuptools/discovery.py
+++ b/setuptools/discovery.py
@@ -219,6 +219,7 @@ class FlatLayoutPackageFinder(PEP420PackageFinder):
         "documentation",
         "manpages",
         "news",
+        "newsfragments",
         "changelog",
         "test",
         "tests",


Test patch: