Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #36 from MousaZeidBaker/feat/no-exact
Browse files Browse the repository at this point in the history
feat: add option to skip dependencies with an exact version
  • Loading branch information
MousaZeidBaker authored Mar 24, 2022
2 parents 54ce0ea + 283e771 commit 71fa963
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "poetryup"
version = "0.5.6"
version = "0.6.0"
description = "Update dependencies and bump their version in the pyproject.toml file"
authors = ["Mousa Zeid Baker"]
packages = [
Expand Down
6 changes: 5 additions & 1 deletion src/poetryup/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def poetryup(
default=False,
help="Whether to update dependencies to their latest version.",
),
skip_exact: bool = typer.Option(
default=False,
help="Whether to skip dependencies with an exact version.",
),
):
"""Update dependencies and bump their version in pyproject.toml file"""

Expand All @@ -30,7 +34,7 @@ def poetryup(
)

pyproject = Pyproject(pyproject_str)
pyproject.update_dependencies(latest)
pyproject.update_dependencies(latest, skip_exact)
Path("pyproject.toml").write_text(pyproject.dumps())


Expand Down
12 changes: 10 additions & 2 deletions src/poetryup/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def constraint(self) -> str:
elif type(self.version) is items.InlineTable:
if self.version.get("version", "").startswith(("^", "~")):
return self.version["version"][0]
return ""
return "" # dependencies with exact version or multiple versions


class Pyproject:
Expand Down Expand Up @@ -138,11 +138,16 @@ def list_lock_dependencies(self) -> List[Dependency]:

return dependencies

def update_dependencies(self, latest: bool = False) -> None:
def update_dependencies(
self,
latest: bool = False,
skip_exact: bool = False,
) -> None:
"""Update dependencies and bump their version in pyproject
Args:
latest: Whether to update dependencies to their latest version
skip_exact: Whether to skip dependencies with an exact version
"""

if latest:
Expand All @@ -152,6 +157,9 @@ def update_dependencies(self, latest: bool = False) -> None:
# other
groups = {}
for dependency in self.list_dependencies():
if skip_exact and dependency.constraint == "":
# skip dependencies with an exact version
continue
if type(dependency.version) is items.String:
groups[dependency.group] = groups.get(
dependency.group, []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[tool.poetry]
name = "test-poetryup"
version = "0.1.0"
description = "Test PoetryUp"
authors = ["Mousa Zeid Baker"]
packages = [
{ include = "test_poetryup", from = "src" }
]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/MousaZeidBaker/poetryup"
repository = "https://github.com/MousaZeidBaker/poetryup"
keywords=[
"packaging",
"dependency",
"poetry",
"poetryup",
]
include = ["LICENSE"]

[tool.poetry.dependencies]
python = "^3.6"
poetryup = "0.2.0"

[tool.poetry.dev-dependencies]

[tool.poetry.scripts]
poetryup = "src.test_poetryup.test_poetryup:main"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[tool.poetry]
name = "test-poetryup"
version = "0.1.0"
description = "Test PoetryUp"
authors = ["Mousa Zeid Baker"]
packages = [
{ include = "test_poetryup", from = "src" }
]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/MousaZeidBaker/poetryup"
repository = "https://github.com/MousaZeidBaker/poetryup"
keywords=[
"packaging",
"dependency",
"poetry",
"poetryup",
]
include = ["LICENSE"]

[tool.poetry.dependencies]
python = "^3.6"
poetryup = "0.1.0"

[tool.poetry.dev-dependencies]

[tool.poetry.scripts]
poetryup = "src.test_poetryup.test_poetryup:main"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
86 changes: 86 additions & 0 deletions tests/unit/test_pyproject.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
from pathlib import Path

from pytest_mock import MockerFixture

from poetryup.pyproject import Pyproject


Expand Down Expand Up @@ -211,6 +213,90 @@ def test_update_dependencies_latest_with_dependency_groups(
)


def test_update_dependencies_with_exact_version_dependency(
mock_poetry_commands,
) -> None:
pyproject_str = Path(
os.path.join(
os.path.dirname(__file__),
"fixtures/input_pyproject/",
"pyproject_with_exact_version_dependency.toml",
)
).read_text()
expected_pyproject_str = Path(
os.path.join(
os.path.dirname(__file__),
"fixtures/expected_pyproject/",
"pyproject_with_exact_version_dependency.toml",
)
).read_text()

pyproject = Pyproject(pyproject_str)
pyproject.update_dependencies()
assert pyproject.dumps() == expected_pyproject_str
assert (
pyproject.pyproject["tool"]["poetry"]["dependencies"]["poetryup"]
== "0.2.0"
)


def test_update_dependencies_latest_with_exact_version_dependency(
mock_poetry_commands,
) -> None:
pyproject_str = Path(
os.path.join(
os.path.dirname(__file__),
"fixtures/input_pyproject/",
"pyproject_with_exact_version_dependency.toml",
)
).read_text()
expected_pyproject_str = Path(
os.path.join(
os.path.dirname(__file__),
"fixtures/expected_pyproject/",
"pyproject_with_exact_version_dependency.toml",
)
).read_text()

pyproject = Pyproject(pyproject_str)
pyproject.update_dependencies(latest=True)
assert pyproject.dumps() == expected_pyproject_str
assert (
pyproject.pyproject["tool"]["poetry"]["dependencies"]["poetryup"]
== "0.2.0"
)


def test_update_dependencies_latest_skip_exact_with_exact_version_dependency(
mock_poetry_commands,
mocker: MockerFixture,
) -> None:
pyproject_str = Path(
os.path.join(
os.path.dirname(__file__),
"fixtures/input_pyproject/",
"pyproject_with_exact_version_dependency.toml",
)
).read_text()

mocker.patch.object(
Pyproject,
"_Pyproject__run_poetry_show",
return_value=(
"poetryup 0.1.0 Update dependencies and bump their version in the "
"pyproject.toml file"
"\n└── toml >=0.10.2,<0.11.0\n"
),
)

pyproject = Pyproject(pyproject_str)
pyproject.update_dependencies(latest=True)
assert (
pyproject.pyproject["tool"]["poetry"]["dependencies"]["poetryup"]
== "0.1.0"
)


def test_update_dependencies_with_git_dependency(
mock_poetry_commands,
) -> None:
Expand Down

0 comments on commit 71fa963

Please sign in to comment.