Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove local version specifier at poetry add #9603

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading