From be2907399220144b2dc93ff15f2c393991dea729 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Mon, 17 Nov 2025 15:25:11 +0100 Subject: [PATCH 1/2] Run black on all updates This will help when we update black across all plugins via the templates. --- plugin-template | 21 +++++++-------------- requirements.txt | 3 ++- templates/github/lint_requirements.txt.j2 | 2 +- utils.py | 11 +++++++++++ 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/plugin-template b/plugin-template index dabf065a..41d275a1 100755 --- a/plugin-template +++ b/plugin-template @@ -379,6 +379,12 @@ def main(): print("\nDeprecation check:") check_for_deprecated_files(plugin_root_dir, sections) + if config["black"]: + try: + subprocess.run(["black", "--quiet", "."], cwd=plugin_root_dir) + except FileNotFoundError: + pass + def migrate_dummy(plugin_root_dir): pass @@ -422,6 +428,7 @@ def write_template_section(config, name, plugin_root_dir, verbose=False): "current_version": utils.current_version(plugin_root_path), "pulpdocs_branch": PULPDOCS_BRANCH, "is_pulpdocs_member": config["plugin_name"] in utils.get_pulpdocs_members(PULPDOCS_BRANCH), + "black_version": utils.black_version(), **config, } @@ -472,20 +479,6 @@ def write_template_section(config, name, plugin_root_dir, verbose=False): if verbose: print(f"Copied file: {relative_path}") - if config["black"]: - black_paths = filter(lambda x: x.endswith(".py.j2"), relative_path_set) - black_paths = map(lambda x: x[: -len(".j2")], black_paths) - black_paths = map( - lambda x: x.replace("plugin_name", utils.to_snake(config["plugin_name"])), black_paths - ) - black_paths = filter( - lambda x: os.path.exists(os.path.join(plugin_root_dir, x)), black_paths - ) - try: - subprocess.run(["black", "--quiet"] + list(black_paths), cwd=plugin_root_dir) - except FileNotFoundError: - pass - print(f"Section: {name} \n templated: {files_templated}\n copied: {files_copied}") return 0 diff --git a/requirements.txt b/requirements.txt index fd6eb960..1546c707 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,8 @@ # Click is pinned because of: # https://github.com/pallets/click/issues/3065 click<8.3 -black +# This needs to match the version in templates/github/lint_requirement.txt.j2 +black==24.3.0 jinja2 pyyaml requests~=2.32.3 diff --git a/templates/github/lint_requirements.txt.j2 b/templates/github/lint_requirements.txt.j2 index b646615c..ab22f9c2 100644 --- a/templates/github/lint_requirements.txt.j2 +++ b/templates/github/lint_requirements.txt.j2 @@ -1,7 +1,7 @@ {% include 'header.j2' %} {% if black -%} -black==24.3.0 +black=={{ black_version }} {% endif -%} # Click is pinned because of: # https://github.com/pallets/click/issues/3065 diff --git a/utils.py b/utils.py index 18b7dfac..64b60b65 100644 --- a/utils.py +++ b/utils.py @@ -1,4 +1,5 @@ from datetime import timedelta +from pathlib import Path import re import requests_cache import stat @@ -93,6 +94,16 @@ def current_version(plugin_root_path): return current_version +def black_version(): + PATTERN = re.compile(r"^black==(?P.*)$") + requirements_file = Path(__file__).parent / "requirements.txt" + for line in requirements_file.read_text().splitlines(): + if match := PATTERN.fullmatch(line): + return match.group("version") + + raise ValueError("'black' not found in 'requirements.txt'") + + def get_pulpdocs_members(pulpdocs_branch="main") -> list[str]: """ Get repositories which are members of the Pulp managed documentation. From 86fffe5b17b1250eb45142e0dccbdd3af631d2f2 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Mon, 17 Nov 2025 18:28:35 +0100 Subject: [PATCH 2/2] Delete old templates --- .../scripts/publish_client_gem.sh.j2 | 26 ------------------- .../scripts/publish_client_pypi.sh.j2 | 23 ---------------- .../scripts/publish_plugin_pypi.sh.j2 | 21 --------------- 3 files changed, 70 deletions(-) delete mode 100755 templates/github/.github/workflows/scripts/publish_client_gem.sh.j2 delete mode 100755 templates/github/.github/workflows/scripts/publish_client_pypi.sh.j2 delete mode 100755 templates/github/.github/workflows/scripts/publish_plugin_pypi.sh.j2 diff --git a/templates/github/.github/workflows/scripts/publish_client_gem.sh.j2 b/templates/github/.github/workflows/scripts/publish_client_gem.sh.j2 deleted file mode 100755 index ecf1f200..00000000 --- a/templates/github/.github/workflows/scripts/publish_client_gem.sh.j2 +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -{% include 'header.j2' %} - -set -euv - -# make sure this script runs at the repo root -cd "$(dirname "$(realpath -e "$0")")"/../../.. - -VERSION="$1" - -if [[ -z "${VERSION}" ]] -then - echo "No version specified." - exit 1 -fi - -mkdir -p ~/.gem -touch ~/.gem/credentials -echo "--- -:rubygems_api_key: ${RUBYGEMS_API_KEY}" > ~/.gem/credentials -sudo chmod 600 ~/.gem/credentials - -{%- for plugin in plugins %} -gem push "{{ plugin.name | snake }}_client-${VERSION}.gem" -{%- endfor %} diff --git a/templates/github/.github/workflows/scripts/publish_client_pypi.sh.j2 b/templates/github/.github/workflows/scripts/publish_client_pypi.sh.j2 deleted file mode 100755 index 18709f7a..00000000 --- a/templates/github/.github/workflows/scripts/publish_client_pypi.sh.j2 +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -{% include 'header.j2' %} - -set -euv - -# make sure this script runs at the repo root -cd "$(dirname "$(realpath -e "$0")")/../../.." - -VERSION="$1" - -if [[ -z "${VERSION}" ]] -then - echo "No version specified." - exit 1 -fi - -twine upload -u __token__ -p "${PYPI_API_TOKEN}" \ -{%- for plugin in plugins %} -"dist/{{ plugin.name | snake }}_client-${VERSION}-py3-none-any.whl" \ -"dist/{{ plugin.name | snake }}_client-${VERSION}.tar.gz" \ -{%- endfor %} -; diff --git a/templates/github/.github/workflows/scripts/publish_plugin_pypi.sh.j2 b/templates/github/.github/workflows/scripts/publish_plugin_pypi.sh.j2 deleted file mode 100755 index 9370870c..00000000 --- a/templates/github/.github/workflows/scripts/publish_plugin_pypi.sh.j2 +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -{% include 'header.j2' %} - -set -euv - -# make sure this script runs at the repo root -cd "$(dirname "$(realpath -e "$0")")"/../../.. - -VERSION="$1" - -if [[ -z "${VERSION}" ]] -then - echo "No version specified." - exit 1 -fi - -twine upload -u __token__ -p "${PYPI_API_TOKEN}" \ -dist/{{ plugin_name | snake | replace("_", "?") }}-"${VERSION}"-py3-none-any.whl \ -dist/{{ plugin_name | snake | replace("_", "?") }}-"${VERSION}".tar.gz \ -;