Skip to content

Commit

Permalink
Merge pull request #2 from marian-nmt/tg/apidoc
Browse files Browse the repository at this point in the history
API doc via python instead of bash and make
  • Loading branch information
thammegowda authored Jul 31, 2023
2 parents 079cc97 + dc7372d commit 2e16e78
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
9 changes: 3 additions & 6 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ SPHINXBUILD ?= sphinx-build
SPHINXAPIDOC ?= sphinx-apidoc
SOURCEDIR = .
BUILDDIR = build
MODULE_NAME = sotastream
CODEDIR = ../$(MODULE_NAME)
MODULE_NAME = sotastream
CODEDIR = ../$(MODULE_NAME)

# Put it first so that "make" without argument is like "make help".
help:
Expand All @@ -21,8 +21,5 @@ help:
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).

%: Makefile
@if [ $@ = "html" ]; then \
$(SPHINXAPIDOC) -o "$(SOURCEDIR)/api" --force "$(CODEDIR)" -H "$(MODULE_NAME) API";\
fi
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@if [ $@ = "clean" ]; then rm -rf "$(SOURCEDIR)/api/"; fi
@if [ $@ = "clean" ]; then rm -rf "$(SOURCEDIR)/api/"; fi
17 changes: 14 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.parent.parent.absolute()))
# <root>/docs/source/conf.py i.e three levels up ^
DOCS_DIR = Path(__file__).parent.absolute()
PROJECT_DIR = DOCS_DIR.parent
# <root>/docs/conf.py i.e two levels up ^
SRC_DIR = PROJECT_DIR / 'sotastream'

sys.path.insert(0, str(PROJECT_DIR))
import sotastream # this import should work

# -- Project information -----------------------------------------------------
Expand All @@ -25,7 +29,6 @@
'sphinx.ext.autodoc',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages',
'sphinx.ext.autodoc',
]

Expand All @@ -40,3 +43,11 @@
# html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']

def run_apidoc(_):
# from sphinx.apidoc import main # for older Sphinx <= 1.6
from sphinx.ext.apidoc import main # for newer
main(['-e', '-o', str(DOCS_DIR / 'api'), str(SRC_DIR), '--force'])

def setup(app):
app.connect('builder-inited', run_apidoc)

0 comments on commit 2e16e78

Please sign in to comment.