From 3f1e7d3b353dcd3d3366e1b36b3cd07bfbaee0cd Mon Sep 17 00:00:00 2001 From: Tsvika Shapira Date: Wed, 5 Mar 2025 01:45:36 +0200 Subject: [PATCH 1/4] update github-action to look for black version in "dependency-groups" "dependency-groups" is the mechanism for storing package requirements in `pyproject.toml`, recommended for formatting tools (see https://packaging.python.org/en/latest/specifications/dependency-groups/ ) this change allow the black action to look also in those locations when determining the version of black to install --- action/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/action/main.py b/action/main.py index 2b347e149cb..463e6ea189a 100644 --- a/action/main.py +++ b/action/main.py @@ -73,6 +73,7 @@ def read_version_specifier_from_pyproject() -> str: arrays = [ pyproject.get("project", {}).get("dependencies"), *pyproject.get("project", {}).get("optional-dependencies", {}).values(), + *pyproject.get("dependency-groups", {}).values(), ] for array in arrays: version = find_black_version_in_array(array) From 0bacc722d1dc401b72f454dfdd15cddfdc6ed4e2 Mon Sep 17 00:00:00 2001 From: Tsvika Shapira Date: Thu, 6 Mar 2025 12:58:05 +0200 Subject: [PATCH 2/4] look at 'dependency-groups' before 'dependencies' and 'optional-dependencies' In case of a package actually extending 'black', it seems reasonable to assume that the formatting requirement will be specified (or narrowed down) in the 'dependency-groups'. --- action/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action/main.py b/action/main.py index 463e6ea189a..f7fdda7efb6 100644 --- a/action/main.py +++ b/action/main.py @@ -71,9 +71,9 @@ def read_version_specifier_from_pyproject() -> str: return f"=={version}" arrays = [ + *pyproject.get("dependency-groups", {}).values(), pyproject.get("project", {}).get("dependencies"), *pyproject.get("project", {}).get("optional-dependencies", {}).values(), - *pyproject.get("dependency-groups", {}).values(), ] for array in arrays: version = find_black_version_in_array(array) From facbe736964f2997df7ba6414ea1973b2fb7817f Mon Sep 17 00:00:00 2001 From: Tsvika Shapira Date: Thu, 6 Mar 2025 12:58:17 +0200 Subject: [PATCH 3/4] add changelog entry --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 8d8808c2573..eec9c9b21a5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -49,6 +49,8 @@ - Fix the version check in the vim file to reject Python 3.8 (#4567) +- Enhance GitHub Action `psf/black` to read Black version from an additional + section in pyproject.toml: `[project.dependency-groups]` (#4606) ### Documentation From 64bf10e61c1a2128e3d72cbd4bbeb69ce8b48d4c Mon Sep 17 00:00:00 2001 From: Tsvika Shapira Date: Thu, 6 Mar 2025 13:01:31 +0200 Subject: [PATCH 4/4] add documentation --- docs/integrations/github_actions.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/integrations/github_actions.md b/docs/integrations/github_actions.md index 61689799731..3270e0f858f 100644 --- a/docs/integrations/github_actions.md +++ b/docs/integrations/github_actions.md @@ -37,10 +37,10 @@ the `pyproject.toml` file. `version` can be any [valid version specifier](https://packaging.python.org/en/latest/glossary/#term-Version-Specifier) or just the version number if you want an exact version. To read the version from the `pyproject.toml` file instead, set `use_pyproject` to `true`. This will first look into -the `tool.black.required-version` field, then the `project.dependencies` array and -finally the `project.optional-dependencies` table. The action defaults to the latest -release available on PyPI. Only versions available from PyPI are supported, so no commit -SHAs or branch names. +the `tool.black.required-version` field, then the `dependency-groups` table, then the +`project.dependencies` array and finally the `project.optional-dependencies` table. +The action defaults to the latest release available on PyPI. Only versions available +from PyPI are supported, so no commit SHAs or branch names. If you want to include Jupyter Notebooks, _Black_ must be installed with the `jupyter` extra. Installing the extra and including Jupyter Notebook files can be configured via