Skip to content

Commit

Permalink
update readthedocs.yaml
Browse files Browse the repository at this point in the history
update readthedocs.yaml

readthedocs.yaml test

update docs 2

update docs 3

changes to docs

update docs/conf.py

docs test

update conf.py

fix Makefile

update year
  • Loading branch information
jamesa08 committed Mar 17, 2023
1 parent b7be2e9 commit 7426eb3
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 97 deletions.
16 changes: 5 additions & 11 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
SOURCEDIR = .
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
Expand All @@ -14,17 +14,11 @@ help:

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

html: Makefile
sphinx-apidoc -f -o source/api ../MIDIAnimator
python3 make.py
$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
python3 build_api_docs.py -f -o api ../MIDIAnimator
python3 -m sphinx -T -E -b html -d $(BUILDDIR)/doctrees . $(BUILDDIR)/html

clean: Makefile
rm -f source/api/*.rst
@echo "Removing everything under source/api/*.rst"
rm -f api/*.rst
@echo "Removing everything under api/*.rst"
$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
27 changes: 0 additions & 27 deletions docs/README.md

This file was deleted.

Empty file added docs/api/.gitkeep
Empty file.
66 changes: 66 additions & 0 deletions docs/build_api_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
import os

os.system('python3 -m pip install -r docs/requirements.txt')

from sphinx.ext.apidoc import main

if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
localDir = sys.argv[3]
main()

# because you cannot change how autodoc works, I wrote a custom stripper for the API docs that gets called before the docs are built.
# This is a bit of a hack, but it works.

for filename in os.listdir(localDir):
if ".libs." in filename\
or "MIDIAnimator.rst" == filename\
or "modules.rst" == filename:
os.remove(os.path.join(localDir, filename))

# now open the files up and edit them
# the first line of the file will be the title of the module. We want to replace " package" with nothing, and "MIDIAnimator." with nothing. Still keep the old name (With the " package" replacement), as we want to check this against other lines
# if the first two characters are "..", don't do anything (as this is an RST module), write the line and continue
# if the line contains "Submodules" and the next line after that contains a dash, do not write either of those lines
# if any line contains the first line of the file as described above + ".", replace it with nothing

for filename in os.listdir(localDir):
if ".libs." in filename\
or "MIDIAnimator.rst" == filename\
or "modules.rst" == filename:
continue
with open(os.path.join(localDir, filename), 'r') as f:
lines = f.readlines()

contains = False
title = ""
with open(os.path.join(localDir, filename), 'w') as f:
for i, line in enumerate(lines):
if i == 0:
title = line.replace(" package", "")
f.write(title.replace("MIDIAnimator.", ""))
title = title.strip()
continue
if line.startswith(".."):
f.write(line)
continue
if "Submodules" in line:
if lines[lines.index(line) + 1].startswith("-"):
contains = True
continue

if contains:
contains = False
continue

if title in line:
line = line.replace(title + ".", "")
if " module" in line:
# replace with ".py"
line = line.replace(" module", ".py")
f.write(line)

13 changes: 9 additions & 4 deletions docs/source/conf.py → docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import os
import sys
import re
import datetime

print(f"cwd={os.getcwd()}")
sys.path.insert(0, os.path.abspath("../"))

sys.path.insert(0, os.path.abspath("../../"))
from MIDIAnimator import bl_info

# -- Project information

project = 'MIDIAnimator'
copyright = '2023, James Alt'
copyright = f'{datetime.date.today().year}, James Alt'
author = 'James Alt'

release = bl_info['name'].split(" ")[-1]
Expand Down Expand Up @@ -42,14 +45,16 @@
# -- Options for EPUB output
epub_show_urls = 'footnote'

autodoc_mock_imports = ["MIDIAnimator.libs", "ObjectShapeKey"]
autodoc_mock_imports = ["MIDIAnimator.libs", "numpy"]

autodoc_class_signature = "separated"

add_module_names = False

exclude_patterns = ['api/modules.rst', 'api/MIDIAnimator.rst', 'api/MIDIAnimator.ui.rst']

master_doc = 'index'


# thank you to https://github.com/sphinx-doc/sphinx/issues/4065#issuecomment-538535280
def strip_signatures(app, what, name, obj, options, signature, return_annotation):
Expand All @@ -64,5 +69,5 @@ def strip_signatures(app, what, name, obj, options, signature, return_annotation
return sig, ret


def setup(app):
def setup(app):
app.connect('autodoc-process-signature', strip_signatures)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
54 changes: 0 additions & 54 deletions docs/make.py

This file was deleted.

File renamed without changes.
File renamed without changes.
17 changes: 16 additions & 1 deletion readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
version: 2

sphinx:
configuration: docs/conf.py

python:
install:
- requirements: docs/requirements.txt
- requirements: docs/requirements.txt

submodules:
include: all
recursive: true

build:
os: ubuntu-22.04
tools:
python: "3.11"
jobs:
pre_create_environment:
- echo "Update autodocs"
- python3 docs/build_api_docs.py -f -o docs/api MIDIAnimator

0 comments on commit 7426eb3

Please sign in to comment.