Skip to content

Commit

Permalink
Add functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysle committed Oct 27, 2023
1 parent 9dcd453 commit f6ff30b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
7 changes: 5 additions & 2 deletions piptools/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,11 @@ def _format_requirement(
if src_ireq.comes_from
}

# Filter out the origin install requirements for extras. See https://github.com/jazzband/pip-tools/issues/2003
if ireq.comes_from and (isinstance(ireq.comes_from, str) or ireq.comes_from.name != ireq.name):
# Filter out the origin install requirements for extras.
# See https://github.com/jazzband/pip-tools/issues/2003
if ireq.comes_from and (
isinstance(ireq.comes_from, str) or ireq.comes_from.name != ireq.name
):
required_by.add(_comes_from_as_string(ireq.comes_from))

required_by |= set(getattr(ireq, "_required_by", set()))
Expand Down
50 changes: 50 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3290,3 +3290,53 @@ def test_do_not_show_warning_on_explicit_strip_extras_option(

assert out.exit_code == 0
assert strip_extras_warning not in out.stderr


def test_origin_of_extra_requirement_not_written_to_annotations(
pip_conf, runner, make_package, make_wheel, tmp_path, tmpdir
):
req_in = tmp_path / "requirements.in"
package_with_extras = make_package(
"package_with_extras",
version="0.1",
extras_require={
"extra1": ["small-fake-a==0.1"],
"extra2": ["small-fake-b==0.1"],
},
)

dists_dir = tmpdir / "dists"
make_wheel(package_with_extras, dists_dir)

with open(req_in, "w") as req_out:
req_out.write("package-with-extras[extra1,extra2]")

out = runner.invoke(
cli,
[
"--output-file",
"-",
"--quiet",
"--no-header",
"--find-links",
str(dists_dir),
"--no-emit-options",
"--no-build-isolation",
req_in.as_posix(),
],
)

assert out.exit_code == 0, out
assert (
dedent(
f"""\
package-with-extras[extra1,extra2]==0.1
# via -r {req_in.as_posix()}
small-fake-a==0.1
# via package-with-extras
small-fake-b==0.1
# via package-with-extras
"""
)
== out.stdout
)

0 comments on commit f6ff30b

Please sign in to comment.