Skip to content

Commit c414e38

Browse files
committed
Fix documentation creation
1 parent e84b009 commit c414e38

3 files changed

Lines changed: 59 additions & 10 deletions

File tree

.github/workflows/docs_latest.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ jobs:
4444
# Note: The sphinx action below can only install a single requirements file.
4545
- name: Build JSON Schemas
4646
run: tox -e generate_json_schemas
47-
env:
48-
TARGET_VERSION: ${{ env.REF_NAME }}
4947
- name: Build BO4E package
5048
# Note: This step necessary to correctly set the version in the JSON-Schema-links
5149
run: |

docs/conf.py

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,39 @@
77
#
88
# All configuration values have a default; values that are commented out
99
# serve to show the default.
10+
import asyncio
1011
import inspect
1112
import os
1213
import shutil
1314
import sys
1415

1516
__location__ = os.path.join(os.getcwd(), os.path.dirname(inspect.getfile(inspect.currentframe())))
1617

18+
from itertools import pairwise
19+
1720
# If extensions (or modules to document with autodoc) are in another directory,
1821
# add these directories to sys.path here. If the directory is relative to the
1922
# documentation root, use os.path.abspath to make it absolute, like shown here.
2023
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
2138

2239
sys.path.insert(0, os.path.join(__location__, "../src"))
2340
sys.path.insert(0, os.path.join(__location__, "../docs"))
2441
sys.path.insert(0, os.path.join(__location__, "../docs/compatibility"))
2542
import uml
26-
from compatibility.__main__ import create_tables_for_doc
2743

2844
# import package bo4e to clarify namespaces and prevent circular import errors
2945
from bo4e import *
@@ -187,11 +203,11 @@ def setup(app):
187203
# be set by the action. This is to support things like /latest or /stable.
188204
if "release" not in globals():
189205
release = os.getenv("SPHINX_DOCS_RELEASE")
190-
if release is None:
206+
if not release:
191207
from bo4e import __gh_version__ as release
192208
if "version" not in globals():
193209
version = os.getenv("SPHINX_DOCS_VERSION")
194-
if version is None:
210+
if not version:
195211
from bo4e import __version__ as version
196212

197213
print(f"Got version = {version} from __version__")
@@ -336,7 +352,42 @@ def setup(app):
336352
print(f"Compiled uml files into svg using kroki.")
337353

338354
# Create compatibility matrix
355+
# CONSOLE.verbose = True
339356
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+
342393
print(f"Created compatibility matrix at static folder {compatibility_matrix_output_file}")

tox.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ deps =
8585
{[testenv:generate_json_schemas]deps}
8686
# any dependency added here should also be added in docs/requirements.in and docs/requirements.txt respectively
8787
setenv =
88-
TARGET_VERSION = {env:TARGET_VERSION:local}
89-
SPHINX_DOCS_RELEASE = {env:TARGET_VERSION:local}
90-
SPHINX_DOCS_VERSION = {env:TARGET_VERSION:local}
88+
TARGET_VERSION = {env:TARGET_VERSION:}
89+
SPHINX_DOCS_RELEASE = {env:TARGET_VERSION:}
90+
SPHINX_DOCS_VERSION = {env:TARGET_VERSION:}
9191
commands =
9292
{[testenv:generate_json_schemas]commands}
9393
sphinx-build -T -W -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html

0 commit comments

Comments
 (0)