From b35b410e20f24b57d78208281503db6e0380ece7 Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Tue, 22 Oct 2024 13:19:39 +0200 Subject: [PATCH] Do not fail the build if only trove-classifiers change (#43236) (#43237) Trove classifiers is a non-code package so generally spaeking we have no need to update it every time it is released, but it would be great if we could update it together with other build dependencies - and not fail the build when only trove classifiers change, but update trove-classifiers nevertheless when we run pre-commit run --hook-stage manual update-build-dependencies --all-files This is very similar to what we already do with UV. This PR achieves that: * in CI we set the env SKIP_TROVE_CLASSIFIERS_ONLY to true * this one will check if the only change in pyproject.toml are trove-classifiers * If so - it only prints warning and exits with success --- .github/workflows/basic-tests.yml | 2 ++ .pre-commit-config.yaml | 1 + .../pre_commit/update_build_dependencies.py | 24 ++++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/basic-tests.yml b/.github/workflows/basic-tests.yml index ae968103dbd1..7ab09d1cd2fe 100644 --- a/.github/workflows/basic-tests.yml +++ b/.github/workflows/basic-tests.yml @@ -308,6 +308,8 @@ jobs: --hook-stage manual update-build-dependencies if: always() + env: + SKIP_TROVE_CLASSIFIERS_ONLY: "true" - name: "Run automated upgrade for chart dependencies" run: > pre-commit run diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a2d218dae693..88f834050b61 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -192,6 +192,7 @@ repos: files: ^.pre-commit-config.yaml$|^scripts/ci/pre_commit/update_build_dependencies.py$ pass_filenames: false require_serial: true + additional_dependencies: ['rich>=12.4.4'] - id: update-installers name: Update installers to latest (manual) entry: ./scripts/ci/pre_commit/update_installers.py diff --git a/scripts/ci/pre_commit/update_build_dependencies.py b/scripts/ci/pre_commit/update_build_dependencies.py index e32a8b2bb518..61cd2bd929cb 100755 --- a/scripts/ci/pre_commit/update_build_dependencies.py +++ b/scripts/ci/pre_commit/update_build_dependencies.py @@ -17,6 +17,7 @@ # under the License. from __future__ import annotations +import os import re import shutil import subprocess @@ -24,6 +25,10 @@ import tempfile from pathlib import Path +COMMON_PRECOMMIT_PATH = Path(__file__).parent.resolve() +sys.path.insert(0, COMMON_PRECOMMIT_PATH.as_posix()) # make sure common_precommit_utils is imported +from common_precommit_utils import console + AIRFLOW_SOURCES = Path(__file__).parents[3].resolve() PYPROJECT_TOML_FILE = AIRFLOW_SOURCES / "pyproject.toml" @@ -72,6 +77,18 @@ result.append("") new_pyproject_toml_file_content = "\n".join(result) if new_pyproject_toml_file_content != pyproject_toml_content: + if os.environ.get("SKIP_TROVE_CLASSIFIERS_ONLY", "false").lower() == "true": + diff = set(new_pyproject_toml_file_content.splitlines()) - ( + set(pyproject_toml_content.splitlines()) + ) + if len(diff) == 1 and "trove-classifiers" in next(iter(diff)): + console.print("\n[yellow]Trove classifiers were changed. Please update them manually.\n") + console.print( + "\n[blue]Please run:[/blue]\n\n" + "pre-commit run --hook-stage manual update-build-dependencies --all-files\n" + ) + console.print("\n[blue]Then commit the resulting files.\n") + sys.exit(0) files_changed = True PYPROJECT_TOML_FILE.write_text(new_pyproject_toml_file_content) for file_to_replace_hatchling in FILES_TO_REPLACE_HATCHLING_IN: @@ -84,5 +101,10 @@ shutil.rmtree(temp_dir) if files_changed: - print("Some files changed. Please commit the changes.") + console.print("\n[red]Build dependencies have changed. Please update them manually.\n") + console.print( + "\n[blue]Please run:[/blue]\n\n" + "pre-commit run --hook-stage manual update-build-dependencies --all-files\n" + ) + console.print("\n[blue]Then commit the resulting files.\n") sys.exit(1)