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 #60 from ermakov-oleg/exclude-deps
Browse files Browse the repository at this point in the history
feat: added ability to exclude dependencies from updates
  • Loading branch information
MousaZeidBaker authored Aug 13, 2022
2 parents dec9ae7 + 8ac3a93 commit b941781
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ Update the `foo` and `bar` dependencies to their latest available version
poetryup --latest --name foo --name bar
```

Update all dependencies to their latest available version except the `foo` and `bar` dependencies
```shell
poetryup --latest --exclude-name foo --exclude-name bar
```

## Automate Dependency Updates with GitHub Actions
Use PoetryUp with GitHub actions to automate the process of updating
dependencies, for reference see this project's [workflow
Expand Down
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.9.0"
version = "0.10.0"
description = "Update dependencies and bump their version in the pyproject.toml file"
authors = ["Mousa Zeid Baker"]
packages = [
Expand Down
13 changes: 12 additions & 1 deletion src/poetryup/core/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,16 @@ def filter_dependencies(
dependencies: List[Dependency],
without_constraints: List[Constraint] = [],
names: List[str] = [],
exclude_names: List[str] = [],
groups: List[str] = [],
) -> Union[Dependency, None]:
) -> List[Dependency]:
"""Search for a dependency by name given a list of dependencies
Args:
dependencies: A list of dependencies to filter
without_constraints: The dependency constraints to ignore
names: The dependency names to include
exclude_names: The dependency names to exclude
groups: The dependency groups to include
Returns:
Expand All @@ -230,6 +232,11 @@ def filter_dependencies(
if names:
# remove deps whom name is NOT in the provided name list
dependencies = [x for x in dependencies if x.name in names]
if exclude_names:
# remove deps whom name is in the provided exclude_names list
dependencies = [
x for x in dependencies if x.name not in exclude_names
]
if groups:
# remove deps whom group is NOT in the provided group list
dependencies = [x for x in dependencies if x.group in groups]
Expand All @@ -241,6 +248,7 @@ def update_dependencies(
latest: bool = False,
without_constraints: List[Constraint] = [],
names: List[str] = [],
exclude_names: List[str] = [],
groups: List[str] = [],
) -> None:
"""Update dependencies and bump their version in pyproject
Expand All @@ -249,6 +257,7 @@ def update_dependencies(
latest: Whether to update dependencies to their latest version
without_constraints: The dependency constraints to ignore
names: The dependency names to include
exclude_names: The dependency names to exclude
groups: The dependency groups to include
"""

Expand All @@ -258,6 +267,7 @@ def update_dependencies(
self.dependencies,
without_constraints,
names,
exclude_names,
groups,
)
# sort dependencies into their groups and add them at once in order
Expand All @@ -284,6 +294,7 @@ def update_dependencies(
self.bumped_dependencies,
without_constraints,
names,
exclude_names,
groups,
)
table = self.pyproject["tool"]["poetry"]
Expand Down
12 changes: 11 additions & 1 deletion src/poetryup/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def poetryup(
default=[],
help="The dependency names to include.",
),
exclude_name: List[str] = typer.Option(
default=[],
help="The dependency names to exclude.",
),
group: List[str] = typer.Option(
default=[],
help="The dependency groups to include.",
Expand All @@ -60,7 +64,13 @@ def poetryup(

pyproject = Pyproject(pyproject_str)
without_constraint = [Constraint.EXACT] if skip_exact else []
pyproject.update_dependencies(latest, without_constraint, name, group)
pyproject.update_dependencies(
latest,
without_constraint,
name,
exclude_name,
group,
)
Path("pyproject.toml").write_text(pyproject.dumps())
# refresh the lock file after changes in pyproject.toml
logging.debug("Execute: 'poetry lock --no-update'")
Expand Down
35 changes: 35 additions & 0 deletions tests/unit/test_pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,41 @@ def test_update_dependencies_latest_with_specific_name(
mock.assert_has_calls(calls)


def test_update_dependencies_latest_with_exclude_names(
mock_poetry_commands,
mocker: MockerFixture,
) -> None:
pyproject = Pyproject(pyproject_str)
mock = mocker.patch.object(
pyproject,
"_Pyproject__run_poetry_add",
return_value=None,
)
pyproject.update_dependencies(
latest=True, exclude_names=["poetryup_caret", "poetryup"]
)

calls = [
call(
packages=[
"poetryup_tilde@latest",
"poetryup_wildcard@latest",
"poetryup_inequality_greater_than@latest",
"poetryup_inequality_greater_than_or_equal@latest",
"poetryup_inequality_less_than@latest",
"poetryup_inequality_less_than_or_equal@latest",
"poetryup_inequality_not_equal@latest",
"poetryup_exact@latest",
"poetryup_multiple_requirements@latest",
"poetryup_underscore@latest",
"Poetryup_Capital@latest",
],
group="main",
),
]
mock.assert_has_calls(calls)


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

0 comments on commit b941781

Please sign in to comment.