|
7 | 7 | # |
8 | 8 | # All configuration values have a default; values that are commented out |
9 | 9 | # serve to show the default. |
| 10 | +import asyncio |
10 | 11 | import inspect |
11 | 12 | import os |
12 | 13 | import shutil |
13 | 14 | import sys |
14 | 15 |
|
15 | 16 | __location__ = os.path.join(os.getcwd(), os.path.dirname(inspect.getfile(inspect.currentframe()))) |
16 | 17 |
|
| 18 | +from itertools import pairwise |
| 19 | + |
17 | 20 | # If extensions (or modules to document with autodoc) are in another directory, |
18 | 21 | # add these directories to sys.path here. If the directory is relative to the |
19 | 22 | # documentation root, use os.path.abspath to make it absolute, like shown here. |
20 | 23 | from pathlib import Path |
| 24 | +from typing import Iterable |
| 25 | + |
| 26 | +from bo4e_cli.diff.diff import diff_schemas |
| 27 | +from bo4e_cli.diff.matrix import create_compatibility_matrix, create_graph_from_changes, get_path_through_di_path_graph |
| 28 | +from bo4e_cli.edit.update_refs import update_references_all_schemas |
| 29 | +from bo4e_cli.io.changes import write_changes |
| 30 | +from bo4e_cli.io.console import CONSOLE |
| 31 | +from bo4e_cli.io.git import get_last_n_tags |
| 32 | +from bo4e_cli.io.github import download_schemas |
| 33 | +from bo4e_cli.io.matrix import write_compatibility_matrix_csv |
| 34 | +from bo4e_cli.io.schemas import read_schemas, write_schemas |
| 35 | +from bo4e_cli.models.meta import Schemas |
| 36 | +from bo4e_cli.models.version import Version |
| 37 | +from bo4e_cli.utils.github_cli import get_access_token_from_cli_if_installed |
21 | 38 |
|
22 | 39 | sys.path.insert(0, os.path.join(__location__, "../src")) |
23 | 40 | sys.path.insert(0, os.path.join(__location__, "../docs")) |
24 | 41 | sys.path.insert(0, os.path.join(__location__, "../docs/compatibility")) |
25 | 42 | import uml |
26 | | -from compatibility.__main__ import create_tables_for_doc |
27 | 43 |
|
28 | 44 | # import package bo4e to clarify namespaces and prevent circular import errors |
29 | 45 | from bo4e import * |
@@ -187,11 +203,11 @@ def setup(app): |
187 | 203 | # be set by the action. This is to support things like /latest or /stable. |
188 | 204 | if "release" not in globals(): |
189 | 205 | release = os.getenv("SPHINX_DOCS_RELEASE") |
190 | | - if release is None: |
| 206 | + if not release: |
191 | 207 | from bo4e import __gh_version__ as release |
192 | 208 | if "version" not in globals(): |
193 | 209 | version = os.getenv("SPHINX_DOCS_VERSION") |
194 | | - if version is None: |
| 210 | + if not version: |
195 | 211 | from bo4e import __version__ as version |
196 | 212 |
|
197 | 213 | print(f"Got version = {version} from __version__") |
@@ -336,7 +352,42 @@ def setup(app): |
336 | 352 | print(f"Compiled uml files into svg using kroki.") |
337 | 353 |
|
338 | 354 | # Create compatibility matrix |
| 355 | +# CONSOLE.verbose = True |
339 | 356 | compatibility_matrix_output_file = Path(__file__).parent / "_static/tables/compatibility_matrix.csv" |
340 | | -gh_token = os.getenv("GITHUB_ACCESS_TOKEN") or os.getenv("GITHUB_TOKEN") |
341 | | -create_tables_for_doc(compatibility_matrix_output_file, release, last_n_versions=0, gh_token=gh_token) |
| 357 | +gh_token = os.getenv("GITHUB_ACCESS_TOKEN") or os.getenv("GITHUB_TOKEN") or get_access_token_from_cli_if_installed() |
| 358 | + |
| 359 | +release_version = Version.from_str(release) |
| 360 | +compiling_from_release_workflow = not release_version.is_dirty() |
| 361 | +last_versions = get_last_n_tags( |
| 362 | + n=0, |
| 363 | + ref=str(release) if compiling_from_release_workflow else "HEAD", |
| 364 | + exclude_candidates=True, |
| 365 | + exclude_technical_bumps=True, |
| 366 | +) |
| 367 | +schemas_base_dir = Path(__file__).parents[1] / "tmp/bo4e_json_schemas" |
| 368 | +changes_base_dir = Path(__file__).parents[1] / "tmp/changes" |
| 369 | + |
| 370 | + |
| 371 | +async def download_missing_schemas(versions: Iterable[Version], gh_token: str | None = None) -> list[Schemas]: |
| 372 | + schemas_list = [] |
| 373 | + for _version in versions: |
| 374 | + schemas_dir = schemas_base_dir / str(_version) |
| 375 | + if not schemas_dir.exists(): |
| 376 | + schemas_list.append(await download_schemas(_version, gh_token)) |
| 377 | + update_references_all_schemas(schemas_list[-1]) |
| 378 | + write_schemas(schemas_list[-1], schemas_dir) |
| 379 | + else: |
| 380 | + schemas_list.append(read_schemas(schemas_dir)) |
| 381 | + return schemas_list |
| 382 | + |
| 383 | + |
| 384 | +schemas = asyncio.run(download_missing_schemas(last_versions, gh_token)) |
| 385 | +changes = [diff_schemas(schemas_1, schemas_2) for schemas_1, schemas_2 in pairwise(reversed(schemas))] |
| 386 | +for changes_obj in changes: |
| 387 | + write_changes(changes_obj, changes_base_dir / f"{changes_obj.old_version}_to_{changes_obj.new_version}.json") |
| 388 | +graph = create_graph_from_changes(iter(changes)) |
| 389 | +graph_path = get_path_through_di_path_graph(graph) |
| 390 | +compatibility_matrix = create_compatibility_matrix(graph, graph_path, use_emotes=True) |
| 391 | +write_compatibility_matrix_csv(compatibility_matrix_output_file, compatibility_matrix, graph_path) |
| 392 | + |
342 | 393 | print(f"Created compatibility matrix at static folder {compatibility_matrix_output_file}") |
0 commit comments