-
-
Notifications
You must be signed in to change notification settings - Fork 295
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
Optionally build type information stub packages #553
Conversation
Add a new `SDistContext` project metadata struct loosely modelled after `BuildContext` structure. Replace raw `source_distribution()` calls in main.rs with higher level `BuildContext` method invocations. No functionality change.
PEP 561 allows to distribute the Python type information for the extension modules by creating separate stub-only packages. Mixed language projects can embed the type information stubs (.pyi) into the package by simply adding a `py.typed` marker file. `maturin stubs` command accomplishes this also for the module-only extensions by automatically building and publishing an associated `foo-stubs` package when the `foo` extension is being built and the `foo.pyi` type information stubs file is found in the project directory. `maturin build` and `maturin publish` commands build and publish the stubs package automatically unless `--no-stubs` flag is passed.
I really want to support stub files in maturin and I appreciate the initiative, but I'm not sure whether extra stub packages are the way to go (for these cases it can also be helpful to open an issue to discuss the implementation before a pull request). PEP 484 says:
The mypy docs add:
Would this be an option for maturin? I wouldn't mind changing the pure-rust layout for that to the following:
CC @ijl any thoughts on this? I remember that you have a stub file for orjson but I don't know how you ship it. |
That would work, but it's almost the same as using a mixed-language project layout from the start.
Wouldn't implicitly converting module-only packages to directory packages cause backwards compatibility issues on the Python side? This PR simply encodes the build flow I'm currently using, except I was scraping |
I've implemented the new layout in #558, please have a look. As far as I can tell, this means no changes for the user:
This is the same for both layouts, so afaik not even the string representations changed. I'll check whether mypy likes this once #558 is merged (I'd prefer that layout either way). |
#558 allows to embed the type info directly into the package, but it isn't clear yet how the user can include |
It should be easy to add |
|
Opened #567 |
PEP 561 allows to distribute the Python type information for
the extension modules by creating separate stub-only packages.
Mixed language projects can embed the type information stubs (.pyi)
into the package by simply adding a
py.typed
marker file.maturin stubs
command accomplishes this also for the module-only extensionsby automatically building and publishing an associated
foo-stubs
packagewhen the
foo
extension is being built and thefoo.pyi
type informationstubs file is found in the project directory.
maturin build
andmaturin publish
commands build and publishthe stubs package automatically unless
--no-stubs
flag is passed.