Skip to content

Commit

Permalink
Merge pull request #2011 from chrysle/requirements-header-filter-out-…
Browse files Browse the repository at this point in the history
…origin-ireqs

Filter out origin ireqs for extra requirements before writing output annotations
  • Loading branch information
webknjaz committed Nov 1, 2023
2 parents 65b0d36 + f6ff30b commit 3f8108c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
6 changes: 5 additions & 1 deletion piptools/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ def _format_requirement(
if src_ireq.comes_from
}

if 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
):
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 3f8108c

Please sign in to comment.