-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FR] Include type information by default (*.pyi
, py.typed
) - PEP 561
#3136
Comments
Hi @cdce8p thank you very much for bringing this issue for discussion. My personal opinion (which might not be shared by the Something that is more likely to happen would besetuptools starting to includ One way to achieve that would be overriding the setuptools/setuptools/_distutils/command/sdist.py Lines 210 to 322 in 6f9e2fe
Please also note that there is a related pending issue in |
Thanks for your comment @abravalheri!
Personally I'm more interested in |
Oh yeah, I forgot about Would you be interested in working in a PR? There is no rush for that, but any help would be more than welcome! |
*.pyi
, py.typed
) - PEP 561
At the moment, I don't have the bandwidth for it unfortunately. If someone else would like to pick this up, that would be awesome. |
I am currently facing an issue distributing This seemed to work in the past, but I recently figured out that on some platforms the .pyi file is missing. setup(
name='mymodule',
ext_modules=[Extension(name='mymodule', ...)],
data_files=[('.', ['mymodule.pyi'])],
) This code was indeed from "some great guides out there explaining it", but is broken as the '.' is not a valid package. The expected installed version of the project should countain two files in the
Here I have a project with a similar setup. I am interested in making the changes necessary.
Is this still the way to go? |
Here is a proof for no actual call is made to |
Based on the advice above, I decided to try modifying setuptools/setuptools/_distutils/command/build_py.py Lines 302 to 303 in 71b355b
to this def get_source_files(self):
py_files = [module[-1] for module in self.find_all_modules()]
possible_stub_files = set(os.path.splitext(f)[0] + ".pyi" for f in py_files)
stub_files = [f for f in possible_stub_files if os.path.isfile(f)]
possible_py_typed_files = set(os.path.dirname(f) + "/py.typed" for f in py_files)
py_typed_files = [f for f in possible_py_typed_files if os.path.isfile(f)]
return py_files + stub_files + py_typed_files I wasn't sure how to test this, but I tested it in the following way and it was successful:
I tried creating a test for this by modifying
by adding lines to create some py.typed and .pyi files and adding more entries to expected but when I run tox I don't think this test runs. (Also when I run tox I always get one failing test that seems to be to do with an error with pip installing something to do with @git+https://... )
|
Hi @Danie-1, would you like to provide a PR for that? We can iterate over it and iron out the issues... Just one thing, for an eventual PR, it would be important to modify (setuptools/command/build_py.py)(https://github.com/pypa/setuptools/blob/main/setuptools/command/build_py.py] instead of The reason why we should avoid modifying files under
Yeah, sorry this is unfortunate. You can try running |
What's the problem this feature will solve?
PEP 561 specifies how type information should be included in a distributions. Namely package authors may choose to add
py.typed
files to fully typed packages and / or include.pyi
stub files. By default, those files won't be included in the sdist / wheel distribution packages.To add them, a package author needs to set
include_package_data = True
and include them via theMANIFEST.in
or withoptions.package_data
(eg. with* = py.typed, *.pyi
). Although there are some great guides out there explaining it, I believe we could make this much simpler.https://blog.whtsky.me/tech/2021/dont-forget-py.typed-for-your-typed-python-package/
https://jugmac00.github.io/blog/bite-my-shiny-type-annotated-library/
Describe the solution you'd like
Add a new option
include_typing_files
orinclude_typing_information
as a shorthand foroptions.package_data
->* = py.typed, *.pyi
.How should it be used?
Authors wanting to include typing files (
py.typed
/ stub files) should setbothinclude_package_data = True
andinclude_typing_files = True
.How would it work with other options to include package data files?
Conceptually this option would add the
* = py.typed, *.pyi
pattern tooptions.package_data
. This also means any file matched byexclude_package_data
should still be excluded.Alternative Solutions
Don't requireinclude_package_data = True
. Similar to license files, one could argue if an author setsinclude_typing_files = True
, they already expressed what they want to do. No need to require an additional option.Include
py.typed
and*.pyi
files by default.Additional context
If others agree that this is something worth adding, I could work on a PR for it.
Code of Conduct
The text was updated successfully, but these errors were encountered: