-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
Move to importlib-metadata for performance improvements #1324
Conversation
@@ -38,8 +38,9 @@ classifiers = | |||
packages = find: | |||
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.* | |||
install_requires = | |||
setuptools >= 30.0.0 | |||
pluggy >= 0.3.0, <1 | |||
importlib-metadata |
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.
shouldn't we version guard from above?
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.
yessss I wasn't sure what to put here, I'll go with >=0.12,<1
pkg = Requirement(require) | ||
pkg_name = canonicalize_name(pkg.name) | ||
if ( | ||
pkg.marker is None or pkg.marker.evaluate({"extra": ""}) |
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.
can you explain this check here 🤔 maybe put a comment because reading it seems kinda cryptic; why we need the extra?
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.
yeah this is a little bit weird
it's essentially a reimplement of pkg_resources.Requirement.requires
but using the importlib-metadata / packaging primitives
the pkg_resources api has:
def requires(self, extras=()):
so by default it does not pass extras at all.
the importlib_metadata
requires ends up looking like this for tox:
>>> for req in importlib_metadata.distribution('tox').requires:
... print(f'- {req}')
...
- setuptools>=30.0.0
- pluggy<1,>=0.3.0
- py<2,>=1.4.17
- six<2,>=1.0.0
- virtualenv>=14.0.0
- toml>=0.9.4
- filelock<4,>=3.0.0
- sphinx<3,>=2.0.0; extra == "docs"
- towncrier>=18.5.0; extra == "docs"
- pygments-github-lexers>=0.0.5; extra == "docs"
- sphinxcontrib-autoprogram>=0.1.5; extra == "docs"
- freezegun<1,>=0.3.11; extra == "testing"
- pathlib2<3,>=2.3.3; extra == "testing"
- pytest<5,>=3.0.0; extra == "testing"
- pytest-cov<3,>=2.5.1; extra == "testing"
- pytest-mock<2,>=1.10.0; extra == "testing"
- pytest-xdist<2,>=1.22.2; extra == "testing"
- pytest-randomly<2,>=1.2.3; extra == "testing"
- flaky<4,>=3.4.0; extra == "testing"
- psutil<6,>=5.6.1; (python_version != "3.4") and extra == "testing"
Converting one of those later ones into packaging
primitives:
>>> from packaging.requirements import Requirement
>>> req = Requirement('pytest-randomly<2,>=1.2.3; extra == "testing"')
>>> req.marker
<Marker('extra == "testing"')>
>>> req.marker.evaluate()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/tox/venv/lib/python3.6/site-packages/packaging/markers.py", line 296, in evaluate
return _evaluate_markers(self._markers, current_environment)
File "/tmp/tox/venv/lib/python3.6/site-packages/packaging/markers.py", line 221, in _evaluate_markers
lhs_value = _get_env(environment, lhs.value)
File "/tmp/tox/venv/lib/python3.6/site-packages/packaging/markers.py", line 203, in _get_env
"{0!r} does not exist in evaluation environment.".format(name)
packaging.markers.UndefinedEnvironmentName: 'extra' does not exist in evaluation environment.
>>> req.marker.evaluate({'extra': ''})
False
>>> req.marker.evaluate({'extra': 'testing'})
True
oh, heh, I was going to add the bounds for importlib-metadata -- I'll do that in another PR 😆 |
setup
(with ~some amount of pip requirements installed -- I used https://github.com/Yelp/paasta as it installs a bunch of things and I know they all build on my machine)
I used "best of 5" when picking the outputs below -- the version
0.0.0
is because I didn't havesetuptools-scm
when I built the dist -- just ignore that ;)before
after
savings
~90ms -- so somewhere between 30-40%
Contribution checklist:
(also see CONTRIBUTING.rst for details)
in message body
<issue number>.<type>.rst
for example (588.bugfix.rst)<type>
is must be one ofbugfix
,feature
,deprecation
,breaking
,doc
,misc
<your username>
"superuser
."CONTRIBUTORS
(preserving alphabetical order)