Skip to content

Commit

Permalink
no direct reference if egg in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentJeannot committed Apr 25, 2021
1 parent 210fa12 commit 4999357
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
2 changes: 2 additions & 0 deletions piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ def format_requirement(
# file:./ is a hack to use a relative path to a package
# Direct reference does not work for this, so only the URL is used
line = ireq.link.url
elif "#" in ireq.link.url and "egg=" in ireq.link.url.rsplit("#", 1)[1]:
line = ireq.link.url
else:
line = f"{ireq.name.lower()} @ {ireq.link.url}"
else:
Expand Down
68 changes: 38 additions & 30 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,44 @@ def test_format_requirement(from_line):
assert format_requirement(ireq) == "test==1.2"


def test_format_requirement_url(from_line):
ireq = from_line("https://example.com/example.zip")
assert format_requirement(ireq) == "https://example.com/example.zip"


def test_format_requirement_url_with_direct_link(from_line):
ireq = from_line("example @ https://example.com/example.zip")
assert format_requirement(ireq) == "example @ https://example.com/example.zip"


def test_format_requirement_url_with_direct_link_is_lower_case(from_line):
ireq = from_line("https://example.com/example.zip#egg=Example")
assert ireq.name == "Example"
assert (
format_requirement(ireq)
== "example @ https://example.com/example.zip#egg=Example"
)


def test_format_requirement_url_with_egg(from_line):
ireq = from_line("https://example.com/example.zip#egg=example")
assert (
format_requirement(ireq)
== "example @ https://example.com/example.zip#egg=example"
)


def test_format_requirement_url_relative_path(from_line):
ireq = from_line("file:./vendor/package.zip")
assert format_requirement(ireq) == "file:./vendor/package.zip"
@pytest.mark.parametrize(
("line", "expected"),
(
pytest.param(
"https://example.com/example.zip",
"https://example.com/example.zip",
id="simple url",
),
pytest.param(
"example @ https://example.com/example.zip",
"example @ https://example.com/example.zip",
id="direct reference",
),
pytest.param(
"Example @ https://example.com/example.zip",
"example @ https://example.com/example.zip",
id="direct reference lower case",
),
pytest.param(
"https://example.com/example.zip#egg=example",
"https://example.com/example.zip#egg=example",
id="url with egg",
),
pytest.param(
"example @ https://example.com/example.zip?egg=test#subdirectory=project_a",
"example @ https://example.com/example.zip?egg=test#subdirectory=project_a",
id="egg as query",
),
pytest.param(
"file:./vendor/package.zip#egg=example",
"file:./vendor/package.zip#egg=example",
id="relative path",
),
),
)
def test_format_requirement_url(from_line, line, expected):
ireq = from_line(line)
assert format_requirement(ireq) == expected


def test_format_requirement_editable_vcs(from_editable):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_iter_lines__hash_missing(capsys, writer, from_line):

expected_lines = (
MESSAGE_UNHASHED_PACKAGE,
"example @ file:///example/#egg=example",
"file:///example/#egg=example",
"test==1.2 \\\n --hash=FAKEHASH",
)
assert tuple(lines) == expected_lines
Expand All @@ -173,8 +173,8 @@ def test_iter_lines__no_warn_if_only_unhashable_packages(writer, from_line):
lines = writer._iter_lines(ireqs, hashes=hashes)

expected_lines = (
"unhashable-pkg1 @ file:///unhashable-pkg1/#egg=unhashable-pkg1",
"unhashable-pkg2 @ file:///unhashable-pkg2/#egg=unhashable-pkg2",
"file:///unhashable-pkg1/#egg=unhashable-pkg1",
"file:///unhashable-pkg2/#egg=unhashable-pkg2",
)
assert tuple(lines) == expected_lines

Expand Down

0 comments on commit 4999357

Please sign in to comment.