Skip to content

Commit

Permalink
Fix adding existing packages with latest constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed Jul 19, 2019
1 parent 5654379 commit b6f4542
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ def _parse_requirements(
if " " in pair:
name, version = pair.split(" ", 2)
require["name"] = name
require["version"] = version
if version != "latest":
require["version"] = version
else:
m = re.match(
"^([^><=!: ]+)((?:>=|<=|>|<|!=|~=|~|\^).*)$", requirement.strip()
Expand Down
35 changes: 35 additions & 0 deletions tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,41 @@ def test_add_should_display_an_error_when_adding_existing_package_with_no_constr
assert "Package foo is already present" == str(e.value)


def test_add_should_work_when_adding_existing_package_with_latest_constraint(
app, repo, installer
):
content = app.poetry.file.read()
content["tool"]["poetry"]["dependencies"]["foo"] = "^1.0"
app.poetry.file.write(content)
command = app.find("add")
tester = CommandTester(command)

repo.add_package(get_package("foo", "1.1.2"))

tester.execute("foo@latest")

expected = """\
Using version ^1.1.2 for foo
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
- Installing foo (1.1.2)
"""

assert expected in tester.io.fetch_output()

content = app.poetry.file.read()["tool"]["poetry"]

assert "foo" in content["dependencies"]
assert content["dependencies"]["foo"] == "^1.1.2"


def test_add_chooses_prerelease_if_only_prereleases_are_available(app, repo, installer):
command = app.find("add")
tester = CommandTester(command)
Expand Down

0 comments on commit b6f4542

Please sign in to comment.