Skip to content

Commit b7a15ed

Browse files
author
Diptorup Deb
authored
Add a special case to document device factory functions. (#721)
- _sycl_device_factory consists of device selection and other functions. Added a check to list all device selections functions as a group and all other functions as "Others".
1 parent 6bf0dbe commit b7a15ed

File tree

1 file changed

+48
-10
lines changed

1 file changed

+48
-10
lines changed

docs/generate_rst.py

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
# Dictionary mapping internal module names to a readable string. so that we
4040
# can use the module name to logically group functions.
4141
function_groups = {
42-
"dpctl._sycl_device_factory": "Device Selection Functions",
4342
"dpctl._device_selection": "Device Selection Functions",
4443
"dpctl._sycl_queue_manager": "Queue Management Functions",
4544
"dpctl.tensor._ctors": "Array Construction",
@@ -237,13 +236,26 @@ def _group_functions(mod):
237236
obj,
238237
]
239238
else:
240-
try:
241-
flist = groups["Other Functions"]
242-
flist.append(obj)
243-
except KeyError:
244-
groups["Other Functions"] = [
245-
obj,
246-
]
239+
# Special case for _sycl_device_factory
240+
if (
241+
obj.__module__ == "dpctl._sycl_device_factory"
242+
and "select_" in obj.__name__
243+
):
244+
try:
245+
flist = groups["Device Selection Functions"]
246+
flist.append(obj)
247+
except KeyError:
248+
groups["Device Selection Functions"] = [
249+
obj,
250+
]
251+
else:
252+
try:
253+
flist = groups["Other Functions"]
254+
flist.append(obj)
255+
except KeyError:
256+
groups["Other Functions"] = [
257+
obj,
258+
]
247259
return groups
248260

249261

@@ -455,6 +467,8 @@ def _write_classes_summary_table(o, mod):
455467
classes.append(cls)
456468
class_names.append(mem_tup[0])
457469
if classes:
470+
_write_line(o, ".. _" + mod.__name__.lower() + "_classes:")
471+
_write_empty_line(o)
458472
_write_underlined(o, "Classes", "-")
459473
_write_empty_line(o)
460474
_write_hidden_toc(output, class_names)
@@ -511,11 +525,35 @@ def _write_functions_summary_table(o, mod, fnobj_list):
511525
_write_empty_line(o)
512526

513527
def _write_function_groups_summary(o, mod, groups):
528+
514529
for group in groups:
530+
if group != "Other Functions":
531+
_write_line(
532+
o,
533+
".. _"
534+
+ mod.__name__.lower()
535+
+ "_"
536+
+ group.lower().replace(" ", "_")
537+
+ ":",
538+
)
539+
_write_empty_line(o)
540+
_write_underlined(o, group, "-")
541+
_write_empty_line(o)
542+
_write_functions_summary_table(o, mod, groups[group])
543+
544+
# We want to write "Other Functions" in the end always
545+
try:
546+
other_fns = groups["Other Functions"]
547+
_write_line(
548+
o,
549+
".. _" + mod.__name__.lower() + "_other_functions:",
550+
)
515551
_write_empty_line(o)
516-
_write_underlined(o, group, "-")
552+
_write_underlined(o, "Other Functions", "-")
517553
_write_empty_line(o)
518-
_write_functions_summary_table(o, mod, groups[group])
554+
_write_functions_summary_table(o, mod, other_fns)
555+
except KeyError:
556+
pass
519557

520558
mod = _get_module(module)
521559

0 commit comments

Comments
 (0)