Skip to content

Commit

Permalink
Add support for pip==23.1 where refactored requirement options (#1832)
Browse files Browse the repository at this point in the history
  • Loading branch information
atugushev committed Mar 31, 2023
1 parent aa59f6a commit f2bbd5e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
12 changes: 10 additions & 2 deletions tests/conftest.py
Expand Up @@ -23,7 +23,7 @@
from pip._vendor.packaging.version import Version
from pip._vendor.pkg_resources import Requirement

from piptools._compat.pip_compat import uses_pkg_resources
from piptools._compat.pip_compat import PIP_VERSION, uses_pkg_resources
from piptools.cache import DependencyCache
from piptools.exceptions import NoCandidateFound
from piptools.logging import log
Expand Down Expand Up @@ -216,7 +216,15 @@ def base_resolver(depcache):

@pytest.fixture
def from_line():
return install_req_from_line
def _from_line(*args, **kwargs):
if PIP_VERSION[:2] <= (23, 0):
hash_options = kwargs.pop("hash_options", {})
options = kwargs.pop("options", {})
options["hashes"] = hash_options
kwargs["options"] = options
return install_req_from_line(*args, **kwargs)

return _from_line


@pytest.fixture
Expand Down
8 changes: 4 additions & 4 deletions tests/test_repository_local.py
Expand Up @@ -23,8 +23,8 @@ def test_get_hashes_local_repository_cache_miss(

def test_get_hashes_local_repository_cache_hit(from_line, repository):
# Create an install requirement with the hashes included in its options
options = {"hashes": {"sha256": [entry.split(":")[1] for entry in EXPECTED]}}
req = from_line("small-fake-a==0.1", options=options)
hash_options = {"sha256": [entry.split(":")[1] for entry in EXPECTED]}
req = from_line("small-fake-a==0.1", hash_options=hash_options)
existing_pins = {key_from_ireq(req): req}

# Use fake repository so that we know the hashes are coming from cache
Expand All @@ -44,8 +44,8 @@ def test_toggle_reuse_hashes_local_repository(
capsys, pip_conf, from_line, pypi_repository, reuse_hashes, expected
):
# Create an install requirement with the hashes included in its options
options = {"hashes": {"sha256": [entry.split(":")[1] for entry in NONSENSE]}}
req = from_line("small-fake-a==0.1", options=options)
hash_options = {"sha256": [entry.split(":")[1] for entry in NONSENSE]}
req = from_line("small-fake-a==0.1", hash_options=hash_options)
existing_pins = {key_from_ireq(req): req}

local_repository = LocalRequirementsRepository(
Expand Down
40 changes: 17 additions & 23 deletions tests/test_sync.py
Expand Up @@ -335,37 +335,31 @@ def test_sync_requirement_file_with_hashes(
to_install = {
from_line(
"django==1.8",
options={
"hashes": {
"sha256": [
"6a03ce2feafdd193a0ba8a26dbd9773e"
"757d2e5d5e7933a62eac129813bd381a"
]
}
hash_options={
"sha256": [
"6a03ce2feafdd193a0ba8a26dbd9773e"
"757d2e5d5e7933a62eac129813bd381a"
]
},
),
from_line(
"click==4.0",
options={
"hashes": {
"sha256": [
"9ab1d313f99b209f8f71a629f3683303"
"0c8d7c72282cf7756834baf567dca662"
]
}
hash_options={
"sha256": [
"9ab1d313f99b209f8f71a629f3683303"
"0c8d7c72282cf7756834baf567dca662"
]
},
),
from_line(
"pytz==2017.2",
options={
"hashes": {
"sha256": [
"d1d6729c85acea542367138286862712"
"9432fba9a89ecbb248d8d1c7a9f01c67",
"f5c056e8f62d45ba8215e5cb8f50dfcc"
"b198b4b9fbea8500674f3443e4689589",
]
}
hash_options={
"sha256": [
"d1d6729c85acea542367138286862712"
"9432fba9a89ecbb248d8d1c7a9f01c67",
"f5c056e8f62d45ba8215e5cb8f50dfcc"
"b198b4b9fbea8500674f3443e4689589",
]
},
),
}
Expand Down
12 changes: 5 additions & 7 deletions tests/test_utils.py
Expand Up @@ -231,13 +231,11 @@ def test_dedup():
def test_get_hashes_from_ireq(from_line):
ireq = from_line(
"pytz==2017.2",
options={
"hashes": {
"sha256": [
"d1d6729c85acea5423671382868627129432fba9a89ecbb248d8d1c7a9f01c67",
"f5c056e8f62d45ba8215e5cb8f50dfccb198b4b9fbea8500674f3443e4689589",
]
}
hash_options={
"sha256": [
"d1d6729c85acea5423671382868627129432fba9a89ecbb248d8d1c7a9f01c67",
"f5c056e8f62d45ba8215e5cb8f50dfccb198b4b9fbea8500674f3443e4689589",
]
},
)
expected = {
Expand Down

0 comments on commit f2bbd5e

Please sign in to comment.