Skip to content

Commit 0d61611

Browse files
author
Diptorup Deb
committed
Split out Python API classes into separate pages.
- All Python API classes are now documented under separate pages. - Add an autosummary to each class documentation page. - Rename dpCtl to dpctl in few places.
1 parent e18b716 commit 0d61611

10 files changed

+250
-28
lines changed

docs/conf.in

+91-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extensions = [
3232
"sphinx.ext.viewcode",
3333
"sphinx.ext.githubpages",
3434
"sphinx.ext.autodoc",
35+
"sphinx.ext.autosummary",
3536
"sphinx.ext.napoleon",
3637
]
3738

@@ -69,7 +70,7 @@ source_suffix = ".rst"
6970
# This pattern also affects html_static_path and html_extra_path.
7071
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
7172

72-
highlight_language = "c"
73+
highlight_language = "Python"
7374

7475
# The name of the Pygments (syntax highlighting) style to use.
7576
pygments_style = "sphinx"
@@ -140,3 +141,92 @@ if generate_multiversion == "ON":
140141
html_context["versions"].append(
141142
(version, DOC_SITE_NAME + version + "/index.html")
142143
)
144+
145+
# Add an "autoclassmembers" directive that acts the same way as
146+
# "autoclass", but does not print out the class doc.
147+
148+
from sphinx.ext.autodoc import ClassDocumenter, ObjectMembers
149+
from sphinx.ext.autodoc.importer import get_class_members
150+
151+
152+
class ClassMembersDocumenter(ClassDocumenter):
153+
"""
154+
Documenter for only class members and skips the class and __init__
155+
docstrings.
156+
"""
157+
158+
objtype = "classmembers"
159+
160+
def add_directive_header(self, sig):
161+
pass
162+
163+
def get_doc(self, encoding=None, ignore=None):
164+
return None
165+
166+
167+
# Add an "autoautosummary" directive to add a summary table of class
168+
# members and attributes.
169+
# See https://stackoverflow.com/questions/20569011/python-sphinx-autosummary-automated-listing-of-member-functions
170+
171+
from sphinx.ext.autosummary import Autosummary
172+
from sphinx.ext.autosummary import get_documenter
173+
from docutils.parsers.rst import directives
174+
from sphinx.util.inspect import safe_getattr
175+
176+
177+
class AutoAutoSummary(Autosummary):
178+
"""Create a summary for methods and attributes (autosummary).
179+
See https://stackoverflow.com/questions/20569011/python-sphinx-autosummary-automated-listing-of-member-functions
180+
"""
181+
182+
option_spec = {
183+
"methods": directives.unchanged,
184+
"private_methods": directives.unchanged,
185+
"attributes": directives.unchanged,
186+
}
187+
188+
required_arguments = 1
189+
190+
@staticmethod
191+
def get_members(app, obj, typ, include_public=None):
192+
if not include_public:
193+
include_public = []
194+
items = []
195+
for name in sorted(obj.__dict__.keys()):
196+
try:
197+
documenter = get_documenter(app, safe_getattr(obj, name), obj)
198+
except AttributeError:
199+
continue
200+
if documenter.objtype in typ:
201+
items.append(name)
202+
return items
203+
204+
def run(self):
205+
clazz = str(self.arguments[0])
206+
(module_name, class_name) = clazz.rsplit(".", 1)
207+
m = __import__(module_name, globals(), locals(), [class_name])
208+
c = getattr(m, class_name)
209+
app = self.state.document.settings.env.app
210+
if "methods" in self.options:
211+
methods = self.get_members(app, c, ["method"], ["__init__"])
212+
self.content = [
213+
"%s" % method for method in methods if not method.startswith("_")
214+
]
215+
if "private_methods" in self.options:
216+
private_methods = self.get_members(app, c, ["method"], ["__init__"])
217+
self.content = [
218+
"%s" % method
219+
for method in private_methods
220+
if method.startswith("_") and not method.startswith("__")
221+
]
222+
if "attributes" in self.options:
223+
attribs = self.get_members(app, c, ["attribute", "property"])
224+
self.content = [
225+
"%s" % attrib for attrib in attribs if not attrib.startswith("_")
226+
]
227+
return super().run()
228+
229+
230+
def setup(app):
231+
app.add_directive("autoautosummary", AutoAutoSummary)
232+
app.add_autodocumenter(ClassMembersDocumenter)

docs/docfiles/dpctl.dptensor_api.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
.. _dpCtl.dptensor_api:
1+
.. _dpctl.dptensor_api:
22

3-
#########################
4-
dpctl dptensor Python API
5-
#########################
3+
##############
4+
dpctl.dptensor
5+
##############
66

77
.. automodule:: dpctl.dptensor
88
:members:

docs/docfiles/dpctl.memory_api.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
.. _dpCtl.memory_api:
1+
.. _dpctl.memory_api:
22

