From c08427a85fee7d69ac30b1f881b4f0ffc9e6a60d Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Tue, 19 Aug 2025 12:23:26 +0200 Subject: [PATCH] Remove black usage in prek hooks We are not using black-related functionality in prek hooks any more - the only remaining hook is 'blacken-docs` - but there is no need to synchronize and upgrade black version any more for it. Upgraded to latest black version for blacken-docs manually. --- .github/workflows/basic-tests.yml | 7 ---- .pre-commit-config.yaml | 15 ++------ scripts/ci/prek/common_prek_black_utils.py | 44 ---------------------- scripts/ci/prek/update_black_version.py | 34 ----------------- 4 files changed, 4 insertions(+), 96 deletions(-) delete mode 100644 scripts/ci/prek/common_prek_black_utils.py delete mode 100755 scripts/ci/prek/update_black_version.py diff --git a/.github/workflows/basic-tests.yml b/.github/workflows/basic-tests.yml index 4be6b383d0825..d289793ac007a 100644 --- a/.github/workflows/basic-tests.yml +++ b/.github/workflows/basic-tests.yml @@ -265,13 +265,6 @@ jobs: # run: prek autoupdate --bleeding-edge --freeze --repo https://github.com/Lucas-C/pre-commit-hooks # - name: "Check if there are any changes in pre-commit hooks" # run: git diff --exit-code - - name: "Run automated upgrade for black" - run: > - prek - --all-files --show-diff-on-failure --color always --verbose - --hook-stage manual - update-black-version - if: always() - name: "Run automated upgrade for chart dependencies" run: > prek diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eb7e9cd134fa6..faa3c0b6563b1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -192,15 +192,6 @@ repos: language: python additional_dependencies: ['rich>=12.4.4'] require_serial: true - - id: update-black-version - name: Update black versions everywhere (manual) - entry: ./scripts/ci/prek/update_black_version.py - stages: ['manual'] - language: python - files: ^\.pre-commit-config\.yaml$ - additional_dependencies: ['pyyaml>=6.0.2'] - pass_filenames: false - require_serial: true - id: upgrade-important-versions name: Upgrade important versions (manual) entry: ./scripts/ci/prek/upgrade_important_versions.py @@ -249,8 +240,10 @@ repos: - --target-version=py310 - --target-version=py311 - --target-version=py312 + - --target-version=py313 alias: blacken-docs - additional_dependencies: ['black==24.10.0'] + additional_dependencies: + - 'black==25.1.0' - repo: https://github.com/pre-commit/pre-commit-hooks rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # frozen: v6.0.0 hooks: @@ -1001,7 +994,7 @@ repos: entry: ./scripts/ci/prek/check_integrations_list.py language: python files: ^scripts/ci/docker-compose/integration-.*\.yml$|^contributing-docs/testing/integration_tests\.rst$ - additional_dependencies: ['black==24.10.0', 'tabulate>=0.9.0', 'rich>=12.4.4', 'pyyaml>=6.0.2'] + additional_dependencies: ['tabulate>=0.9.0', 'rich>=12.4.4', 'pyyaml>=6.0.2'] require_serial: true pass_filenames: false - id: update-breeze-readme-config-hash diff --git a/scripts/ci/prek/common_prek_black_utils.py b/scripts/ci/prek/common_prek_black_utils.py deleted file mode 100644 index 5f6e0a877784f..0000000000000 --- a/scripts/ci/prek/common_prek_black_utils.py +++ /dev/null @@ -1,44 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -from __future__ import annotations - -import os -import sys -from functools import cache -from pathlib import Path - -from black import Mode, TargetVersion, format_str, parse_pyproject_toml - -sys.path.insert(0, str(Path(__file__).parent.resolve())) # make sure common_prek_utils is imported - -from common_prek_utils import AIRFLOW_BREEZE_SOURCES_PATH - - -@cache -def black_mode(is_pyi: bool = Mode.is_pyi) -> Mode: - config = parse_pyproject_toml(os.fspath(AIRFLOW_BREEZE_SOURCES_PATH / "pyproject.toml")) - target_versions = {TargetVersion[val.upper()] for val in config.get("target_version", ())} - - return Mode( - target_versions=target_versions, - line_length=config.get("line_length", Mode.line_length), - is_pyi=is_pyi, - ) - - -def black_format(content: str, is_pyi: bool = Mode.is_pyi) -> str: - return format_str(content, mode=black_mode(is_pyi=is_pyi)) diff --git a/scripts/ci/prek/update_black_version.py b/scripts/ci/prek/update_black_version.py deleted file mode 100755 index 4d1b98ef310c3..0000000000000 --- a/scripts/ci/prek/update_black_version.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -from __future__ import annotations - -import re - -import yaml -from common_prek_utils import AIRFLOW_ROOT_PATH - -if __name__ == "__main__": - PRE_COMMIT_CONFIG_FILE = AIRFLOW_ROOT_PATH / ".pre-commit-config.yaml" - pre_commit_config_content = yaml.safe_load(PRE_COMMIT_CONFIG_FILE.read_text()) - for repo in pre_commit_config_content["repos"]: - if repo["repo"] == "https://github.com/psf/black": - black_version = repo["rev"] - pre_commit_text = PRE_COMMIT_CONFIG_FILE.read_text() - pre_commit_text = re.sub(r"black==[0-9\.]*", f"black=={black_version}", pre_commit_text) - PRE_COMMIT_CONFIG_FILE.write_text(pre_commit_text) - break