Skip to content

Commit

Permalink
Python: Honour --strip-extras flag of pip-compile
Browse files Browse the repository at this point in the history
The `--strip-extras` flag of `pip-compile` is useful to generate
contstraints files (instead of the more traditional requirements files)
from some `constraints.in` file.

Constraints files can't have extras markers on the packages (this
wouldn't make much sense indeed), hence they need to be stripped. Since
`pip-tools` 6.2.0 this is supported by using the `--strip-extras` flag.

This commit adds this as a 'recognized' flag: if it's found in an
existing `foo.txt` file, it will be passed to `pip-compile` when some
`foo.in` file is updated.

See: dependabot#3974 (comment)
See: dependabot#3974 (comment)
See: jazzband/pip-tools#1300 (comment)
  • Loading branch information
NicolasT committed Nov 22, 2021
1 parent ebe338e commit 2cf1980
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ def pip_compile_options_from_compiled_file(requirements_file)
options << "--no-header" unless requirements_file.content.include?("autogenerated by pip-c")

options << "--pre" if requirements_file.content.include?("--pre")

options << "--strip-extras" if requirements_file.content.include?("--strip-extras")

options
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,5 +505,21 @@
end
end
end

context "with stripped extras" do
let(:manifest_fixture_name) { "strip_extras.in" }
let(:generated_fixture_name) { "pip_compile_strip_extras.txt" }
let(:dependency_name) { "cachecontrol" }
let(:dependency_version) { "0.12.10" }
let(:dependency_previous_version) { "0.12.9" }

it "doesn't add an extras annotation on cachecontrol" do
expect(updated_files.count).to eq(1)
expect(updated_files.first.content).to include("--strip-extras")
expect(updated_files.first.content).to include("cachecontrol==0.12.10")
expect(updated_files.first.content).
to_not include("cachecontrol[filecache]==")
end
end
end
end
1 change: 1 addition & 0 deletions python/spec/fixtures/pip_compile_files/strip_extras.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cachecontrol[filecache]
22 changes: 22 additions & 0 deletions python/spec/fixtures/requirements/pip_compile_strip_extras.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# This file is autogenerated by pip-compile with python 3.10
# To update, run:
#
# pip-compile --strip-extras --output-file=constraints.txt constraints.in
#
cachecontrol==0.12.10
# via -r constraints.in
certifi==2021.10.8
# via requests
charset-normalizer==2.0.7
# via requests
idna==3.3
# via requests
lockfile==0.12.2
# via cachecontrol
msgpack==1.0.2
# via cachecontrol
requests==2.26.0
# via cachecontrol
urllib3==1.26.7
# via requests

0 comments on commit 2cf1980

Please sign in to comment.