Skip to content

Commit

Permalink
Update apidocs generation to work with readthedocs
Browse files Browse the repository at this point in the history
  • Loading branch information
jgriffiths committed Apr 13, 2018
1 parent 348597b commit 13caebe
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 97 deletions.
9 changes: 8 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@ apidocs:
- ga
script:
- cd $CI_PROJECT_DIR
- ./tools/build_apidocs.sh
- ./tools/cleanup.sh
- virtualenv -p python2 .venv
- source .venv/bin/activate
- pip install sphinx sphinx_rtd_theme
- sphinx-build -b html -a -c docs/source docs/source docs/build/html
- cd docs/build && tar czf ../../apidocs.tar.gz html/ && cd ../..
- deactivate
- ./tools/cleanup.sh

package_release:
tags:
Expand Down
26 changes: 0 additions & 26 deletions docs/Makefile

This file was deleted.

56 changes: 56 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,62 @@
# -*- coding: utf-8 -*-
#
# libwally-core documentation build configuration file
SCANNING, DOCS, FUNC = 1, 2, 3

def get_doc_lines(l):
if l.startswith('.. '):
return [' ' + l, '']
return [' ' + l]

def output_func(docs, func):
is_normal_ret = 'WALLY_CORE_API int' in func
func = func[:-1].replace('WALLY_CORE_API','').strip()
func = func.replace(',',', ').replace(' ', ' ')
ret = ['.. c:function:: ' + func, '']
seen_param = False
for l in docs:
ret.extend(get_doc_lines(l))
if is_normal_ret:
ret.append(' :return: WALLY_OK or an error code.') # FIXME: Link
ret.append(' :rtype: int')
ret.append('')
ret.append('')
return ret

def extract_docs(infile, outfile):

lines = [l.strip() for l in open(infile).readlines()]
title = infile.split('_')[1][:-2].capitalize() + ' Functions'
title_markup = '=' * len(title)
output, current, func, state = [title, title_markup, ''], [], '', SCANNING

for l in lines:
if state == SCANNING:
if l.startswith('/**') and '*/' not in l:
current, func, state = [l[3:]], '', DOCS
elif state == DOCS:
if l == '*/':
state = FUNC
else:
assert l.startswith('*'), l
if l.startswith('*|'):
current[-1] += ' ' + l[2:].strip()
else:
current.append(l[1:].strip())
else: # FUNC
func += l
if ');' in func:
output.extend(output_func(current, func))
state = SCANNING
with open(outfile, 'w') as f:
f.write('\n'.join(output))

# Generate the documentation source files
# FIXME: elements
for m in [
'core', 'crypto', 'address', 'bip32', 'bip38', 'bip39', 'script', 'transaction'
]:
extract_docs('../../include/wally_%s.h' % m, '%s.rst' % m)

# -- General configuration ------------------------------------------------

Expand Down
13 changes: 0 additions & 13 deletions tools/build_apidocs.sh

This file was deleted.

57 changes: 0 additions & 57 deletions tools/extract_docs.py

This file was deleted.

0 comments on commit 13caebe

Please sign in to comment.