Skip to content

Commit 044878d

Browse files
committed
feat: Add documentation auto generation for new signed documents
1 parent 39bbe30 commit 044878d

22 files changed

+273
-189
lines changed

.config/dictionaries/project.dic

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ pubkey
202202
publickey
203203
pubspec
204204
pwrite
205+
pytest
205206
qpsg
206207
quic
207208
rapidoc

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,6 @@ $RECYCLE.BIN/
8484
# Dart stuff
8585
/pubspec.lock
8686
/.dart_tool/**/*
87+
88+
# Python stuff
89+
.pytest_cache

.markdownlint-cli2.jsonc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"ignores": [
1111
".config/dictionaries/**",
1212
"**/target/**",
13-
"**/.dart_tool/**"
13+
"**/.dart_tool/**",
14+
"**/.pytest_cache/**"
1415
],
1516
// Set standard config options in `/.markdownlint.jsonc`
1617
"config": {

Justfile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ check-spelling:
1515
earthly +check-spelling
1616

1717

18+
# Fix and Check Markdown files
19+
format-python-code:
20+
ruff check --select I --fix .
21+
ruff format .
22+
23+
# Fix and Check Markdown files
24+
lint-python:
25+
ruff check .
26+
27+
# generates specifications data
28+
gen_specs:
29+
just specs/pre-push
30+
1831
# Pre Push Checks - intended to be run by a git pre-push hook.
19-
pre-push: check-markdown check-spelling
32+
pre-push: gen_specs check-markdown check-spelling format-python-code lint-python
2033
just rust/pre-push

docs/macros/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .include import inc_file
2-
from .signed_docs import (doc_type_summary, doc_type_details)
2+
from .signed_docs import doc_type_details, doc_type_summary, signed_doc_details
3+
34

45
def define_env(env):
56
"""
@@ -18,3 +19,7 @@ def insert_doc_type_summary():
1819
@env.macro
1920
def insert_doc_type_details():
2021
return doc_type_details(env)
22+
23+
@env.macro
24+
def insert_signed_doc_details(name):
25+
return signed_doc_details(env, name)

docs/macros/signed_docs.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import os
2-
import re
3-
import textwrap
41
import json
2+
import os
3+
4+
# import re
5+
# import textwrap
6+
7+
# SIGNED_DOCS_SPECS="signed_doc.json"
8+
SIGNED_DOCS_SPECS = "includes/signed_doc.json"
59

6-
#SIGNED_DOCS_SPECS="signed_doc.json"
7-
SIGNED_DOCS_SPECS="includes/signed_doc.json"
810

911
def uuid_as_cbor(uuid):
1012
return f"37(h'{uuid.replace('-', '')}')"
@@ -19,6 +21,7 @@ def get_signed_doc_data(env):
1921
with open(full_filename, "r") as f:
2022
return json.load(f)
2123

24+
2225
def doc_type_summary(env):
2326
"""
2427
Generate a Document Base Type Summary from the Document Specifications Data
@@ -34,7 +37,9 @@ def doc_type_summary(env):
3437
"""
3538

3639
for k in doc_types:
37-
doc_type_summary += f"| {k} | `{doc_types[k]}` | `{uuid_as_cbor(doc_types[k])}` |\n"
40+
doc_type_summary += (
41+
f"| {k} | `{doc_types[k]}` | `{uuid_as_cbor(doc_types[k])}` |\n"
42+
)
3843

3944
return doc_type_summary
4045
except Exception as exc:
@@ -50,23 +55,25 @@ def name_for_uuid(doc_types, uuid):
5055
return k
5156
return "Unknown"
5257

53-
54-
def name_to_spec_link(name,ref=None):
58+
59+
def name_to_spec_link(name, ref=None):
5560
"""
5661
Create a link to a document type, and an optional ref inside the document.
5762
"""
58-
link = "./../catalyst_docs/"+name.lower().replace(' ','_') + ".md"
63+
link = "./../catalyst_docs/" + name.lower().replace(" ", "_") + ".md"
5964
if ref is not None:
6065
link += f"#{ref}"
6166
return link
6267

68+
6369
def base_types(docs, doc_types, name):
6470
types = docs[name]["type"]
6571
type_names = ""
6672
for sub_type in types:
6773
type_names += name_for_uuid(doc_types, sub_type) + "/"
6874
return type_names[:-1]
6975

76+
7077
def types_as_cbor(docs, name):
7178
types = docs[name]["type"]
7279
type_names = "["
@@ -91,16 +98,24 @@ def doc_type_details(env):
9198
"""
9299

93100
for k in docs:
94-
doc_type_details += f"| {k} | {base_types(docs,doc_types,k)} | {types_as_cbor(docs,k)} | [Specification]({name_to_spec_link(k)}) | \n"
101+
doc_type_details += f"| {k} | {base_types(docs, doc_types, k)} | {types_as_cbor(docs, k)} | [Specification]({name_to_spec_link(k)}) | \n"
95102

96103
return doc_type_details
97104
except Exception as exc:
98105
return f"{exc}"
99106

100-
#class env:
107+
108+
def signed_doc_details(env, name):
109+
"""
110+
Generate Signed Document Detailed Documentation Page.
111+
"""
112+
return name + "\n" + "test\n"
113+
114+
115+
# class env:
101116
# project_dir = "/home/steven/Development/iohk/catalyst-libs/specs"
102117

103-
#if __name__ == '__main__':
118+
# if __name__ == '__main__':
104119

105-
# print(doc_type_details(env))
106-
# print(doc_type_summary(env))
120+
# print(doc_type_details(env))
121+
# print(doc_type_summary(env))
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
title: Catalyst Documents
2-
arrange:
3-
- proposal.md
4-
- review.md
5-
- comment.md
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Category Parameters
1+
# {{ insert_signed_doc_details( "Category Parameters" ) }}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Comment Action Document
1+
# {{ insert_signed_doc_details( "Comment Action Document" ) }}
File renamed without changes.

0 commit comments

Comments
 (0)