-
-
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
Decrease start-up time of editable-installed entry points on newer versions of Python #2194
Conversation
|
||
if __name__ == '__main__': | ||
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) | ||
for entry_point in distribution(%(spec)r).entry_points: |
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.
should this use entry_points()['console_scripts']
perhaps instead?
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.
Wouldn't that enumerate every script for every package?
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.
iirc distribution
already enumerates every package but I might be misremembering
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.
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 was surprised this interface isn't nicer :/. Yes, I believe this usage is correct. Probably importlib-metadata should provide some helpers to make this usage simpler, though that won't help for this implementation.
load_entry_point(%(spec)r, %(group)r, %(name)r)() | ||
) | ||
""").lstrip() | ||
if sys.version_info >= (3, 8): |
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'm trying to imagine a way this could rely also on importlib_metadata
and thus eliminate the dependency on pkg_resources. I dislike that the code has to be forked to support the legacy behavior (and until Python 3.7 support is dropped). Perhaps that can't be solved now.
load_entry_point(%(spec)r, %(group)r, %(name)r)() | ||
) | ||
""").lstrip() | ||
if sys.version_info >= (3, 8): |
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 also wonder if it would make sense to unify these two scripts into one which tries importlib-metadata then falls back to pkg_resources. That approach would avoid the fork and would also avoid the suppressed linter errors.
load_entry_point('spec', 'console_scripts', 'name')() | ||
) | ||
""") # noqa: E501 | ||
if sys.version_info >= (3, 8): |
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'll plan to consolidate this fork later... and just make some assertions about the result that are common to both behaviors.
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.
My comments are largely for edification. No action is necessary. Let's adopt this and iterate on it. Thanks for the contrib.
Thank you! |
Needs small fix #2196 |
pypa/setuptools#2194 git-svn-id: file:///srv/repos/svn-community/svn@852053 9fca08f4-af9d-4005-b8df-a31f2cc04f65
pypa/setuptools#2194 git-svn-id: file:///srv/repos/svn-community/svn@852053 9fca08f4-af9d-4005-b8df-a31f2cc04f65
Summary of changes
When
importlib.metadata
is present, the generated scripts will use that rather than the significantly slowerpkg_resources
.Closes #510 completely as editable installs are the final affected part (that is actionable) brought up in that issue and what I've been experiencing the last 2 weeks (it's indeed annoying)
The issue is locked, so here are some pings: @jaraco @scopatz @ninjaaron @untitaker @asottile @pganssle @gaborbernat @pfmoore @pradyunsg
Benchmark
Before and after, using hyperfine:
Pull Request Checklist