Skip to content

Commit

Permalink
Fixing poetry major.minor compatibility
Browse files Browse the repository at this point in the history
Adding a test to ensure we don't update the pyproject.toml with a new python version, but temporarily we expand the range to allow the update to proceed.
  • Loading branch information
pavera authored and jeffwidman committed Nov 23, 2022
1 parent c066138 commit 0ac4e37
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def prepared_pyproject
content = sanitize(content)
content = freeze_other_dependencies(content)
content = freeze_dependencies_being_updated(content)
content = update_python_requirement(content)
content
end
end
Expand All @@ -131,6 +132,12 @@ def freeze_dependencies_being_updated(pyproject_content)
TomlRB.dump(pyproject_object)
end

def update_python_requirement(pyproject_content)
PyprojectPreparer.
new(pyproject_content: pyproject_content).
update_python_requirement(Helpers.python_major_minor(python_version))
end

def lock_declaration_to_new_version!(poetry_object, dep)
Dependabot::Python::FileParser::PyprojectFilesParser::POETRY_DEPENDENCY_TYPES.each do |type|
names = poetry_object[type]&.keys || []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def add_auth_env_vars(credentials)
end
end

def update_python_requirement(requirement)
pyproject_object = TomlRB.parse(@pyproject_content)
if pyproject_object.dig("tool", "poetry", "dependencies", "python")
pyproject_object["tool"]["poetry"]["dependencies"]["python"] = "~#{requirement}"
end
TomlRB.dump(pyproject_object)
end

def sanitize
# {{ name }} syntax not allowed
pyproject_content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
to start_with("8cea4ecb5b2230fbd4a33a67a4da004f1ccabad48352aaf040")
end

context "with a specified Python version", :slow do
context "with a specified Python version" do
let(:pyproject_fixture_name) { "python_310.toml" }
let(:lockfile_fixture_name) { "python_310.lock" }

Expand Down Expand Up @@ -112,6 +112,11 @@
requests = lockfile_obj["package"].find { |d| d["name"] == "requests" }
expect(requests["version"]).to eq("2.19.1")
end
it "does not change python version" do
updated_pyproj = updated_files.find { |f| f.name == "pyproject.toml" }
pyproj_obj = TomlRB.parse(updated_pyproj.content)
pyproj_obj["tool"]["poetry"]["dependencies"]["python"] == "3.10.7"
end
end

context "with a supported python version", :slow do
Expand Down

0 comments on commit 0ac4e37

Please sign in to comment.