Skip to content

Commit

Permalink
Merge pull request #26 from KotlinIsland/feat/dont-up-zero
Browse files Browse the repository at this point in the history
(🎁) feat: Preserve zero based notation
  • Loading branch information
MousaZeidBaker authored Aug 30, 2023
2 parents cde5350 + 8a5d3cb commit 0b6f878
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/poetry_plugin_up/command.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Any, Dict, Iterable, List

from cleo.helpers import argument, option
Expand Down Expand Up @@ -134,6 +135,11 @@ def handle_dependency(
self.line(f"No new version for '{dependency.name}'")
return

# preserve zero based carets ('^0.0') when bumping
version = re.match(r"\^([0.]+)", dependency.pretty_constraint)
if version and candidate.pretty_version.startswith(version[1]):
return

if (
dependency.pretty_constraint[0] == "~"
and "." in dependency.pretty_constraint
Expand Down
42 changes: 42 additions & 0 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,45 @@ def test_handle_dependency_with_latest(
new_version=f"^{new_version}",
pyproject_content=content,
)


def test_handle_dependency_with_zero_caret(
up_cmd_tester: TestUpCommand,
mocker: MockerFixture,
) -> None:
dependency = Dependency(
name="foo",
constraint="^0",
groups=["main"],
)
new_version = "0.1"
package = Package(
name=dependency.name,
version=new_version,
)

content = parse("")

selector = Mock()
selector.find_best_candidate = Mock(return_value=package)
bump_version_in_pyproject_content = mocker.patch(
"poetry_plugin_up.command.UpCommand.bump_version_in_pyproject_content",
return_value=None,
)

up_cmd_tester.handle_dependency(
dependency=dependency,
latest=True,
pinned=False,
only_packages=[],
pyproject_content=content,
selector=selector,
)

selector.find_best_candidate.assert_called_once_with(
package_name=dependency.name,
target_package_version="*",
allow_prereleases=dependency.allows_prereleases(),
source=dependency.source_name,
)
bump_version_in_pyproject_content.assert_not_called()

0 comments on commit 0b6f878

Please sign in to comment.