Generate `distutils-stubs` on install
Summary of changes
3rd iteration to close #4689 (doesn't solve everything mentioned in that issue, but it would greatly reduce the scope so I'd prefer re-opening as a new issue)
This is built off of https://github.com/pypa/setuptools/pull/4704 where the stubs are automatically generated, but now they're done on install instead of existing in the source code.
Further Advantages over #4704:
- Doesn't pollute the source or history
Further Disadvantages over #4704:
- Contributors must install the local setuptools repo in their environment (
pip install .) to get proper type-checking in their editor on Python 3.12+ when it comes to pypa/distutils derived types. (they already had to installtypes-setuptools, this replaces that)
Pull Request Checklist
- [x] Changes have tests (existing build+install and type-checking tests)
- [x] News fragment added in
newsfragments/. (See documentation for details)
Aaaah, right, I forgot that *-stubs will never override the stdlib types from typeshed. So this only affects Python 3.12+
For end users: This is already the case with typeshed's own setuptools stubs, so that's fine. (This is true even of #4689)
For setuptools contributors: This means we can't use this to get correct types in our own code, when pypa differs from stdlib on Python < 3.12
Overall still an improvement (and typeshed won't have to special case this stub anymore) and a necessary step for https://github.com/pypa/setuptools/issues/2345
@jaraco I think that this version has minimal (if any) downsides, solves real issues (addresses the user-facing concerns of https://github.com/pypa/setuptools/issues/4689 and part of the setuptools internal typing ones), is literally as good as typeshed's and works towards https://github.com/pypa/setuptools/issues/2345
I think this doesn't work with tox because of PEP660 editable installs? I'll need help to get that working.
I very nearly got it working with a custom build backend to support PEP 660 editable installs, which also happens to leave the stubs in the source (which I can just .gitignore). Bringing all the benefits of #4704 .
But I'm currently blocked on this mypy issue: https://github.com/python/mypy/issues/18775
Necessary distutils changes have been PRd in https://github.com/pypa/distutils/pull/357