From c3190f85d5b1cdd500c43dedeeeebb5f667275a3 Mon Sep 17 00:00:00 2001 From: "o.ermakov" Date: Fri, 16 Sep 2022 14:26:08 +0300 Subject: [PATCH] feat: added support update dependencies with extras --- pyproject.toml | 2 +- src/poetryup/core/pyproject.py | 20 +++++++++++++++---- tests/conftest.py | 1 + .../expected_pyproject/pyproject.toml | 1 + .../fixtures/input_pyproject/pyproject.toml | 1 + tests/unit/test_pyproject.py | 8 ++++++++ 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f554af2..b60e086 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ diff --git a/src/poetryup/core/pyproject.py b/src/poetryup/core/pyproject.py index c1b19d7..41270d8 100644 --- a/src/poetryup/core/pyproject.py +++ b/src/poetryup/core/pyproject.py @@ -1,5 +1,6 @@ import logging import re +from collections import defaultdict from typing import Dict, List, Optional, Union import tomlkit @@ -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( diff --git a/tests/conftest.py b/tests/conftest.py index 2efdc9a..e353ad4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/unit/fixtures/expected_pyproject/pyproject.toml b/tests/unit/fixtures/expected_pyproject/pyproject.toml index c0a5d34..e6c3a88 100644 --- a/tests/unit/fixtures/expected_pyproject/pyproject.toml +++ b/tests/unit/fixtures/expected_pyproject/pyproject.toml @@ -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] diff --git a/tests/unit/fixtures/input_pyproject/pyproject.toml b/tests/unit/fixtures/input_pyproject/pyproject.toml index 25f557f..ff2e418 100644 --- a/tests/unit/fixtures/input_pyproject/pyproject.toml +++ b/tests/unit/fixtures/input_pyproject/pyproject.toml @@ -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] diff --git a/tests/unit/test_pyproject.py b/tests/unit/test_pyproject.py index cb601bd..a302b5d 100644 --- a/tests/unit/test_pyproject.py +++ b/tests/unit/test_pyproject.py @@ -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( @@ -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", ), @@ -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", ), @@ -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", ), @@ -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", ),