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
#11655 Remove use of pkg_resources #11730
Conversation
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.
Looks fine, but I'm not sure it's going to pass coverage. I'll switch the merge base to trunk now that it's reviewed, and hopefully that will run through CI
Co-authored-by: Glyph <glyph@twistedmatrix.com>
src/twisted/trial/__main__.py
Outdated
@@ -4,6 +4,15 @@ | |||
if __name__ == "__main__": | |||
import sys | |||
|
|||
from pkg_resources import load_entry_point | |||
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.
Sigh. Okay. Codecov is too smart for our trickery.
Which actually raises the question: why are we doing this faffing with packaging metadata, anyway? We used to do this because we wanted to be as similar as possible to the stubs that pip install
generated, but looking at a modern virtualenv, I see the stubs look like this:
#!/Users/glyph/.virtualenvs/Twisted/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from twisted.scripts.trial import run
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(run())
So that implies that this should instead simply be:
from twisted.scripts.trial import run
sys.exit(run())
Is there any reason not to do that?
(Suggestion in multiple parts below)
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.
very true
src/twisted/trial/__main__.py
Outdated
if sys.version_info >= (3, 8): | ||
from importlib.metadata import distribution | ||
else: | ||
from importlib_metadata import distribution |
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.
Part 1: no need for this package at all
if sys.version_info >= (3, 8): | |
from importlib.metadata import distribution | |
else: | |
from importlib_metadata import distribution |
src/twisted/trial/__main__.py
Outdated
sys.exit( | ||
next( | ||
ep | ||
for ep in distribution("twisted").entry_points | ||
if (ep.group, ep.name) == ("console_scripts", "trial") | ||
).load()() | ||
) |
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.
Part 2: let's not overcomplicate things
sys.exit( | |
next( | |
ep | |
for ep in distribution("twisted").entry_points | |
if (ep.group, ep.name) == ("console_scripts", "trial") | |
).load()() | |
) | |
from twisted.scripts.trial import run | |
sys.exit(run()) |
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.
Oops. Whatever we do here, twisted/__main__.py
also needs to be fixed in the same way.
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.
Made a suggestion to keep the script import inside the if __name__
block, but otherwise, if this passes tests let's land.
rebased |
Thanks @adiroiban ! |
Scope and purpose
Fixes #11655
See #11728 (comment)