|
8 | 8 | import sphinx_rtd_theme |
9 | 9 | from sphinx.ext.apidoc import main |
10 | 10 |
|
| 11 | +web_docs = False |
| 12 | +if 'PSIJ_WEB_DOCS' in os.environ: |
| 13 | + web_docs = True |
| 14 | + |
11 | 15 | needs_sphinx = '1.6' |
12 | 16 |
|
13 | 17 | # Set Sphinx variables |
14 | 18 | master_doc = 'index' |
15 | 19 |
|
16 | 20 | project = u'PSI/J' |
17 | 21 | copyright = u'The ExaWorks Team' |
18 | | - |
19 | | -html_theme = 'sphinx_rtd_theme' |
20 | | -html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] |
| 22 | +if web_docs: |
| 23 | + html_theme = 'cloud' |
| 24 | +else: |
| 25 | + html_theme = 'sphinx_rtd_theme' |
| 26 | + html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] |
21 | 27 | html_favicon = 'favicon.ico' |
22 | 28 | autoclass_content = 'both' |
23 | 29 | add_module_names = False |
|
28 | 34 | ('py:class', 'distutils.version.Version') |
29 | 35 | ] |
30 | 36 |
|
| 37 | +if web_docs: |
| 38 | + templates_path = ['_templates'] |
| 39 | + # Unfortunately sphinx-multiversion does not properly deal with |
| 40 | + # setting the title to the proper version. You either get some |
| 41 | + # default like "0.0.1" or you get whatever the current conf.py |
| 42 | + # sets (i.e., the latest version). |
| 43 | + # See, e.g., https://github.com/Holzhaus/sphinx-multiversion/issues/61 |
| 44 | + # |
| 45 | + # But we already have the version selector that displays the version, |
| 46 | + # so we can display that where the broken version would otherwise |
| 47 | + # have appeared. |
| 48 | + html_title = "PSI/J" |
| 49 | + # Multi-version |
| 50 | + smv_branch_whitelist = '^matchmeifyoucan$' |
| 51 | + smv_remote_whitelist = None |
| 52 | + smv_released_pattern = r'^\d+\.\d+\.\d+(\..*)?$' |
| 53 | + smv_outputdir_format = 'v/{ref.name}' |
| 54 | + |
| 55 | + |
31 | 56 | html_sidebars = {'**': ['globaltoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html']} |
32 | 57 |
|
33 | 58 | # These are needed for the dhtml trickery |
|
44 | 69 | 'sphinx.ext.viewcode', |
45 | 70 | ] |
46 | 71 |
|
| 72 | +if web_docs: |
| 73 | + extensions.append('sphinx_multiversion') |
| 74 | + |
47 | 75 | autodoc_typehints = "description" |
48 | 76 | autodoc_typehints_format = "short" |
49 | 77 |
|
| 78 | +release = None |
| 79 | +version = None |
| 80 | +src_dir = None |
| 81 | + |
| 82 | +def read_version(docs_dir): |
| 83 | + global release, version, src_dir |
| 84 | + src_dir = os.path.abspath(os.path.join(docs_dir, '../src')) |
50 | 85 |
|
51 | | -script_dir = os.path.normpath(os.path.dirname(__file__)) |
52 | | -src_dir = os.path.abspath(os.path.join(script_dir, '../src')) |
| 86 | + sys.path.insert(0, src_dir) |
53 | 87 |
|
54 | | -print(src_dir + "/") |
| 88 | + import psij |
| 89 | + release = psij.__version__ |
| 90 | + version = release |
55 | 91 |
|
56 | | -sys.path.insert(0, src_dir) |
57 | 92 |
|
58 | | -import psij |
59 | | -release = psij.__version__ |
60 | | -version = release |
| 93 | +my_dir = os.path.normpath(os.path.dirname(__file__)) |
| 94 | +read_version(my_dir) |
61 | 95 |
|
62 | 96 | intersphinx_mapping = { |
63 | 97 | 'python': ('https://docs.python.org/3', None), |
|
69 | 103 | # Copied from https://github.com/readthedocs/readthedocs.org/issues/1139 |
70 | 104 |
|
71 | 105 | # run api doc |
72 | | -def run_apidoc(_): |
73 | | - output_path = os.path.join(script_dir, '.generated') |
74 | | - print(f"OUTPUT PATH = {output_path}") |
75 | | - #exclusions = [os.path.join(src_dir, 'setup.py'),] |
| 106 | +def run_apidoc(sphinx): |
| 107 | + read_version(sphinx.srcdir) # this sets src_dir based on the version being compiled |
| 108 | + output_path = os.path.join(sphinx.srcdir, '.generated') |
76 | 109 | main(['-f', '-o', output_path, src_dir]) |
77 | 110 |
|
78 | 111 | # launch setup |
|
0 commit comments