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

Filter out origin ireqs for extra requirements before writing output annotations #2011

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
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]")
Comment on lines +3311 to +3312
Copy link
Member

Choose a reason for hiding this comment

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

Nit: in the future, use the pathlib interface of the tmp_path fixture.

Suggested change
with open(req_in, "w") as req_out:
req_out.write("package-with-extras[extra1,extra2]")
req_in.write_text("package-with-extras[extra1,extra2]", encoding="utf-8")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the hint!


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
)