uranusjr commented on code in PR #71757:
URL: https://github.com/apache/airflow/pull/71757#discussion_r4336108688


##########
scripts/ci/prek/update_lang_sdk_central_matrix.py:
##########
@@ -0,0 +1,152 @@
+#!/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.
+# /// script
+# requires-python = ">=3.11,<3.12"
+# dependencies = ["PyYAML>=6.0", "rich>=13.6.0"]
+# ///
+"""Regenerate the consolidated Language SDK compatibility matrix in the 
user-facing docs.
+
+Reads every ``<sdk>/capabilities.yaml`` listed in the ``LANG_SDKS`` registry 
(an SDK that has
+not published one yet simply shows the "absent" mark) and rewrites the 
``list-table`` blocks in
+``airflow-core/docs/authoring-and-scheduling/language-sdks/index.rst`` between 
the
+AUTO-GENERATED markers. Exits non-zero when the file changed so the 
contributor re-stages it.
+"""
+
+from __future__ import annotations
+
+import sys
+from collections.abc import Sequence
+from pathlib import Path
+from typing import Final, NamedTuple
+
+sys.path.insert(0, str(Path(__file__).resolve().parent))
+
+import lang_sdk_compat_matrix as matrix
+from common_prek_utils import console, insert_documentation
+
+CENTRAL_MATRIX_HEADER: Final = ".. BEGIN AUTO-GENERATED LANG-SDK COMPAT MATRIX"
+CENTRAL_MATRIX_FOOTER: Final = ".. END AUTO-GENERATED LANG-SDK COMPAT MATRIX"
+ABSENT_MARK: Final = matrix.NO_VERSION_MARK
+
+INDEX_RST: Final = (
+    matrix.AIRFLOW_ROOT_PATH
+    / "airflow-core"
+    / "docs"
+    / "authoring-and-scheduling"
+    / "language-sdks"
+    / "index.rst"
+)
+
+
+class SdkCapabilities(NamedTuple):
+    display_name: str
+    doc: matrix.CapabilitiesDoc | None
+
+
+def load_sdk_capabilities(sdks: Sequence[matrix.LangSdk]) -> 
list[SdkCapabilities]:
+    """Load every published manifest in registry order."""
+    return [
+        SdkCapabilities(
+            display_name=matrix.SDK_DISPLAY_NAMES[sdk["id"]],
+            doc=(
+                matrix.load_capabilities(sdk["capabilities_yaml"], 
expected_sdk=sdk["id"])

Review Comment:
   Instead of loading, passing these around and back into `matrix.get_entry`, 
`load_capabilities` can probably return a resolved lookup, where a shared 
capability’s native/stub entries are stored under `(name, "native")` and 
`(name, "stub")`. Then `get_entry` becomes `doc.entries[(row.name, row.mode if 
row.name in SHARED else None)]` or similar. That removes the union type in 
CapabilitiesDoc and all three casts, including the one in validate_capabilities.



-- 
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]

Reply via email to