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

feat: add option to include zero based carets dependencies #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion src/poetry_plugin_up/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class UpCommand(InstallerCommand):
"Include pinned (exact) dependencies when updating to latest."
),
),
option(
long_name="zero-based-carets",
short_name=None,
description="Include zero based carets dependencies.",
),
option(
long_name="exclude",
short_name=None,
Expand Down Expand Up @@ -71,6 +76,7 @@ def handle(self) -> int:
only_packages = self.argument("packages")
latest = self.option("latest")
pinned = self.option("pinned")
zero_based_carets = self.option("zero-based-carets")
no_install = self.option("no-install")
dry_run = self.option("dry-run")
exclude = self.option("exclude")
Expand All @@ -96,6 +102,7 @@ def handle(self) -> int:
dependency=dependency,
latest=latest,
pinned=pinned,
zero_based_carets=zero_based_carets,
only_packages=only_packages,
pyproject_content=pyproject_content,
selector=selector,
Expand Down Expand Up @@ -135,6 +142,7 @@ def handle_dependency(
dependency: Dependency,
latest: bool,
pinned: bool,
zero_based_carets: bool,
only_packages: List[str],
pyproject_content: TOMLDocument,
selector: VersionSelector,
Expand Down Expand Up @@ -169,7 +177,11 @@ def handle_dependency(

# 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]):
if (
not zero_based_carets
and version
and candidate.pretty_version.startswith(version[1])
):
return

if (
Expand Down
54 changes: 54 additions & 0 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_handle_dependency(
dependency=dependency,
latest=False,
pinned=False,
zero_based_carets=False,
only_packages=[],
exclude=[],
pyproject_content=content,
Expand Down Expand Up @@ -84,6 +85,7 @@ def test_handle_dependency_with_latest(
dependency=dependency,
latest=True,
pinned=True,
zero_based_carets=False,
only_packages=[],
exclude=[],
pyproject_content=content,
Expand Down Expand Up @@ -132,6 +134,7 @@ def test_handle_dependency_with_zero_caret(
dependency=dependency,
latest=True,
pinned=False,
zero_based_carets=False,
only_packages=[],
exclude=[],
pyproject_content=content,
Expand All @@ -148,6 +151,55 @@ def test_handle_dependency_with_zero_caret(
bump_version_in_pyproject_content.assert_not_called()


def test_handle_dependency_with_zero_caret_when_included(
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,
zero_based_carets=True,
only_packages=[],
exclude=[],
pyproject_content=content,
selector=selector,
preserve_wildcard=False,
)

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_called_once_with(
dependency=dependency,
new_version=f"^{new_version}",
pyproject_content=content,
)


def test_handle_dependency_excluded(
up_cmd_tester: TestUpCommand,
mocker: MockerFixture,
Expand Down Expand Up @@ -176,6 +228,7 @@ def test_handle_dependency_excluded(
dependency=dependency,
latest=False,
pinned=False,
zero_based_carets=False,
only_packages=[],
exclude=["foo"],
pyproject_content=content,
Expand Down Expand Up @@ -215,6 +268,7 @@ def test_handle_dependency_preserve_wildcard(
dependency=dependency,
latest=True,
pinned=False,
zero_based_carets=False,
only_packages=[],
exclude=[],
pyproject_content=content,
Expand Down