-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Generate distutils-stubs
on install
#4861
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
base: main
Are you sure you want to change the base?
Conversation
Aaaah, right, I forgot that Overall still an improvement (and typeshed won't have to special case this stub anymore) and a necessary step for #2345 |
setup.py
Outdated
module = "setuptools._distutils." + str(relative_path.with_suffix("")).replace( | ||
os.sep, "." | ||
).removesuffix(".__init__") |
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.
Alternative code for readability (but less "correct" because replace
is run on an unnecessary extra bit of str
):
module = "setuptools._distutils." + str(relative_path.with_suffix("")).replace( | |
os.sep, "." | |
).removesuffix(".__init__") | |
module = ( | |
("setuptools._distutils." + str(relative_path.with_suffix(""))) | |
.replace(os.sep, ".") | |
.removesuffix(".__init__") | |
) |
Playing with it some more (also changed with_suffix
for removesuffix
, just to see):
module = "setuptools._distutils." + str(relative_path.with_suffix("")).replace( | |
os.sep, "." | |
).removesuffix(".__init__") | |
module = ( | |
"setuptools._distutils." # (don't unwrap) | |
+ str(relative_path) | |
.removesuffix(".py") | |
.replace(os.sep, ".") | |
.removesuffix(".__init__") | |
) |
73befc0
to
d9e413e
Compare
I think this doesn't work with tox because of PEP660 editable installs? I'll need help to get that working. |
This comment was marked as resolved.
This comment was marked as resolved.
…te-distuttils-stubs-on-install
…te-distuttils-stubs-on-install
@@ -132,7 +132,7 @@ def do_install_data(self) -> None: | |||
site_packages = os.path.normcase(os.path.realpath(_get_purelib())) | |||
old, self.distribution.data_files = self.distribution.data_files, [] | |||
|
|||
for item in old: | |||
for item in old or (): |
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 would previously raise if self.distribution.data_files
was None
self, | ||
infile: StrPath, | ||
outfile: StrPathT, | ||
preserve_mode: bool = True, | ||
preserve_times: bool = True, | ||
link: str | None = None, | ||
level: object = 1, | ||
) -> tuple[StrPathT | str, bool]: | ||
level: int = 1, |
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 was typed as object
because it's unused. However, distutils types it as int
.
So either distutils should change it to object
(or Any
) to indicate that anything can be passed to level
and that subclasses are not intended to implement it.
Or, if some subclasses are meant to implement it, then this should indeed be level: int
even if unused.
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 #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:
Further Disadvantages over #4704:
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
newsfragments/
.(See documentation for details)