Skip to content
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

PEP 440 Direct Reference support #1392

Merged
merged 17 commits into from Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion piptools/utils.py
Expand Up @@ -115,7 +115,18 @@ def format_requirement(
if ireq.editable:
line = f"-e {ireq.link.url}"
elif is_url_requirement(ireq):
line = ireq.link.url
# if the requirement has no name then it's just a URL
if not ireq.name:
FlorentJeannot marked this conversation as resolved.
Show resolved Hide resolved
line = ireq.link.url
# if it starts with "file:", PEP508 does not support direct reference
elif ireq.link.url.startswith("file:"):
FlorentJeannot marked this conversation as resolved.
Show resolved Hide resolved
line = ireq.link.url
# if egg is after # then it's not a direct reference
elif "#" in ireq.link.url and "egg=" in ireq.link.url.rsplit("#", 1)[1]:
line = ireq.link.url
# otherwise, it's a direct reference
else:
line = f"{ireq.name.lower()} @ {ireq.link.url}"
else:
line = str(ireq.req).lower()

Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli_compile.py
Expand Up @@ -47,19 +47,19 @@ def test_command_line_overrides_pip_conf(pip_with_index_conf, runner):
pytest.param("small-fake-a==0.1", "small-fake-a==0.1", id="regular"),
pytest.param(
"pip-tools @ https://github.com/jazzband/pip-tools/archive/7d86c8d3.zip",
"https://github.com/jazzband/pip-tools/archive/7d86c8d3.zip",
"pip-tools @ https://github.com/jazzband/pip-tools/archive/7d86c8d3.zip",
id="zip URL",
),
pytest.param(
"pip-tools @ git+https://github.com/jazzband/pip-tools@7d86c8d3",
"git+https://github.com/jazzband/pip-tools@7d86c8d3",
"pip-tools @ git+https://github.com/jazzband/pip-tools@7d86c8d3",
id="scm URL",
),
pytest.param(
"pip-tools @ https://files.pythonhosted.org/packages/06/96/"
"89872db07ae70770fba97205b0737c17ef013d0d1c790"
"899c16bb8bac419/pip_tools-3.6.1-py2.py3-none-any.whl",
"https://files.pythonhosted.org/packages/06/96/"
"pip-tools @ https://files.pythonhosted.org/packages/06/96/"
"89872db07ae70770fba97205b0737c17ef013d0d1c790"
"899c16bb8bac419/pip_tools-3.6.1-py2.py3-none-any.whl",
id="wheel URL",
Expand Down
1 change: 1 addition & 0 deletions tests/test_data/packages/fake_with_deps/setup.py
Expand Up @@ -18,5 +18,6 @@
"SQLAlchemy!=0.9.5,<2.0.0,>=0.7.8,>=1.0.0",
"python-memcached>=1.57,<2.0",
"xmltodict<=0.11,>=0.4.6",
"requests @ git+git://github.com/psf/requests@v2.25.1",
FlorentJeannot marked this conversation as resolved.
Show resolved Hide resolved
],
)
51 changes: 48 additions & 3 deletions tests/test_utils.py
Expand Up @@ -32,9 +32,54 @@ 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"
@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 lowered case",
),
pytest.param(
"exemple @ https://example.com/example.zip#egg=example",
FlorentJeannot marked this conversation as resolved.
Show resolved Hide resolved
"https://example.com/example.zip#egg=example",
id="url with egg after #",
),
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="url without egg after #",
),
pytest.param(
"file:./vendor/package.zip",
"file:./vendor/package.zip",
id="relative path",
),
pytest.param(
"file:vendor/package.zip",
"file:vendor/package.zip",
id="relative path",
),
pytest.param(
"file:///vendor/package.zip",
"file:///vendor/package.zip",
id="full 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