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 #64 from ermakov-oleg/support-deps-with-extras
Browse files Browse the repository at this point in the history
feat: added support update dependencies with extras
  • Loading branch information
MousaZeidBaker committed Sep 18, 2022
2 parents 1760427 + c3190f8 commit c982a79
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 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.11.1"
version = "0.12.0"
description = "Update dependencies and bump their version in the pyproject.toml file"
authors = ["Mousa Zeid Baker"]
packages = [
Expand Down
20 changes: 16 additions & 4 deletions src/poetryup/core/pyproject.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import re
from collections import defaultdict
from typing import Dict, List, Optional, Union

import tomlkit
Expand Down Expand Up @@ -272,12 +273,23 @@ def update_dependencies(
# sort dependencies into their groups and add them at once in order
# to avoid version solver error in case dependencies depend on each
# other
dependency_groups = {}
dependency_groups = defaultdict(list)
for dependency in dependencies:
if isinstance(dependency.version, str):
dependency_groups[dependency.group] = dependency_groups.get(
dependency.group, []
) + [f"{dependency.name}@latest"]
dependency_groups[dependency.group].append(
f"{dependency.name}@latest"
)
if (
isinstance(dependency.version, dict)
and "version" in dependency.version
):
# skip dependencies with restriction markers
if {"markers", "python"} & set(dependency.version):
continue
extras = ",".join(dependency.version.get("extras", []))
suffix = f"[{extras}]" if extras else ""
package_version = f"{dependency.name}{suffix}@latest"
dependency_groups[dependency.group].append(package_version)

for group, packages in dependency_groups.items():
self.__run_poetry_add(
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def mock_poetry_commands(mocker: MockerFixture) -> None:
"poetryup-git",
"poetryup-underscore",
"poetryup-capital",
"poetryup_extras",
]
s = " 0.2.0 Some description\n└── some-package >=0.10.2,<0.11.0\n"
return_value = s.join(dependencies) + s
Expand Down
1 change: 1 addition & 0 deletions tests/unit/fixtures/expected_pyproject/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ poetryup_restricted = { version = "^0.2.0", python = "<3.7" }
poetryup_git = { git = "https://github.com/MousaZeidBaker/poetryup.git" }
poetryup_underscore = "^0.2.0"
Poetryup_Capital = "^0.2.0"
poetryup_extras = { version = "^0.2.0", extras = ["foo", "bar"]}

[tool.poetry.group.dev.dependencies]

Expand Down
1 change: 1 addition & 0 deletions tests/unit/fixtures/input_pyproject/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ poetryup_restricted = { version = "^0.1.0", python = "<3.7" }
poetryup_git = { git = "https://github.com/MousaZeidBaker/poetryup.git" }
poetryup_underscore = "^0.1.0"
Poetryup_Capital = "^0.1.0"
poetryup_extras = { version = "^0.1.0", extras = ["foo", "bar"]}

[tool.poetry.group.dev.dependencies]

Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def test_update_dependencies(
}
assert table["poetryup_underscore"] == "^0.2.0"
assert table["Poetryup_Capital"] == "^0.2.0"
assert table["poetryup_extras"] == {
"version": "^0.2.0",
"extras": ["foo", "bar"],
}


def test_update_dependencies_latest(
Expand Down Expand Up @@ -90,6 +94,7 @@ def test_update_dependencies_latest(
"poetryup_multiple_requirements@latest",
"poetryup_underscore@latest",
"Poetryup_Capital@latest",
"poetryup_extras[foo,bar]@latest",
],
group="main",
),
Expand Down Expand Up @@ -131,6 +136,7 @@ def test_update_dependencies_latest_skip_exact(
"poetryup_multiple_requirements@latest",
"poetryup_underscore@latest",
"Poetryup_Capital@latest",
"poetryup_extras[foo,bar]@latest",
],
group="main",
),
Expand Down Expand Up @@ -165,6 +171,7 @@ def test_update_dependencies_latest_with_specific_group(
"poetryup_multiple_requirements@latest",
"poetryup_underscore@latest",
"Poetryup_Capital@latest",
"poetryup_extras[foo,bar]@latest",
],
group="main",
),
Expand Down Expand Up @@ -221,6 +228,7 @@ def test_update_dependencies_latest_with_exclude_names(
"poetryup_multiple_requirements@latest",
"poetryup_underscore@latest",
"Poetryup_Capital@latest",
"poetryup_extras[foo,bar]@latest",
],
group="main",
),
Expand Down

0 comments on commit c982a79

Please sign in to comment.