Skip to content

Commit

Permalink
remove local version specifier at poetry add (#9603)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby authored Aug 15, 2024
1 parent 36c7e18 commit 3ea8a5d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ def _find_best_version_for_package(
# TODO: find similar
raise ValueError(f"Could not find a matching version of package {name}")

return package.pretty_name, f"^{package.version.to_string()}"
version = package.version.without_local()
return package.pretty_name, f"^{version.to_string()}"

def _parse_requirements(self, requirements: list[str]) -> list[dict[str, Any]]:
from poetry.core.pyproject.exceptions import PyProjectException
Expand Down
28 changes: 28 additions & 0 deletions tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def repo_add_default_packages(repo: TestRepository) -> None:
repo.add_package(get_package("tomlkit", "0.5.5"))
repo.add_package(get_package("pyyaml", "3.13"))
repo.add_package(get_package("pyyaml", "4.2b2"))
repo.add_package(get_package("torch", "2.4.0+cpu"))


def test_add_no_constraint(app: PoetryTestApplication, tester: CommandTester) -> None:
Expand Down Expand Up @@ -133,6 +134,33 @@ def test_add_no_constraint(app: PoetryTestApplication, tester: CommandTester) ->
assert content["dependencies"]["cachy"] == "^0.2.0"


def test_add_local_version(app: PoetryTestApplication, tester: CommandTester) -> None:
tester.execute("torch")

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

assert tester.io.fetch_output() == expected
assert isinstance(tester.command, InstallerCommand)
assert tester.command.installer.executor.installations_count == 1

pyproject: dict[str, Any] = app.poetry.file.read()
content = pyproject["tool"]["poetry"]

assert "torch" in content["dependencies"]
assert content["dependencies"]["torch"] == "^2.4.0"


def test_add_non_package_mode_no_name(
project_factory: ProjectFactory,
command_tester_factory: CommandTesterFactory,
Expand Down

0 comments on commit 3ea8a5d

Please sign in to comment.