-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Build backend: Support stubs packages #13563
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
Conversation
Stubs packages are different in that their name ends with `-stubs`, their module is `<module name>-stubs` (with a dash, not the generally legal underscore) and their modules contain a `__init__.pyi` instead of an `__init__.py` (https://typing.python.org/en/latest/spec/distributing.html#stub-only-packages). We add support in the uv build backend by detecting the `-stubs` suffix.
e3f6368
to
99d21fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM as far as I can tell!
If you want to see how ty handles this in its module resolver, you can grep for uses of this struct in the crates/ty_python_semantic/src/module_resolver
directory in the Ruff repo
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Identifier::from_str(package_name.as_dist_info_name().as_ref())?.to_string() | ||
// Infer stubs packages from package name alone. There are potential false positives if | ||
// someone had a regular package with `-stubs`. | ||
if let Some(stem) = package_name.to_string().strip_suffix("-stubs") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a false positive happens, is there a way for a user to override that and say, "no, this is not a stubs package"?
Conversely, is there a way for a package that doesn't end with -stubs
to be treated as a stubs package?
From this PR, it looks like the answer to both above is "no." Are we sure that's okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In one direction, https://typing.python.org/en/latest/spec/distributing.html#stub-only-packages is a clear MUST about the -stubs
suffix. In the other direction, I think I'd try this out, and if there are really packages with let's say foo_stubs
we can add an override (tool.uv.build-backend.stubs = False
). If we can have one option less by having this inference I'd prefer that.
Another option would be to require stubs packages to always declare a module name, so we can tell -stubs
(stubs package) from _stubs
(regular module).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In one direction, https://typing.python.org/en/latest/spec/distributing.html#stub-only-packages is a clear MUST about the
-stubs
suffix. In the other direction, I think I'd try this out, and if there are really packages with let's sayfoo_stubs
we can add an override (tool.uv.build-backend.stubs = False
). If we can have one option less by having this inference I'd prefer that.
I think that's good enough for me.
Another option would be to require stubs packages to always declare a module name, so we can tell
-stubs
(stubs package) from_stubs
(regular module).
I do like this idea! But I agree that inference probably makes more sense, and if necessary, we can add a way to override it if it comes up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that we actually do have overrides: Setting the module name to _stubs
vs. -stubs
will trigger regular package vs. stubs package behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Yeah I think that SGTM!
Added some docs, mainly to make searching for "stubs" show that we support them. |
Stubs packages are different in that their name ends with
-stubs
, their module is<module name>-stubs
(with a dash, not the generally legal underscore) and their modules contain a__init__.pyi
instead of an__init__.py
(https://typing.python.org/en/latest/spec/distributing.html#stub-only-packages).We add support in the uv build backend by detecting the
-stubs
suffix.Fixes #13546