Skip to content

Commit

Permalink
Merge pull request #2 from albertferras-vrf/patch-1-tests
Browse files Browse the repository at this point in the history
UV Pip Compile increase test coverage
  • Loading branch information
avilaton authored Aug 21, 2024
2 parents c1739f1 + 6f12f60 commit 93342d0
Show file tree
Hide file tree
Showing 21 changed files with 841 additions and 25 deletions.
2 changes: 1 addition & 1 deletion python/helpers/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plette==2.1.0
poetry==1.8.3
# TODO: Replace 3p package `toml` with 3.11's new stdlib `tomllib` once we drop support for Python 3.10.
toml==0.10.2
uv==0.2.26
uv==0.2.37

# Some dependencies will only install if Cython is present
Cython==3.0.10
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,13 @@ def pip_compile_options(filename)
options += pip_compile_index_options

if (requirements_file = compiled_file_for_filename(filename))
options += pip_compile_options_from_compiled_file(requirements_file)
end

command = "pyenv exec pip-compile"
if (requirements_file = compiled_file_for_filename(filename)) &&
requirements_file.content.include?("autogenerated by uv")
command = "pyenv exec uv pip compile"
if requirements_file.content.include?("uv pip compile")
options += uv_pip_compile_options_from_compiled_file(requirements_file)
command = "pyenv exec uv pip compile"
else
options += pip_compile_options_from_compiled_file(requirements_file)
command = "pyenv exec pip-compile"
end
end

[options.join(" "), command]
Expand Down Expand Up @@ -490,6 +490,30 @@ def pip_compile_options_from_compiled_file(requirements_file)
options
end

def uv_pip_compile_options_from_compiled_file(requirements_file)
options = ["--output-file=#{requirements_file.name}"]

options << "--no-emit-index-url" unless requirements_file.content.include?("index-url http")

options << "--generate-hashes" if requirements_file.content.include?("--hash=sha")

options << "--no-annotate" unless requirements_file.content.include?("# via ")

options << "--no-header"

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

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

options << "--emit-build-options" if (requirements_file.content.include?("--no-binary") || requirements_file.content.include?("--only-binary"))

if (resolver = RESOLVER_REGEX.match(requirements_file.content))
options << "--resolver=#{resolver}"
end

options
end

def pip_compile_index_options
credentials
.select { |cred| cred["type"] == "python_index" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,6 @@
end
end

context "with a uv header" do
let(:manifest_fixture_name) { "unpinned_uv.in" }
let(:generated_fixture_name) { "pip_compile_uv_header.txt" }

it "upgrades attrs to latest" do
expect(updated_files.count).to eq(1)
expect(updated_files.first.content).to include("attrs==18.1.0")
expect(updated_files.first.content).to include("This file was autogenerated by uv")
end
end

context "with a no-binary flag" do
let(:manifest_fixture_name) { "no_binary.in" }
let(:generated_fixture_name) { "pip_compile_no_binary.txt" }
Expand Down
Loading

0 comments on commit 93342d0

Please sign in to comment.