Skip to content

Commit 10debc8

Browse files
committed
Merge branch '2.0' into 2.0-migration-guide-plus
2 parents a9a605c + 85ebb78 commit 10debc8

6 files changed

Lines changed: 359 additions & 356 deletions

File tree

‎.github/workflows/docgen.yml‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: Generate Reference
3+
on:
4+
pull_request:
5+
push:
6+
branches: [master, main, 'v?[0-9]+.[0-9]+']
7+
jobs:
8+
docgen:
9+
name: Run generator script
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout the repository
13+
uses: actions/checkout@v4
14+
with:
15+
ref: ${{ github.event.pull_request.head.ref }}
16+
repository: ${{ github.event.pull_request.head.repo.full_name }}
17+
- name: Set up Python 3.13
18+
uses: actions/setup-python@v6
19+
with:
20+
python-version: '3.13'
21+
- name: Install deps
22+
run: |
23+
pip install -r docs/requirements.txt
24+
- name: Run script
25+
run: python docs/generate_reference.py ${{ github.head_ref || github.ref_name }}
26+
- name: commit changes
27+
uses: stefanzweifel/git-auto-commit-action@v7
28+
with:
29+
commit_message: Update docs/reference.md [no ci]
30+
file_pattern: docs/reference.md

‎.github/workflows/pr-checks.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: PR checks
33
on:
44
pull_request:
55
push:
6-
branches: [master, main, 'v?[0-9]+.[0-9]+**']
6+
branches: [master, main, 'v?[0-9]+.[0-9]+']
77
jobs:
88
linting:
99
name: Check Yamllint

‎TranslatorReasonerAPI.yaml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,6 @@ components:
801801
additionalProperties: true
802802
required:
803803
- nodes
804-
- edges
805804
QueryGraph:
806805
type: object
807806
description: >-
@@ -917,7 +916,7 @@ components:
917916
to AND)
918917
items:
919918
$ref: '#/components/schemas/AttributeConstraint'
920-
default: []
919+
minItems: 1
921920
additionalProperties: true
922921
QEdge:
923922
type: object

‎docs/generate_reference.py‎

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
"""Generate README."""
2-
import os
2+
3+
from pathlib import Path
34
import re
5+
import sys
6+
from typing import Any, Hashable, override
47

58
from jinja2 import Environment, FileSystemLoader
69
import yaml
710
from yaml.loader import SafeLoader
811

9-
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
12+
# So we can ensure we're going a directory up for the yaml
13+
SCRIPT_DIR = Path(__file__).absolute().parent
1014

1115

12-
def link_refs(string):
16+
def link_refs(string: str) -> str:
1317
"""Hyperlink refs."""
1418
return re.sub(
1519
r"\"\$ref\": \"#/components/schemas/(\w+)\"",
@@ -19,44 +23,46 @@ def link_refs(string):
1923

2024

2125
class SafeLineLoader(SafeLoader):
22-
def construct_mapping(self, node, deep=False):
26+
@override
27+
def construct_mapping(
28+
self, node: yaml.MappingNode, deep: bool = False
29+
) -> dict[Hashable, Any]:
2330
mapping = super().construct_mapping(node, deep=deep)
2431
# Add 1 so line numbering starts at 1
25-
mapping['_start'] = node.start_mark.line
26-
mapping['_end'] = node.end_mark.line
32+
mapping["_start"] = node.start_mark.line
33+
mapping["_end"] = node.end_mark.line
2734
return mapping
2835

2936

3037
def main():
3138
"""Generate README."""
32-
yamlpath = os.path.join(
33-
THIS_DIR,
34-
"TranslatorReasonerAPI.yaml",
35-
)
39+
yamlpath = SCRIPT_DIR.parent.joinpath("TranslatorReasonerAPI.yaml")
3640

3741
j2_env = Environment(
38-
loader=FileSystemLoader(THIS_DIR),
42+
loader=FileSystemLoader(SCRIPT_DIR),
3943
trim_blocks=False,
4044
keep_trailing_newline=True,
4145
extensions=[
4246
"jinja2.ext.do",
43-
]
47+
],
4448
)
4549

46-
with open(yamlpath, 'r') as stream:
50+
with yamlpath.open("r") as stream:
4751
data = yaml.load(stream, Loader=SafeLineLoader)
48-
components = data['components']
49-
schemas = components['schemas']
52+
components = data["components"]
53+
schemas = components["schemas"]
5054

5155
sha = "master"
56+
if len(sys.argv) >= 2:
57+
sha = sys.argv[1]
5258

53-
markdown = j2_env.get_template('reference_template.md').render(
59+
markdown = j2_env.get_template("reference_template.md").render(
5460
schemas=schemas,
5561
sha=sha,
5662
)
5763

58-
with open('reference.md', 'w') as stream:
59-
stream.write(markdown.encode('cp850', 'replace').decode('utf-8', 'replace'))
64+
with SCRIPT_DIR.joinpath("reference.md").open("w") as stream:
65+
_ = stream.write(markdown)
6066

6167

6268
if __name__ == "__main__":

0 commit comments

Comments
 (0)