Skip to content

Commit 8821e62

Browse files
committed
Fix autosummary by patching stub sub-modules in conf.py
1 parent fce632e commit 8821e62

23 files changed

+32
-29
lines changed

spec/2021.12/conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import sys
2+
3+
from array_api_stubs import _2021_12 as stubs_mod
4+
from _spec_conf import *
5+
6+
release = "2021.12"
7+
sys.modules["signatures"] = stubs_mod

spec/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ help:
2121

2222
clean:
2323
-rm -rf $(BUILDDIR)
24-
-rm -rf "$(SOURCEDIR)/draft/API_specification/generated"
25-
-rm -rf "$(SOURCEDIR)/draft/extensions/generated"
24+
-rm -rf $(SOURCEDIR)/**/generated

spec/draft/conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import sys
2+
3+
from array_api_stubs import _draft as stubs_mod
4+
from _spec_conf import *
5+
6+
release = "DRAFT"
7+
sys.modules["array_api"] = stubs_mod

spec/conf.py renamed to src/_spec_conf.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,18 @@
1-
# Configuration file for the Sphinx documentation builder.
1+
# Base configuration file for the Sphinx documentation builder.
22
#
33
# This file only contains a selection of the most common options. For a full
44
# list see the documentation:
55
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
import re
67

7-
# -- Path setup --------------------------------------------------------------
8-
9-
# If extensions (or modules to document with autodoc) are in another directory,
10-
# add these directories to sys.path here. If the directory is relative to the
11-
# documentation root, use os.path.abspath to make it absolute, like shown here.
12-
#
13-
import os
14-
import sys
158
import sphinx_material
16-
import array_api_stubs
179

1810
# -- Project information -----------------------------------------------------
1911

2012
project = 'Python array API standard'
2113
copyright = '2020, Consortium for Python Data API Standards'
2214
author = 'Consortium for Python Data API Standards'
2315

24-
# The full version, including alpha/beta/rc tags
25-
release = '2022.05-DRAFT'
26-
27-
2816
# -- General configuration ---------------------------------------------------
2917

3018
# Add any Sphinx extension module names here, as strings. They can be
@@ -64,23 +52,23 @@
6452
# autodoc wants to make cross-references for every type hint. But a lot of
6553
# them don't actually refer to anything that we have a document for.
6654
nitpick_ignore = [
67-
('py:class', 'device'),
68-
('py:class', 'dtype'),
69-
('py:class', 'NestedSequence'),
70-
('py:class', 'SupportsBufferProtocol'),
7155
('py:class', 'collections.abc.Sequence'),
7256
('py:class', "Optional[Union[int, float, Literal[inf, - inf, 'fro', 'nuc']]]"),
7357
('py:class', "Union[int, float, Literal[inf, - inf]]"),
7458
('py:obj', "typing.Optional[typing.Union[int, float, typing.Literal[inf, - inf, 'fro', 'nuc']]]"),
7559
('py:obj', "typing.Union[int, float, typing.Literal[inf, - inf]]"),
76-
('py:class', 'PyCapsule'),
7760
('py:class', 'enum.Enum'),
7861
('py:class', 'ellipsis'),
79-
('py:class', 'finfo_object'),
80-
('py:class', 'iinfo_object'),
8162
]
8263
nitpick_ignore_regex = [
8364
('py:class', '.*array'),
65+
('py:class', '.*device'),
66+
('py:class', '.*dtype'),
67+
('py:class', '.*NestedSequence'),
68+
('py:class', '.*SupportsBufferProtocol'),
69+
('py:class', '.*PyCapsule'),
70+
('py:class', '.*finfo_object'),
71+
('py:class', '.*iinfo_object'),
8472
]
8573
# In array_object.py we have to use aliased names for some types because they
8674
# would otherwise refer back to method objects of array
@@ -101,7 +89,7 @@
10189
autosummary_mod.mangle_signature = lambda sig, max_chars=30: sig
10290

10391
# Add any paths that contain templates here, relative to this directory.
104-
templates_path = ['_templates']
92+
templates_path = ['../_templates']
10593

10694
# List of patterns, relative to source directory, that match files and
10795
# directories to ignore when looking for source files.
@@ -125,7 +113,7 @@
125113
# Add any paths that contain custom static files (such as style sheets) here,
126114
# relative to this directory. They are copied after the builtin static files,
127115
# so a file named "default.css" will overwrite the builtin "default.css".
128-
html_static_path = ['_static']
116+
html_static_path = ['../_static']
129117

130118

131119
# -- Material theme options (see theme.conf for more information) ------------
@@ -137,7 +125,7 @@
137125
html_theme_options = {
138126

139127
# Set the name of the project to appear in the navigation.
140-
'nav_title': f'Python array API standard {release}',
128+
'nav_title': f'Python array API standard',
141129

142130
# Set you GA account ID to enable tracking
143131
#'google_analytics_account': 'UA-XXXXX',
@@ -206,12 +194,14 @@
206194
"pypa": ("https://packaging.python.org/%s", ""),
207195
}
208196

197+
# -- Prettify type hints -----------------------------------------------------
198+
r_type_prefix = re.compile(r"array_api_stubs\._[a-z0-9_]+\._types\.")
209199

210200
def process_signature(app, what, name, obj, options, signature, return_annotation):
211201
if signature:
212-
signature = signature.replace("array_api._types.", "")
202+
signature = re.sub(r_type_prefix, "", signature)
213203
if return_annotation:
214-
return_annotation = return_annotation.replace("array_api._types.", "")
204+
return_annotation = re.sub(r_type_prefix, "", return_annotation)
215205
return signature, return_annotation
216206

217207
def setup(app):

src/array_api_stubs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from . import draft
1+
from . import _2021_12, _draft
22

File renamed without changes.

0 commit comments

Comments
 (0)