pypa / setuptools

Official project repository for the Setuptools build system
https://pypi.org/project/setuptools/
MIT License
2.53k stars 1.19k forks source link

[BUG] setuptools is not automatically including type stubs by default #4713

Closed winstxnhdw closed 3 weeks ago

winstxnhdw commented 3 weeks ago

setuptools version

setuptools==75.3.0

Python version

Python 3.13

OS

Arch Linux

Additional environment information

No response

Description

According to the setuptools note here,

Added in version v69.0.0: setuptools will attempt to include type information files by default in the distribution (.pyi and py.typed, as specified in PEP 561). Please note however that this feature is EXPERIMENTAL and may change in the future. If you have .pyi and py.typed files in your project, but do not wish to distribute them, you can opt out by setting exclude-package-data to remove them.

However, I found that my type stubs (.pyi) are not being packaged unless I specify them in my MANIFEST.in.

Expected behavior

The type stubs should be automatically included in my sdist without having to specify it in MANIFEST.in

How to Reproduce

  1. Create a Cython extension
  2. Add a .pyi file
  3. Ensure that setuptools required by the build system is >=69.0.0
  4. Upload to GitHub
  5. pip install the package
  6. See that everything but the type stubs are in the relevant site-packages folder

Output

N/A

abravalheri commented 3 weeks ago

Hi @winstxnhdw, could you please include a complete minimal reproducer, including the source code for the examples. Please have a look at the advice in https://stackoverflow.com/help/minimal-reproducible-example.

If I had to guess, I would say that is because you are adding a top-lelvel single extension module instead of a package. .pyi files may be detected inside of packages, but as a coexisting top level file, probably not (that is not how the autodiscovery works). But yeah, we can only confirm this hypothesis or proceed with the investigation once we have a complete minimal reproducer.


Assuming the hypothesis is confirmed, because this is an experimental feature contributed by a member of the community, we have 2 ways we can go about it:

  1. A member of the community submits an emhancement to handle this use case via PR
  2. We document the existing limitation and accept it as the way the system works.

Would you like to give it a go and propose a PR?

winstxnhdw commented 3 weeks ago

Hey @abravalheri,

It's as you said. setuptools is not detecting the extension module as a package. Simply adding a __init__.py resolves this issue.