Skip to content

Commit

Permalink
Merge pull request #100 from dls-controls/fix_docs
Browse files Browse the repository at this point in the history
Make generate_docs build relative so it works on rtd
  • Loading branch information
coretl committed Jul 19, 2016
2 parents 893652d + 54999a3 commit 93f0d7a
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions docs/generate_api_docs.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import os


def generate_docs():
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))


repo_root = os.path.abspath('../')
def generate_docs():

if "build" not in os.listdir("./"):
os.mkdir("./build/")
if "build" not in os.listdir(os.path.join(repo_root, "docs")):
os.mkdir(os.path.join(repo_root, "docs", "build"))

# open the .rst file
with open(repo_root + '/docs/build/api.rst', 'w') as api_docs:
fname = os.path.join(repo_root, "docs", "build", "api.rst")
with open(fname, 'w') as api_docs:

# add header
api_docs.write('Malcolm API\n===========\n\n')

modules_root = repo_root + '/malcolm'
modules_root = os.path.join(repo_root, 'malcolm')
# create entries in the .rst file for each module

excluded_files = ['__init__.py']

for root, _, modules in os.walk(modules_root, topdown=True):
modules.sort()
if '__' not in root and len(root.split("pymalcolm/malcolm/")) > 1:
if '__' not in root and len(root.split("/malcolm/")) > 1:
modules[:] = [m for m in modules if m.split('.')[-1] == 'py']
modules[:] = [m for m in modules if m not in excluded_files]

Expand All @@ -31,15 +33,14 @@ def generate_docs():


def add_module_entry(module, _root, modules_list):
pkg_path = _root.split('pymalcolm/malcolm/')[1]
pkg_path = _root.split('/malcolm/')[1]
sub_section = pkg_path.replace('/', '.')
prefix = "../dev/api/"

module.write(sub_section.capitalize() + '\n' + '-' * len(sub_section) + '\n')
module.write(sub_section + '\n' + '-' * len(sub_section) + '\n')
module.write('\n.. toctree::\n')

for file_ in modules_list:
file_path = prefix + pkg_path + '/' + file_
file_path = os.path.join("..", "dev", "api", pkg_path, file_)
module.write(' ' * 4 + file_path.split('.py')[0] + '\n')
module.write('\n\n')

Expand Down

0 comments on commit 93f0d7a

Please sign in to comment.