Repository: pypa/setuptools (python)

Issue:
[BUG] vendor package `typeguard` installed to entrypoints
### setuptools version

setuptools==71.0.1

### Python version

python 3.8

### OS

arch linux

### Additional environment information

_No response_

### Description

bug introduced by https://github.com/pypa/setuptools/compare/v71.0.1..v71.0.0#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711R181-R183

pytest would search the plugins by the entrypoint `pytest11`. the `vendor/typeguard` got installed to the entrypoint, but without a correct metadata. Got error message

```
Traceback (most recent call last):
  ... unrelated ..
  File "myenv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 159, in main
    config = _prepareconfig(args, plugins)
  File "myenv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 346, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "myenv/lib/python3.8/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "myenv/lib/python3.8/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "myenv/lib/python3.8/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "myenv/lib/python3.8/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "myenv/lib/python3.8/site-packages/_pytest/helpconfig.py", line 106, in pytest_cmdline_parse
    config = yield
  File "myenv/lib/python3.8/site-packages/pluggy/_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "myenv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1152, in pytest_cmdline_parse
    self.parse(args)
  File "myenv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1501, in parse
    self._preparse(args, addopts=addopts)
  File "myenv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1388, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "myenv/lib/python3.8/site-packages/pluggy/_manager.py", line 421, in load_setuptools_entrypoints
    plugin = ep.load()
  File "myenv/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 183, in load
    module = import_module(match.group('module'))
  File "myuser/.pyenv/versions/3.8.19/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "myenv/lib/python3.8/site-packages/setuptools/_vendor/typeguard/__init__.py", line 21, in <module>
    from ._importhook import ImportHookManager as ImportHookManager
  File "myenv/lib/python3.8/site-packages/setuptools/_vendor/typeguard/_importhook.py", line 35, in <module>
    OPTIMIZATION = "typeguard" + "".join(version("typeguard").split(".")[:3])
  File "myenv/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 982, in version
    return distribution(distribution_name).version
  File "myenv/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 475, in version
    return self.metadata['Version']
  File "myenv/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/_adapters.py", line 54, in __getitem__
    raise KeyError(item)
KeyError: 'Version'
```

succeeded with version 71.0.0

### Expected behavior

run successfully

### How to Reproduce

as description

### Output

as description

Pull request description:
Include all vendored metadata
- **Add a failing test covering the missed expectation.**
- **Include all vendored files in the sdist.**

<!-- First time contributors: Take a moment to review https://setuptools.pypa.io/en/latest/development/developer-guide.html! -->
<!-- Remove sections if not applicable -->

## Summary of changes

<!-- Summary goes here -->

Closes #4480

### Pull Request Checklist
- [x] Changes have tests
- [x] News fragment added in [`newsfragments/`].
  _(See [documentation][PR docs] for details)_


[`newsfragments/`]: https://github.com/pypa/setuptools/tree/master/newsfragments
[PR docs]:
https://setuptools.pypa.io/en/latest/development/developer-guide.html#making-a-pull-request


Patch:
diff --git a/MANIFEST.in b/MANIFEST.in
index c4f12dc68..092612cb2 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -2,7 +2,7 @@ recursive-include setuptools *.py *.exe *.xml *.tmpl
 recursive-include tests *.py
 recursive-include setuptools/tests *.html
 recursive-include docs *.py *.txt *.rst *.conf *.css *.css_t Makefile indexsidebar.html
-recursive-include setuptools/_vendor *.py *.txt
+recursive-include setuptools/_vendor *
 recursive-include pkg_resources *.py *.txt
 recursive-include pkg_resources/tests/data *
 recursive-include tools *
diff --git a/NEWS.rst b/NEWS.rst
index 974aae24f..1b569cc88 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -13,7 +13,7 @@ v71.0.0
 Deprecations and Removals
 -------------------------
 
-- Now setuptools declares its own dependencies in the ``core`` extra. Dependencies are still vendored for bootstrapping purposes, but setuptools will prefer installed dependencies if present. The ``core`` extra is used for informational purposes and should *not* be declared in package metadata (e.g. ``build-requires``). Downstream packagers can de-vendor by simply removing the ``setuptools/_vendor`` directory. Since Setuptools now prefers installed dependencies, those installing to an environment with old, incompatible dependencies will not work. In that case, either uninstall the incompatible dependencies or upgrade them to satisfy those declared in ``core``. (#2825)
+- Now setuptools declares its own dependencies in the ``core`` extra. Dependencies are still vendored for bootstrapping purposes, but setuptools will prefer installed dependencies if present. The ``core`` extra is used for informational purposes and should *not* be declared in package metadata (e.g. ``build-requires``). Downstream packagers can de-vendor by simply removing the ``setuptools/_vendor`` directory. (#2825)
 
 
 v70.3.0
diff --git a/newsfragments/4480.bugfix.rst b/newsfragments/4480.bugfix.rst
new file mode 100644
index 000000000..a43949fa7
--- /dev/null
+++ b/newsfragments/4480.bugfix.rst
@@ -0,0 +1,1 @@
+Include all vendored files in the sdist.
\ No newline at end of file


Test patch:
diff --git a/setuptools/tests/test_setuptools.py b/setuptools/tests/test_setuptools.py
index 613a52d04..566af6980 100644
--- a/setuptools/tests/test_setuptools.py
+++ b/setuptools/tests/test_setuptools.py
@@ -1,5 +1,6 @@
 """Tests for the 'setuptools' package"""
 
+import re
 import sys
 import os
 import distutils.core
@@ -315,3 +316,12 @@ def test_wheel_includes_cli_scripts(setuptools_wheel):
         contents = [f.replace(os.sep, '/') for f in zipfile.namelist()]
 
     assert any('cli-64.exe' in member for member in contents)
+
+
+def test_wheel_includes_vendored_metadata(setuptools_wheel):
+    with ZipFile(setuptools_wheel) as zipfile:
+        contents = [f.replace(os.sep, '/') for f in zipfile.namelist()]
+
+    assert any(
+        re.search(r'_vendor/.*\.dist-info/METADATA', member) for member in contents
+    )