potiuk commented on code in PR #53697: URL: https://github.com/apache/airflow/pull/53697#discussion_r2230286528
########## scripts/ci/pre_commit/check_shared_projects.py: ########## @@ -0,0 +1,144 @@ +#!/usr/bin/env python3 +# 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. + +""" +Check shared projects in the "shared" subfolder for compliance. +""" + +from __future__ import annotations + +import re +import sys +from pathlib import Path + +try: + import tomllib +except ImportError: + import tomli as tomllib + +sys.path.insert(0, str(Path(__file__).parent.resolve())) # make sure common_precommit_utils is imported +from common_precommit_utils import AIRFLOW_ROOT_PATH, console + +SHARED_DIR = AIRFLOW_ROOT_PATH / "shared" + + +def check_shared_project(shared_path): + pyproject_path = shared_path / "pyproject.toml" + console.print(f"\n[bold blue]Checking:[/bold blue] [magenta]{shared_path.name}[/magenta] shared project") + # Check pyproject.toml exists + if pyproject_path.exists(): + console.print(" pyproject.toml exists [bold green]OK[/bold green]") + else: + console.print(" [red]pyproject.toml missing[/red]") + return False + # Check project name pattern and value + with open(pyproject_path, "rb") as f: + pyproject = tomllib.load(f) + name = pyproject.get("project", {}).get("name", "") + expected_name = f"apache-airflow-shared-{shared_path.name}" + m = re.match(r"apache-airflow-shared-(.+)", name) + if m and name == expected_name: + console.print(f" project name matches and is '{expected_name}' [bold green]OK[/bold green]") + else: + console.print(f" [red]project name '{name}' does not match or is not '{expected_name}'[/red]") + return False + pkg_name = m.group(1) if m else shared_path.name + # Check src/airflow_shared/NAME exists + pkg_path = shared_path / "src" / "airflow_shared" / pkg_name + airflow_shared_path = shared_path / "src" / "airflow_shared" + if pkg_path.exists(): + console.print(f" src/airflow_shared/{pkg_name} exists [bold green]OK[/bold green]") + else: + console.print(f" [red]{pkg_path} does not exist (should be sub-package of airflow_shared)[/red]") + return False + # Check airflow_shared does not contain __init__.py + init_file = airflow_shared_path / "__init__.py" + if not init_file.exists(): + console.print(" src/airflow_shared/__init__.py does not exist [bold green]OK[/bold green]") + else: + console.print(f" [red]{init_file} should NOT exist (implicit namespace package)[/red]") + return False + # Check tests/NAME exists + tests_pkg_path = shared_path / "tests" / pkg_name + if tests_pkg_path.exists(): + console.print(f" tests/{pkg_name} exists [bold green]OK[/bold green]") + else: + console.print(f" [red]{tests_pkg_path} does not exist (should be test package)[/red]") + return False + # Check 'Private :: Do Not Upload' classifier exists and is only classifier + classifiers = pyproject.get("project", {}).get("classifiers", []) + if classifiers == ["Private :: Do Not Upload"]: + console.print( + " 'Private :: Do Not Upload' classifier is only classifier [bold green]OK[/bold green]" + ) + else: + console.print(f" [red]classifiers are not exactly ['Private :: Do Not Upload']: {classifiers}[/red]") + return False + # Check 'build-system' exists and is correct + build_system = pyproject.get("build-system", {}) + if build_system == {"requires": ["hatchling"], "build-backend": "hatchling.build"}: + console.print(" build-system is correct [bold green]OK[/bold green]") + else: + console.print(f" [red]build-system is not correct: {build_system}[/red]") + return False + # Check tool.hatch.build.targets.wheel exists and is correct + hatch_build_targets = pyproject.get("tool", {}).get("hatch", {}).get("build", {}).get("targets", {}) + if hatch_build_targets.get("wheel", {}).get("packages", []) == ["src/airflow_shared"]: + console.print(" tool.hatch.build.targets.wheel is correct [bold green]OK[/bold green]") + else: + console.print(f" [red]tool.hatch.build.targets.wheel is not correct: {hatch_build_targets}[/red]") + return False + # Check tool.ruff exists and is correct + ruff = pyproject.get("tool", {}).get("ruff", {}) + if ruff.get("extend", None) == "../../pyproject.toml" and ruff.get("src", None) == ["src"]: + console.print(" tool.ruff is correct [bold green]OK[/bold green]") + else: + console.print(f" [red]tool.ruff is not correct: {ruff}[/red]") + return False + # Check tool.ruff.lint rules exist and are correct + ruff_lint = ruff.get("lint", {}) + per_file_ignores = ruff_lint.get("per-file-ignores", {}) + flake8_tidy_imports = ruff_lint.get("flake8-tidy-imports", {}) + if ( + per_file_ignores.get("!src/*", None) == ["D", "S101", "TRY002"] + and flake8_tidy_imports.get("ban-relative-imports", None) == "parents" + ): + console.print(" tool.ruff.lint rules are correct [bold green]OK[/bold green]") + else: + console.print(f" [red]tool.ruff.lint rules are not correct: {ruff_lint}[/red]") + return False + console.print(f"[bold green]Summary: {shared_path.name} is OK[/bold green]") + return True Review Comment: Yep. Good idea. I will ask copilot to do so... It was all vibe-coded :) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
