Skip to content

Commit 2a3c8cc

Browse files
authored
New docs generation (terminusdb#405)
* Fix docs and license * Try to insert docs * Use poetry * Add commit message and author * Remove the commit message and author * Fix integration tests because of new requests lib (terminusdb#395) * Fix conversion of sys:JSON type schema to Python (terminusdb#400) If a class contained a "sys:JSON" property, it wouldn't convert to a normal Python class as it should. Fixes issue terminusdb#397 * Add version 10.2.3 * Change title of application and description * Get examples * ci: don't do poetry interactively * Fix parameters for patch function * Only generate docs on version push or manual run
1 parent 2fb9cf8 commit 2a3c8cc

File tree

4 files changed

+150
-99
lines changed

4 files changed

+150
-99
lines changed

.github/insert_docs.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python3
2+
import inspect
3+
import json
4+
5+
import terminusdb_client
6+
from numpydoc.docscrape import FunctionDoc, ClassDoc
7+
8+
def parameter_to_document(param):
9+
return {'@type': 'Parameter', 'type': param.type, 'name': param.name, 'summary': "\n".join(param.desc)}
10+
11+
classes_to_scan = ['Client']#, 'WOQLQuery']
12+
classes = []
13+
14+
for name, obj in inspect.getmembers(terminusdb_client):
15+
if inspect.isclass(obj) and 'terminusdb' in str(obj):
16+
if name in classes_to_scan:
17+
docstring_class = ClassDoc(obj)
18+
class_params = [parameter_to_document(x) for x in docstring_class['Attributes']]
19+
functions = []
20+
for func in obj.__dict__.values():
21+
if callable(func) and func.__doc__:
22+
docstring_function = FunctionDoc(func)
23+
parameters = [parameter_to_document(x) for x in docstring_function['Parameters']]
24+
examples = '\n'.join(docstring_function['Examples'])
25+
if len(docstring_function['Returns']) > 0:
26+
ret = docstring_function['Returns'][0] # Functions always have one return
27+
returns = {'@type': 'Returns', 'name': '', 'type': ret.type}
28+
if len(ret.desc) > 0:
29+
returns['summary'] = "\n".join(ret.desc)
30+
else:
31+
returns = {'@type': 'Returns', 'name': '', 'type': 'void'}
32+
function_obj = {'@type': 'Definition',
33+
'name': func.__name__,
34+
'parameters': parameters,
35+
'returns': returns,
36+
'examples': [examples] if examples != "" else None,
37+
'summary': "\n".join(docstring_function['Summary'])}
38+
functions.append(function_obj)
39+
class_obj = {'@type': 'Class', 'name': name, 'summary': "\n".join(docstring_class['Summary']), 'memberVariables': class_params, 'memberFunctions': functions}
40+
classes.append(class_obj)
41+
42+
application = {
43+
'@type': 'Application',
44+
'version': terminusdb_client.__version__.__version__,
45+
'name': terminusdb_client.__version__.__title__,
46+
'summary': terminusdb_client.__version__.__description__,
47+
'language': 'Python',
48+
'license': terminusdb_client.__version__.__license__,
49+
'modules': [
50+
{
51+
'@type': 'Module',
52+
'name': 'terminusdb_client',
53+
'classes': classes
54+
}
55+
]}
56+
57+
print(json.dumps(application))

.github/workflows/docs.yml

+12-25
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
push:
88
tags:
99
- v*
10+
workflow_dispatch:
1011

1112
jobs:
1213
make_docs:
@@ -18,29 +19,15 @@ jobs:
1819
uses: actions/setup-python@v4
1920
with:
2021
python-version: '3.x'
21-
- name: Generate docs
22+
- name: Install requirements
2223
run: |
23-
git clone --single-branch --branch add_gitbook https://github.com/terminusdb/pydoc-markdown.git
24-
python -m pip install --upgrade pip
25-
pip install ./pydoc-markdown
26-
pydoc-markdown
27-
cd docs
28-
python -m pip install -r requirements.txt
29-
make markdown
30-
python generateGitbookMD.py
31-
cp -r reference/* build/markdown/gitbook-md/
32-
- name: Set destination BRANCH_NAME for docs repo
33-
run: echo "BRANCH_NAME=Python-Reference-Updates-$(date +%s)" >> $GITHUB_ENV
34-
- name: Create pull request in terminusdb/terminusdb-docs
35-
uses: paygoc6/[email protected]
36-
env:
37-
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
38-
with:
39-
source_folder: 'docs/build/markdown/gitbook-md'
40-
destination_repo: 'terminusdb/terminusdb-docs'
41-
destination_folder: 'guides/reference-guides/python-client-reference'
42-
destination_base_branch: 'main'
43-
destination_head_branch: ${{ env.BRANCH_NAME }}
44-
user_email: '[email protected]'
45-
user_name: 'rrooij'
46-
pull_request_reviewers: 'GavinMendelGleason'
24+
pip install poetry
25+
poetry install -n
26+
- name: Generate docs JSON
27+
run: poetry run python .github/insert_docs.py > docs.json
28+
- name: Upload to TerminusCMS
29+
run: |
30+
curl -H 'Authorization: Token ${{ secrets.TERMINUSCMS_TOKEN}}' \
31+
-H 'Content-Type: application/json' \
32+
'${{ secrets.TERMINUSCMS_URL}}' -d @./docs.json
33+

terminusdb_client/__version__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
__title__ = "woqlClient"
2-
__description__ = "woqlClient library for accessing the Terminus DB API"
1+
__title__ = "terminusdb-client"
2+
__description__ = "TerminusDB client library for accessing the Terminus DB API"
33
__url__ = ""
44
__version__ = "10.2.3"
55
__build__ = 00
66
__author__ = "TerminusDB group"
77
__author_email__ = "[email protected]"
8-
__license__ = "GNU General Public License v3 (GPLv3)"
8+
__license__ = "Apache 2.0"
99
__copyright__ = "Copyright 2019 datachemist"

0 commit comments

Comments
 (0)