Skip to content

Commit 98bd9e5

Browse files
authored
Merge pull request #8185 from jepler/document-optional-types-functions
Document optional types & functions
2 parents 4a21e05 + f41e314 commit 98bd9e5

File tree

10 files changed

+126
-24
lines changed

10 files changed

+126
-24
lines changed

docs/rstjinja.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Derived from code on Eric Holscher's blog, found at:
22
# https://www.ericholscher.com/blog/2016/jul/25/integrating-jinja-rst-sphinx/
33

4+
import re
5+
6+
def render_with_jinja(docname, source):
7+
if "shared-bindings/support_matrix" in docname:
8+
return True
9+
if re.search('^\s+.. jinja$', source[0], re.M):
10+
return True
11+
return False
12+
413
def rstjinja(app, docname, source):
514
"""
615
Render our pages as a jinja template for fancy templating goodness.
@@ -9,12 +18,12 @@ def rstjinja(app, docname, source):
918
if app.builder.format not in ("html", "latex"):
1019
return
1120

12-
# we only want our one jinja template to run through this func
13-
if "shared-bindings/support_matrix" not in docname:
21+
# we only want specific files to run through this func
22+
if not render_with_jinja(docname, source):
1423
return
1524

1625
src = rendered = source[0]
17-
print(docname)
26+
print(f"rendering {docname} as jinja templates")
1827

1928
if app.builder.format == "html":
2029
rendered = app.builder.templates.render_string(

docs/shared_bindings_matrix.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,23 @@
6969
"array": "CIRCUITPY_ARRAY",
7070
# always available, so depend on something that's always 1.
7171
"builtins": "CIRCUITPY",
72+
"builtins.pow3": "CIRCUITPY_BUILTINS_POW3",
73+
"busio.SPI": "CIRCUITPY_BUSIO_SPI",
74+
"busio.UART": "CIRCUITPY_BUSIO_UART",
7275
"collections": "CIRCUITPY_COLLECTIONS",
7376
"fontio": "CIRCUITPY_DISPLAYIO",
7477
"io": "CIRCUITPY_IO",
78+
"keypad.KeyMatrix": "CIRCUITPY_KEYPAD_KEYMATRIX",
79+
"keypad.Keys": "CIRCUITPY_KEYPAD_KEYS",
80+
"keypad.ShiftRegisterKeys": "CIRCUITPY_KEYPAD_SHIFTREGISTERKEYS",
81+
"os.getenv": "CIRCUITPY_OS_GETENV",
7582
"select": "MICROPY_PY_USELECT_SELECT",
76-
"terminalio": "CIRCUITPY_DISPLAYIO",
7783
"sys": "CIRCUITPY_SYS",
84+
"terminalio": "CIRCUITPY_DISPLAYIO",
7885
"usb": "CIRCUITPY_USB_HOST",
7986
}
8087

81-
MODULES_NOT_IN_BINDINGS = [
82-
"_asyncio",
83-
"array",
84-
"binascii",
85-
"builtins",
86-
"collections",
87-
"errno",
88-
"json",
89-
"re",
90-
"select",
91-
"sys",
92-
"ulab",
93-
]
88+
MODULES_NOT_IN_BINDINGS = [ "binascii", "errno", "json", "re", "ulab" ]
9489

9590
FROZEN_EXCLUDES = ["examples", "docs", "tests", "utils", "conf.py", "setup.py"]
9691
"""Files and dirs at the root of a frozen directory that should be ignored.
@@ -117,7 +112,7 @@ def get_bindings():
117112
bindings_modules = []
118113
for d in get_circuitpython_root_dir().glob("ports/*/bindings"):
119114
bindings_modules.extend(module.name for module in d.iterdir() if d.is_dir())
120-
return shared_bindings_modules + bindings_modules + MODULES_NOT_IN_BINDINGS
115+
return shared_bindings_modules + bindings_modules + MODULES_NOT_IN_BINDINGS + list(ADDITIONAL_MODULES.keys())
121116

122117

123118
def get_board_mapping():

shared-bindings/busio/SPI.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,22 @@
5252
//| `!MOSI`, `!MISO`. Its up to the client to manage the appropriate
5353
//| select line, often abbreviated `!CS` or `!SS`. (This is common because
5454
//| multiple secondaries can share the `!clock`, `!MOSI` and `!MISO` lines
55-
//| and therefore the hardware.)"""
55+
//| and therefore the hardware.)
56+
//|
57+
//| .. raw:: html
58+
//|
59+
//| <p>
60+
//| <details>
61+
//| <summary>Available on these boards</summary>
62+
//| <ul>
63+
//| {% for board in support_matrix_reverse["busio.SPI"] %}
64+
//| <li> {{ board }}
65+
//| {% endfor %}
66+
//| </ul>
67+
//| </details>
68+
//| </p>
69+
//|
70+
//| """
5671
//|
5772
//| def __init__(
5873
//| self,

shared-bindings/busio/UART.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,22 @@
4444
// #define STREAM_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
4545

