Decrease start-up time of editable-installed entry points on newer versions of Python#2194
Decrease start-up time of editable-installed entry points on newer versions of Python#2194jaraco merged 3 commits intopypa:masterfrom
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.
should this use entry_points()['console_scripts'] perhaps instead?
There was a problem hiding this comment.
Wouldn't that enumerate every script for every package?
There was a problem hiding this comment.
iirc distribution already enumerates every package but I might be misremembering
There was a problem hiding this comment.
I think that's distributions:
There was a problem hiding this comment.
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.
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.
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.
I'll plan to consolidate this fork later... and just make some assertions about the result that are common to both behaviors.
jaraco
left a comment
There was a problem hiding this comment.
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.metadatais 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