Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
sphinx4 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed May 11, 2021
1 parent e155aee commit 10f9716
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
27 changes: 25 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# serve to show the default.

import os
import re
import sys
from sphinx.ext import apidoc

Expand Down Expand Up @@ -366,6 +367,29 @@
"special-members": "__call__"
}

_package_base = "data_specification"


# Automatically called by sphinx at startup
def setup(app):
# NB: extra dot at end is deliberate!
trim = (_package_base + ".", "spinn_utilities.", "spinn_machine.")

# Magic to shorten the names of our classes to their public versions
def skip_handler(_app, what, name, obj, skip, _options):
if not skip and what == 'module' and hasattr(obj, "__module__"):
# Get parent module *and* check if our name is in it
m = re.sub(r'\.[a-z0-9_]+$', '', obj.__module__)
if any(m.startswith(prefix) for prefix in trim) and \
name in dir(sys.modules[m]):
# It is, so update to say that's canonical location for
# documentation purposes
obj.__module__ = m
return skip # We don't care to change this

# Connect the callback to the autodoc-skip-member event from apidoc
app.connect('autodoc-skip-member', skip_handler)


def filtered_files(base, unfiltered_files_filename):
with open(unfiltered_files_filename) as f:
Expand All @@ -384,7 +408,6 @@ def filtered_files(base, unfiltered_files_filename):

_output_dir = os.path.abspath(".")
_unfiltered_files = os.path.abspath("../unfiltered-files.txt")
_package_base = "data_specification"

# Do the rst generation; remove files which aren't in git first!
for fl in os.listdir("."):
Expand All @@ -393,5 +416,5 @@ def filtered_files(base, unfiltered_files_filename):
os.remove(fl)
os.chdir("../..") # WARNING! RELATIVE FILENAMES CHANGE MEANING HERE!
apidoc.main([
'-o', _output_dir, _package_base,
'-q', '-o', _output_dir, _package_base,
*filtered_files(_package_base, _unfiltered_files)])
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ flake8
coverage >= 4.4, < 5.0
# pytest will be brought in by pytest-cov
pytest-cov
sphinx >= 2
sphinx >= 4

0 comments on commit 10f9716

Please sign in to comment.