Skip to content

Commit

Permalink
Fix a bug where pip-compile setup.py would fail with URL deps (#1347)
Browse files Browse the repository at this point in the history
  • Loading branch information
atugushev committed Mar 11, 2021
1 parent fe6dd97 commit 20d873d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
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
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

0 comments on commit 20d873d

Please sign in to comment.