Skip to content

Commit

Permalink
(joe) address requirement creation from other paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jbylund committed Oct 6, 2021
1 parent dba95e8 commit 44a7076
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/10550.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve performance of dependency resolution.
8 changes: 5 additions & 3 deletions src/pip/_internal/resolution/resolvelib/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
cast,
)

from pip._vendor.packaging.requirements import InvalidRequirement
from pip._vendor.packaging.requirements import Requirement as PackagingRequirement
from pip._vendor.packaging.requirements import (
InvalidRequirement,
get_or_create_requirement,
)
from pip._vendor.packaging.specifiers import SpecifierSet
from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
from pip._vendor.resolvelib import ResolutionImpossible
Expand Down Expand Up @@ -365,7 +367,7 @@ def find_candidates(
# If the current identifier contains extras, add explicit candidates
# from entries from extra-less identifier.
with contextlib.suppress(InvalidRequirement):
parsed_requirement = PackagingRequirement(identifier)
parsed_requirement = get_or_create_requirement(identifier)
explicit_candidates.update(
self._iter_explicit_candidates_from_base(
requirements.get(parsed_requirement.name, ()),
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_req.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,13 +657,15 @@ def test_parse_editable_local_extras(
{"bar", "baz"},
)


def test_get_or_create_caching() -> None:
"""test caching of get_or_create requirement"""
teststr = "affinegap==1.10"
assert get_or_create_requirement(teststr) == Requirement(teststr)
assert not(get_or_create_requirement(teststr) is Requirement(teststr))
assert not (get_or_create_requirement(teststr) is Requirement(teststr))
assert get_or_create_requirement(teststr) is get_or_create_requirement(teststr)


def test_exclusive_environment_markers() -> None:
"""Make sure RequirementSet accepts several excluding env markers"""
eq36 = install_req_from_line("Django>=1.6.10,<1.7 ; python_version == '3.6'")
Expand Down

0 comments on commit 44a7076

Please sign in to comment.