Skip to content

Commit 0bf9222

Browse files
authored
Fix bug where relax would fail when git dependencies are present (#90)
* Add failing test case for #89 * Avoid updating the constraint when it is empty * Improve error message when constraint updates fail
1 parent d4928bc commit 0bf9222

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/poetry_relax/_core.py

+10
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,23 @@ def drop_caret_bound_from_dependency(dependency: "Dependency") -> "Dependency":
255255
If the dependency does not use a caret constraint to specify its upper bound,
256256
it will not be changed but a new copy will be returned.
257257
"""
258+
# If the constraint is empty, there is nothing to do
259+
if not dependency.pretty_constraint:
260+
return dependency
261+
258262
new_version = mutate_constraint(
259263
dependency.pretty_constraint, drop_upper_bound_from_caret_constraint
260264
)
261265

262266
# Copy the existing dependency to retain as much information as possible
263267
new_dependency = copy(dependency)
264268

269+
# If the constraint is empty, assignment will fail
270+
if not new_version:
271+
raise ValueError(
272+
f"Updating constraint for {dependency} resulted in an empty version"
273+
)
274+
265275
# Update the constraint to the new version
266276
# The property setter parses this into a proper constraint type
267277
new_dependency.constraint = new_version # type: ignore

tests/test_command.py

+16
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,22 @@ def test_dependency_with_additional_options(relax_command: PoetryCommandTester):
335335
assert relax_command.status_code == 0
336336

337337

338+
def test_dependency_with_git_url(relax_command: PoetryCommandTester):
339+
with update_pyproject() as pyproject:
340+
pyproject["tool"]["poetry"]["dependencies"]["test"] = {
341+
"git": "https://github.com/zanieb/test.git"
342+
}
343+
344+
with assert_pyproject_matches() as expected_config:
345+
relax_command.execute()
346+
347+
expected_config["tool"]["poetry"]["dependencies"]["test"] = {
348+
"git": "https://github.com/zanieb/test.git"
349+
}
350+
351+
assert relax_command.status_code == 0
352+
353+
338354
def test_dependency_with_multiple_conditional_versions(
339355
relax_command: PoetryCommandTester,
340356
):

0 commit comments

Comments
 (0)