Skip to content

Commit

Permalink
feat: add pinned option to include pinned dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Mousa Zeid Baker committed Dec 13, 2022
1 parent 1f64eed commit 7ff01f9
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/poetry_plugin_up/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class UpCommand(InstallerCommand):
short_name=None,
description="Update to latest available compatible versions.",
),
option(
long_name="pinned",
short_name=None,
description="Included pinned dependencies when updating to latest.",
),
option(
long_name="no-install",
short_name=None,
Expand All @@ -49,6 +54,7 @@ class UpCommand(InstallerCommand):
def handle(self) -> int:
only_packages = self.argument("packages")
latest = self.option("latest")
pinned = self.option("pinned")
no_install = self.option("no-install")
dry_run = self.option("dry-run")

Expand All @@ -60,6 +66,7 @@ def handle(self) -> int:
self.handle_dependency(
dependency=dependency,
latest=latest,
pinned=pinned,
only_packages=only_packages,
pyproject_content=pyproject_content,
selector=selector,
Expand Down Expand Up @@ -91,13 +98,14 @@ def handle_dependency(
self,
dependency: Dependency,
latest: bool,
pinned: bool,
only_packages: List[str],
pyproject_content: TOMLDocument,
selector: VersionSelector,
) -> None:
"""Handles a dependency"""

if not self.is_bumpable(dependency, only_packages, latest):
if not self.is_bumpable(dependency, only_packages, latest, pinned):
return

target_package_version = dependency.pretty_constraint
Expand Down Expand Up @@ -132,6 +140,7 @@ def is_bumpable(
dependency: Dependency,
only_packages: List[str],
latest: bool,
pinned: bool,
) -> bool:
"""Determines if a dependency can be bumped in pyproject.toml"""

Expand All @@ -141,8 +150,9 @@ def is_bumpable(
return False
if only_packages and dependency.name not in only_packages:
return False

constraint = dependency.pretty_constraint
if not latest:
constraint = dependency.pretty_constraint
if constraint[0].isdigit():
# pinned
return False
Expand All @@ -165,6 +175,11 @@ def is_bumpable(
# multiple requirements e.g. '>=1.0.0, <2.0.0'
return False

if not pinned:
if constraint[0].isdigit():
# pinned
return False

return True

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ garply = {path = "./"}
waldo = {git = "https://example.com/test/project.git"}

[tool.poetry.group.dev.dependencies]
fred = "^2.2.2"
fred = "1.1.1"
plugh = "^2.2.2"
xyzzy = "^2.2.2"
nacho = "^2.2.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[tool.poetry]
name = "simple-project"
version = "1.2.3"
description = "Some description."
authors = ["Mousa Zeid Baker"]
license = "MIT"

[tool.poetry.dependencies]
python = "^3.7"
foo = "^2.2.2"
bar = "^2.2.2"
baz = {version = "^2.2.2", extras = ["qux", "quux"]}
corge = {version = "^2.2.2", optional = true}
grault = {version = "^2.2.2", allow-prereleases = true}
garply = {path = "./"}
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"
nacho = "^2.2.2"
thud = "^2.2.2"

[tool.poetry.group.docs.dependencies]
foobar = "^2.2.2"
foobaz = "^2.2.2"
fooqux = "^2.2.2"
fooquux = "^2.2.2"
Foo_Corge = "^2.2.2"
2 changes: 2 additions & 0 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_handle_dependency(
up_cmd_tester.handle_dependency(
dependency=dependency,
latest=False,
pinned=False,
only_packages=[],
pyproject_content=content,
selector=selector,
Expand Down Expand Up @@ -80,6 +81,7 @@ def test_handle_dependency_with_latest(
up_cmd_tester.handle_dependency(
dependency=dependency,
latest=True,
pinned=True,
only_packages=[],
pyproject_content=content,
selector=selector,
Expand Down
39 changes: 38 additions & 1 deletion tests/unit/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def test_is_bumpable_is_false_when_source_type_is_git(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is False

Expand All @@ -130,6 +131,7 @@ def test_is_bumpable_is_false_when_source_type_is_file(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is False

Expand All @@ -146,6 +148,7 @@ def test_is_bumpable_is_false_when_source_type_is_directory(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is False

Expand All @@ -158,6 +161,7 @@ def test_is_bumpable_is_false_when_name_is_python(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is False

Expand All @@ -170,6 +174,7 @@ def test_is_bumpable_is_false_when_dependency_not_in_only_packages(
dependency=dependency,
only_packages=["bar"],
latest=False,
pinned=False,
)
assert is_bumpable is False

Expand All @@ -185,6 +190,7 @@ def test_is_bumpable_is_false_when_version_pinned(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is False

Expand All @@ -200,6 +206,7 @@ def test_is_bumpable_is_false_when_version_wildcard(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is False

Expand All @@ -215,6 +222,7 @@ def test_is_bumpable_is_false_when_version_less_than(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is False

Expand All @@ -230,6 +238,7 @@ def test_is_bumpable_is_false_when_version_greater_than(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is False

Expand All @@ -245,6 +254,7 @@ def test_is_bumpable_is_false_when_version_less_than_or_equal(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is False

Expand All @@ -260,6 +270,7 @@ def test_is_bumpable_is_false_when_version_inequality(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is False

Expand All @@ -275,6 +286,7 @@ def test_is_bumpable_is_false_when_version_multiple_requirements(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is False

Expand All @@ -290,6 +302,7 @@ def test_is_bumpable_is_true_when_version_caret(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is True

Expand All @@ -305,6 +318,7 @@ def test_is_bumpable_is_true_when_version_tilde(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is True

Expand All @@ -320,6 +334,7 @@ def test_is_bumpable_is_true_when_version_greater_than_or_equal(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is True

Expand All @@ -335,11 +350,12 @@ def test_is_bumpable_is_true_when_version_tilde_pep440(
dependency=dependency,
only_packages=[],
latest=False,
pinned=False,
)
assert is_bumpable is True


def test_is_bumpable_is_true_when_version_pinned_and_latest(
def test_is_bumpable_is_false_when_version_pinned_and_latest(
up_cmd_tester: TestUpCommand,
) -> None:
dependency = Dependency(
Expand All @@ -350,6 +366,23 @@ def test_is_bumpable_is_true_when_version_pinned_and_latest(
dependency=dependency,
only_packages=[],
latest=True,
pinned=False,
)
assert is_bumpable is False


def test_is_bumpable_is_true_when_version_pinned_and_latest_and_pinned(
up_cmd_tester: TestUpCommand,
) -> None:
dependency = Dependency(
name="foo",
constraint="1.2.3",
)
is_bumpable = up_cmd_tester.is_bumpable(
dependency=dependency,
only_packages=[],
latest=True,
pinned=True,
)
assert is_bumpable is True

Expand All @@ -365,6 +398,7 @@ def test_is_bumpable_is_true_when_version_wildcard_and_latest(
dependency=dependency,
only_packages=[],
latest=True,
pinned=False,
)
assert is_bumpable is True

Expand All @@ -380,6 +414,7 @@ def test_is_bumpable_is_true_when_version_less_than_and_latest(
dependency=dependency,
only_packages=[],
latest=True,
pinned=False,
)
assert is_bumpable is True

Expand All @@ -395,6 +430,7 @@ def test_is_bumpable_is_true_when_version_greater_than_and_latest(
dependency=dependency,
only_packages=[],
latest=True,
pinned=False,
)
assert is_bumpable is True

Expand All @@ -410,5 +446,6 @@ def test_is_bumpable_is_true_when_version_less_than_or_equal_and_latest(
dependency=dependency,
only_packages=[],
latest=True,
pinned=False,
)
assert is_bumpable is True

0 comments on commit 7ff01f9

Please sign in to comment.