From 3f0821e0e0b6178a63c94a844acec3e88d438a10 Mon Sep 17 00:00:00 2001 From: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com> Date: Wed, 25 Oct 2023 10:26:35 +0200 Subject: [PATCH] Add project name by default to `already_handled_packages` (#202) Add inter-relative extra dependency and test it. Use inter-relative dependency for the `dev` extra to install `docs` and `testing` also. --- ci_cd/tasks/update_deps.py | 5 ++++- pyproject.toml | 1 + tests/tasks/test_update_deps.py | 13 ++++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ci_cd/tasks/update_deps.py b/ci_cd/tasks/update_deps.py index a7152e08..8cf5e173 100644 --- a/ci_cd/tasks/update_deps.py +++ b/ci_cd/tasks/update_deps.py @@ -120,7 +120,10 @@ def update_deps( # pylint: disable=too-many-branches,too-many-locals,too-many-s ) py_version = match.group("version") - already_handled_packages = set() + # Skip package if it is this project (this can happen for inter-relative extra + # dependencies) + already_handled_packages = {pyproject["project"]["name"]} + updated_packages = {} dependencies = pyproject.get("project", {}).get("dependencies", []) for optional_deps in ( diff --git a/pyproject.toml b/pyproject.toml index 0cf0e5dc..9d333517 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,7 @@ testing = [ dev = [ "pre-commit ~=2.21", "pylint ~=2.13", + "ci-cd[docs,testing]", ] [project.urls] diff --git a/tests/tasks/test_update_deps.py b/tests/tasks/test_update_deps.py index 09ecc04b..faebf47f 100644 --- a/tests/tasks/test_update_deps.py +++ b/tests/tasks/test_update_deps.py @@ -1,5 +1,5 @@ """Test `ci_cd.tasks.update_deps()`.""" -# pylint: disable=line-too-long,too-many-lines,too-many-locals +# pylint: disable=line-too-long,too-many-lines,too-many-locals,too-many-branches from __future__ import annotations from typing import TYPE_CHECKING @@ -34,6 +34,7 @@ def test_update_deps(tmp_path: "Path", caplog: pytest.LogCaptureFixture) -> None pyproject_file.write_text( data=f""" [project] +name = "test" requires-python = "~=3.7" dependencies = [ @@ -51,10 +52,9 @@ def test_update_deps(tmp_path: "Path", caplog: pytest.LogCaptureFixture) -> None ] dev = [ "mike >={original_dependencies['mike']},<3", - "pytest ~={original_dependencies['pytest']}", - "pytest-cov ~={original_dependencies['pytest-cov']}", "pre-commit ~={original_dependencies['pre-commit']}", "pylint ~={original_dependencies['pylint']}", + "test[testing]", ] # List from https://peps.python.org/pep-0508/#complete-grammar @@ -161,6 +161,12 @@ def test_update_deps(tmp_path: "Path", caplog: pytest.LogCaptureFixture) -> None "'name5 [fred,bar]' is pinned to a URL and will be skipped" in caplog.text ) + elif "test[testing]" in line: + assert line == "test[testing]" + assert ( + "'test[testing]' is not version restricted and will be skipped." + not in caplog.text + ) else: pytest.fail(f"Unknown package in line: {line}") @@ -1100,6 +1106,7 @@ def test_ignore_rules_logic( pyproject_file.write_text( data=f""" [project] +name = "test" requires-python = "~=3.7" dependencies = [