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

Fix a bug where pip-compile setup.py would fail due to URL dependency #1347

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 2 additions & 5 deletions piptools/scripts/compile.py
Expand Up @@ -7,10 +7,7 @@
import click
from click.utils import safecall
from pip._internal.commands import create_command
from pip._internal.req.constructors import (
install_req_from_line,
install_req_from_req_string,
)
from pip._internal.req.constructors import install_req_from_line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember struggling for hours to understand the difference between these two functions, and it seems that I still didn't fully get them... thanks @atugushev 👍🏽

from pip._internal.utils.misc import redact_auth_from_url
from pip._vendor.pep517 import meta

Expand Down Expand Up @@ -359,7 +356,7 @@ def cli(
comes_from = f"{dist.metadata.get_all('Name')[0]} ({src_file})"
constraints.extend(
[
install_req_from_req_string(req, comes_from=comes_from)
install_req_from_line(req, comes_from=comes_from)
for req in dist.requires or []
]
)
Expand Down
62 changes: 34 additions & 28 deletions tests/test_cli_compile.py
Expand Up @@ -39,42 +39,48 @@ def test_command_line_overrides_pip_conf(pip_with_index_conf, runner):


@pytest.mark.network
def test_command_line_setuptools_read(runner, make_pip_conf):
make_pip_conf(
dedent(
"""\
[global]
disable-pip-version-check = True
"""
)
@pytest.mark.parametrize(
("install_requires", "expected_output"),
(
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",
id="zip URL",
),
pytest.param(
"pip-tools @ git+https://github.com/jazzband/pip-tools@7d86c8d3",
"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/"
"89872db07ae70770fba97205b0737c17ef013d0d1c790"
"899c16bb8bac419/pip_tools-3.6.1-py2.py3-none-any.whl",
id="wheel URL",
),
),
)
def test_command_line_setuptools_read(
runner, make_pip_conf, make_package, install_requires, expected_output
):
package_dir = make_package(
name="fake-setuptools-a",
install_requires=(install_requires,),
)

with open("setup.py", "w") as package:
package.write(
dedent(
"""\
from setuptools import setup
setup(
name="fake-setuptools-a",
install_requires=["small-fake-a==0.1"]
)
"""
)
)
out = runner.invoke(
cli,
["--no-header", "--no-emit-find-links", "--find-links", MINIMAL_WHEELS_PATH],
(str(package_dir / "setup.py"), "--find-links", MINIMAL_WHEELS_PATH),
)

assert out.stderr == dedent(
"""\
small-fake-a==0.1
# via fake-setuptools-a (setup.py)
"""
)
assert expected_output in out.stderr.splitlines()

# check that pip-compile generated a configuration file
assert os.path.exists("requirements.txt")
assert (package_dir / "requirements.txt").exists()


@pytest.mark.network
Expand Down