4646
//| class UART:
47-
//| """A bidirectional serial protocol"""
47+
//| """A bidirectional serial protocol
48+
//|
49+
//| .. raw:: html
50+
//|
51+
//| <p>
52+
//| <details>
53+
//| <summary>Available on these boards</summary>
54+
//| <ul>
55+
//| {% for board in support_matrix_reverse["busio.UART"] %}
56+
//| <li> {{ board }}
57+
//| {% endfor %}
58+
//| </ul>
59+
//| </details>
60+
//| </p>
61+
//|
62+
//| """
4863
//|
4964
//| def __init__(
5065
//| self,

shared-bindings/busio/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
//|
7878
//| Tutorial for UART:
7979
//| https://learn.adafruit.com/circuitpython-essentials/circuitpython-uart-serial
80+
//|
81+
//| .. jinja
8082
//| """
8183

8284
STATIC const mp_rom_map_elem_t busio_module_globals_table[] = {

shared-bindings/keypad/KeyMatrix.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,22 @@
3535
#include "shared-bindings/util.h"
3636

3737
//| class KeyMatrix:
38-
//| """Manage a 2D matrix of keys with row and column pins."""
38+
//| """Manage a 2D matrix of keys with row and column pins.
39+
//|
40+
//| .. raw:: html
41+
//|
42+
//| <p>
43+
//| <details>
44+
//| <summary>Available on these boards</summary>
45+
//| <ul>
46+
//| {% for board in support_matrix_reverse["keypad.KeyMatrix"] %}
47+
//| <li> {{ board }}
48+
//| {% endfor %}
49+
//| </ul>
50+
//| </details>
51+
//| </p>
52+
//|
53+
//| """
3954
//|
4055
//| def __init__(
4156
//| self,

shared-bindings/keypad/Keys.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,22 @@
3535
#include "shared-bindings/util.h"
3636

3737
//| class Keys:
38-
//| """Manage a set of independent keys."""
38+
//| """Manage a set of independent keys.
39+
//|
40+
//| .. raw:: html
41+
//|
42+
//| <p>
43+
//| <details>
44+
//| <summary>Available on these boards</summary>
45+
//| <ul>
46+
//| {% for board in support_matrix_reverse["keypad.Keys"] %}
47+
//| <li> {{ board }}
48+
//| {% endfor %}
49+
//| </ul>
50+
//| </details>
51+
//| </p>
52+
//|
53+
//| """
3954
//|
4055
//| def __init__(
4156
//| self,

shared-bindings/keypad/ShiftRegisterKeys.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,22 @@
3535
#include "shared-bindings/util.h"
3636

3737
//| class ShiftRegisterKeys:
38-
//| """Manage a set of keys attached to an incoming shift register."""
38+
//| """Manage a set of keys attached to an incoming shift register.
39+
//|
40+
//| .. raw:: html
41+
//|
42+
//| <p>
43+
//| <details>
44+
//| <summary>Available on these boards</summary>
45+
//| <ul>
46+
//| {% for board in support_matrix_reverse["keypad.ShiftRegisterKeys"] %}
47+
//| <li> {{ board }}
48+
//| {% endfor %}
49+
//| </ul>
50+
//| </details>
51+
//| </p>
52+
//|
53+
//| """
3954
//|
4055
//| def __init__(
4156
//| self,

shared-bindings/keypad/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ const mp_obj_property_t keypad_generic_events_obj = {
8989
//|
9090
//| For more information about working with the `keypad` module in CircuitPython,
9191
//| see `this Learn guide <https://learn.adafruit.com/key-pad-matrix-scanning-in-circuitpython>`_.
92+
//|
93+
//| .. jinja
9294
//| """
9395

9496
STATIC mp_rom_map_elem_t keypad_module_globals_table[] = {

shared-bindings/os/__init__.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
//| """functions that an OS normally provides
4242
//|
4343
//| |see_cpython_module| :mod:`cpython:os`.
44+
//|
45+
//| .. jinja
4446
//| """
4547
//|
4648
//| import typing
@@ -88,7 +90,24 @@ MP_DEFINE_CONST_FUN_OBJ_0(os_getcwd_obj, os_getcwd);
8890
//| def getenv(key: str, default: Optional[str] = None) -> Optional[str]:
8991
//| """Get the environment variable value for the given key or return ``default``.
9092
//|
91-
//| This may load values from disk so cache the result instead of calling this often."""
93+
//| This may load values from disk so cache the result instead of calling this often.
94+
//|
95+
//| On boards that do not support ``settings.toml`` reading in the core, this function will raise NotImplementedError.
96+
//|
97+
//| .. raw:: html
98+
//|
99+
//| <p>
100+
//| <details>
101+
//| <summary>Available on these boards</summary>
102+
//| <ul>
103+
//| {% for board in support_matrix_reverse["os.getenv"] %}
104+
//| <li> {{ board }}
105+
//| {% endfor %}
106+
//| </ul>
107+
//| </details>
108+
//| </p>
109+
//|
110+
//| """
92111
//| ...
93112
//|
94113
STATIC mp_obj_t os_getenv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {

0 commit comments

Comments
 (0)