|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +""" |
| 18 | +Keep the recorded Python serialization output the conformance suite compares against honest. |
| 19 | +
|
| 20 | +``ts-sdk/tests/conformance/serialized_python.json`` is what Airflow's own serializer |
| 21 | +produced for the fixtures in ``test_dags.json``. The TypeScript conformance suite diffs |
| 22 | +its output against that recording, so the recording going stale would leave the suite |
| 23 | +passing against an Airflow that no longer serializes the same way. |
| 24 | +""" |
| 25 | + |
| 26 | +from __future__ import annotations |
| 27 | + |
| 28 | +import subprocess |
| 29 | +import sys |
| 30 | +from pathlib import Path |
| 31 | + |
| 32 | +sys.path.insert(0, str(Path(__file__).resolve().parents[4] / "scripts" / "ci" / "prek")) |
| 33 | + |
| 34 | +from common_prek_utils import AIRFLOW_ROOT_PATH, console |
| 35 | + |
| 36 | +if __name__ not in ("__main__", "__mp_main__"): |
| 37 | + raise SystemExit( |
| 38 | + "This file is intended to be executed as an executable program. You cannot use it as a module." |
| 39 | + f"To run this script, run the ./{__file__} command" |
| 40 | + ) |
| 41 | + |
| 42 | +SCRIPT = Path("ts-sdk/tests/conformance/serialize_python.py") |
| 43 | + |
| 44 | +if __name__ == "__main__": |
| 45 | + result = subprocess.run( |
| 46 | + ["uv", "run", "--project", "airflow-core", "python", str(SCRIPT), "--check"], |
| 47 | + cwd=AIRFLOW_ROOT_PATH, |
| 48 | + check=False, |
| 49 | + capture_output=True, |
| 50 | + text=True, |
| 51 | + ) |
| 52 | + if result.returncode == 0: |
| 53 | + sys.exit(0) |
| 54 | + message = ( |
| 55 | + f"{SCRIPT} --check failed, so the recorded Python output no longer matches what " |
| 56 | + "Airflow's serializer produces.\n" |
| 57 | + f"Re-record it with `uv run --project airflow-core python {SCRIPT}` and review the diff: " |
| 58 | + "a change there is a change in the parity contract.\n\n" |
| 59 | + f"{result.stdout}{result.stderr}" |
| 60 | + ) |
| 61 | + if console: |
| 62 | + console.print(f"[yellow]{message}[/]") |
| 63 | + else: |
| 64 | + print(message, file=sys.stderr) |
| 65 | + raise SystemExit(result.returncode) |
0 commit comments