Skip to content

Commit

Permalink
Remove unused name_from_req() (#1334)
Browse files Browse the repository at this point in the history
  • Loading branch information
atugushev committed Mar 3, 2021
1 parent c10fd0e commit 21d56e4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 27 deletions.
10 changes: 0 additions & 10 deletions piptools/utils.py
Expand Up @@ -218,16 +218,6 @@ def dedup(iterable: Iterable[_T]) -> Iterable[_T]:
return iter(collections.OrderedDict.fromkeys(iterable))


def name_from_req(req):
"""Get the name of the requirement"""
if hasattr(req, "project_name"):
# from pkg_resources, such as installed dists for pip-sync
return req.project_name
else:
# from packaging, such as install requirements from requirements.txt
return req.name


def get_hashes_from_ireq(ireq: InstallRequirement) -> Set[str]:
"""
Given an InstallRequirement, return a set of string hashes in the format
Expand Down
4 changes: 2 additions & 2 deletions tests/test_minimal_upgrade.py
@@ -1,7 +1,7 @@
import pytest

from piptools.repositories import LocalRequirementsRepository
from piptools.utils import name_from_req
from piptools.utils import key_from_ireq


@pytest.mark.parametrize(
Expand Down Expand Up @@ -37,7 +37,7 @@ def test_no_upgrades(base_resolver, repository, from_line, input, pins, expected
existing_pins = dict()
for line in pins:
ireq = from_line(line)
existing_pins[name_from_req(ireq.req)] = ireq
existing_pins[key_from_ireq(ireq)] = ireq
local_repository = LocalRequirementsRepository(existing_pins, repository)
output = base_resolver(
input, prereleases=False, repository=local_repository
Expand Down
6 changes: 3 additions & 3 deletions tests/test_repository_local.py
Expand Up @@ -3,7 +3,7 @@
import pytest

from piptools.repositories.local import LocalRequirementsRepository
from piptools.utils import name_from_req
from piptools.utils import key_from_ireq
from tests.conftest import FakeRepository

EXPECTED = {"sha256:5e6071ee6e4c59e0d0408d366fe9b66781d2cf01be9a6e19a2433bb3c5336330"}
Expand All @@ -29,7 +29,7 @@ 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)
existing_pins = {name_from_req(req): req}
existing_pins = {key_from_ireq(req): req}

# Use fake repository so that we know the hashes are coming from cache
local_repository = LocalRequirementsRepository(existing_pins, repository)
Expand All @@ -50,7 +50,7 @@ def test_toggle_reuse_hashes_local_repository(
# 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)
existing_pins = {name_from_req(req): req}
existing_pins = {key_from_ireq(req): req}

local_repository = LocalRequirementsRepository(
existing_pins, pypi_repository, reuse_hashes=reuse_hashes
Expand Down
12 changes: 0 additions & 12 deletions tests/test_utils.py
Expand Up @@ -17,7 +17,6 @@
is_pinned_requirement,
is_url_requirement,
lookup_table,
name_from_req,
)


Expand Down Expand Up @@ -198,17 +197,6 @@ def test_is_url_requirement_filename(caplog, from_line, line):
assert is_url_requirement(ireq) is True


def test_name_from_req(from_line):
ireq = from_line("django==1.8")
assert name_from_req(ireq.req) == "django"


def test_name_from_req_with_project_name(from_line):
ireq = from_line("foo==1.8")
ireq.req.project_name = "bar"
assert name_from_req(ireq.req) == "bar"


@pytest.mark.parametrize(
("cli_args", "expected_command"),
(
Expand Down

0 comments on commit 21d56e4

Please sign in to comment.