From b34604275a937faeb2a4b25b765429ecbaabef4d Mon Sep 17 00:00:00 2001 From: KotlinIsland Date: Sun, 12 Feb 2023 12:54:39 +1000 Subject: [PATCH] feat: Preserve tilde when bumping --- src/poetry_plugin_up/command.py | 12 ++++++++---- .../expected_pyproject_with_latest.toml | 2 +- .../expected_pyproject_with_latest_and_pinned.toml | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/poetry_plugin_up/command.py b/src/poetry_plugin_up/command.py index 65114fe..8d358b5 100644 --- a/src/poetry_plugin_up/command.py +++ b/src/poetry_plugin_up/command.py @@ -134,11 +134,15 @@ def handle_dependency( self.line(f"No new version for '{dependency.name}'") return - new_version = "^" + candidate.pretty_version + if ( + dependency.pretty_constraint[0] == "~" + and "." in dependency.pretty_constraint + ): + new_version = "~" + candidate.pretty_version + else: + new_version = "^" + candidate.pretty_version if not latest: - if dependency.pretty_constraint[0] == "~": - new_version = "~" + candidate.pretty_version - elif dependency.pretty_constraint[:2] == ">=": + if dependency.pretty_constraint[:2] == ">=": new_version = ">=" + candidate.pretty_version self.bump_version_in_pyproject_content( diff --git a/tests/fixtures/simple_project/expected_pyproject_with_latest.toml b/tests/fixtures/simple_project/expected_pyproject_with_latest.toml index 3f06949..9540a6a 100644 --- a/tests/fixtures/simple_project/expected_pyproject_with_latest.toml +++ b/tests/fixtures/simple_project/expected_pyproject_with_latest.toml @@ -18,7 +18,7 @@ waldo = {git = "https://example.com/test/project.git"} [tool.poetry.group.dev.dependencies] fred = "1.1.1" plugh = "^2.2.2" -xyzzy = "^2.2.2" +xyzzy = "~2.2.2" nacho = "^2.2.2" thud = "^2.2.2" diff --git a/tests/fixtures/simple_project/expected_pyproject_with_latest_and_pinned.toml b/tests/fixtures/simple_project/expected_pyproject_with_latest_and_pinned.toml index d3f77ad..f8000f0 100644 --- a/tests/fixtures/simple_project/expected_pyproject_with_latest_and_pinned.toml +++ b/tests/fixtures/simple_project/expected_pyproject_with_latest_and_pinned.toml @@ -18,7 +18,7 @@ waldo = {git = "https://example.com/test/project.git"} [tool.poetry.group.dev.dependencies] fred = "^2.2.2" plugh = "^2.2.2" -xyzzy = "^2.2.2" +xyzzy = "~2.2.2" nacho = "^2.2.2" thud = "^2.2.2"