3-
#######################
4-
dpCtl Memory Python API
5-
#######################
3+
############
4+
dpctl.memory
5+
############
66

77
.. automodule:: dpctl.memory
88

docs/docfiles/dpctl.program_api.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
.. _dpCtl.program_api:
1+
.. _dpctl.program_api:
22

3-
########################
4-
dpctl Program Python API
5-
########################
3+
#############
4+
dpctl.program
5+
#############
66

77
.. automodule:: dpctl.program
88

docs/docfiles/dpctl_pyapi.rst

+7-15
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,14 @@ Sub-modules
1919
Classes
2020
-------
2121

22-
.. autoclass:: dpctl.SyclContext
23-
:members:
24-
:undoc-members:
25-
26-
.. autoclass:: dpctl.SyclDevice
27-
:members:
28-
:inherited-members:
29-
:undoc-members:
30-
31-
.. autoclass:: dpctl.SyclEvent
32-
:members:
33-
:undoc-members:
22+
.. toctree::
23+
:maxdepth: 1
3424

35-
.. autoclass:: dpctl.SyclQueue
36-
:members:
37-
:undoc-members:
25+
dpctl_pyapi/SyclContext
26+
dpctl_pyapi/SyclDevice
27+
dpctl_pyapi/SyclEvent
28+
dpctl_pyapi/SyclPlatform
29+
dpctl_pyapi/SyclQueue
3830

3931
Enumerations
4032
------------
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. _SyclContext_api:
2+
3+
#################
4+
dpctl.SyclContext
5+
#################
6+
7+
.. autoclass:: dpctl.SyclContext
8+
9+
.. rubric:: Attributes:
10+
11+
.. autoautosummary:: dpctl.SyclContext
12+
:attributes:
13+
14+
.. rubric:: Private methods:
15+
16+
.. autoautosummary:: dpctl.SyclContext
17+
:private_methods:
18+
19+
.. rubric:: Public methods:
20+
21+
.. autoautosummary:: dpctl.SyclContext
22+
:methods:
23+
24+
Detail
25+
======
26+
27+
Private methods
28+
---------------
29+
30+
.. autoclassmembers:: dpctl.SyclContext
31+
:noindex:
32+
:private-members: _get_capsule
33+
34+
35+
Public methods
36+
--------------
37+
38+
.. autoclassmembers:: dpctl.SyclContext
39+
:noindex:
40+
:members:
41+
:undoc-members:
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.. _SyclDevice_api:
2+
3+
################
4+
dpctl.SyclDevice
5+
################
6+
7+
.. autoclass:: dpctl.SyclDevice
8+
9+
.. rubric:: Attributes:
10+
11+
.. autoautosummary:: dpctl.SyclDevice
12+
:attributes:
13+
14+
.. rubric:: Public methods:
15+
16+
.. autoautosummary:: dpctl.SyclDevice
17+
:methods:
18+
19+
Detail
20+
======
21+
22+
Public methods
23+
--------------
24+
25+
.. autoclassmembers:: dpctl.SyclDevice
26+
:noindex:
27+
:members:
28+
:undoc-members:
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. _SyclEvent_api:
2+
3+
###############
4+
dpctl.SyclEvent
5+
###############
6+
7+
.. autoclass:: dpctl.SyclEvent
8+
:members:
9+
:inherited-members:
10+
:undoc-members:
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. _SyclPlatform_api:
2+
3+
##################
4+
dpctl.SyclPlatform
5+
##################
6+
7+
8+
.. autoclass:: dpctl.SyclPlatform
9+
10+
11+
Detail
12+
======
13+
14+
Public methods
15+
--------------
16+
17+
.. autoclassmembers:: dpctl.SyclPlatform
18+
:noindex:
19+
:members:
20+
:undoc-members:
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. _SyclQueue_api:
2+
3+
###############
4+
dpctl.SyclQueue
5+
###############
6+
7+
.. autoclass:: dpctl.SyclQueue
8+
9+
.. rubric:: Attributes:
10+
11+
.. autoautosummary:: dpctl.SyclQueue
12+
:attributes:
13+
14+
.. rubric:: Private methods:
15+
16+
.. autoautosummary:: dpctl.SyclQueue
17+
:private_methods:
18+
19+
.. rubric:: Public methods:
20+
21+
.. autoautosummary:: dpctl.SyclQueue
22+
:methods:
23+
24+
Detail
25+
======
26+
27+
Private methods
28+
---------------
29+
30+
.. autoclassmembers:: dpctl.SyclQueue
31+
:noindex:
32+
:private-members: _get_capsule
33+
:undoc-members:
34+
35+
Public methods
36+
--------------
37+
38+
.. autoclassmembers:: dpctl.SyclQueue
39+
:noindex:
40+
:members:
41+
:undoc-members:

0 commit comments

Comments
 (0)