Skip to content

Commit 354edd9

Browse files
authored
Merge pull request #3252 from ciscorn/pyi
Some improvements to the core module docs
2 parents 8f6950e + 56c898d commit 354edd9

File tree

60 files changed

+686
-539
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+686
-539
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ stubs:
245245
@$(PYTHON) tools/extract_pyi.py ports/atmel-samd/bindings $(STUBDIR)
246246
@$(PYTHON) setup.py -q sdist
247247

248+
.PHONY: check-stubs
249+
check-stubs: stubs
250+
MYPYPATH=$(STUBDIR) mypy --strict $(STUBDIR)
251+
248252
update-frozen-libraries:
249253
@echo "Updating all frozen libraries to latest tagged version."
250254
cd frozen; for library in *; do cd $$library; ../../tools/git-checkout-latest-tag.sh; cd ..; done

conf.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#
1818
# SPDX-License-Identifier: MIT
1919

20-
import json
2120
import logging
2221
import os
2322
import re
@@ -26,6 +25,9 @@
2625
import urllib.parse
2726

2827
import recommonmark
28+
from sphinx.transforms import SphinxTransform
29+
from docutils import nodes
30+
from sphinx import addnodes
2931

3032
# If extensions (or modules to document with autodoc) are in another directory,
3133
# add these directories to sys.path here. If the directory is relative to the
@@ -85,6 +87,7 @@
8587
autoapi_add_toctree_entry = False
8688
autoapi_options = ['members', 'undoc-members', 'private-members', 'show-inheritance', 'special-members', 'show-module-summary']
8789
autoapi_template_dir = 'docs/autoapi/templates'
90+
autoapi_python_class_content = "both"
8891
autoapi_python_use_implicit_namespaces = True
8992
autoapi_root = "shared-bindings"
9093

@@ -442,7 +445,38 @@ def generate_redirects(app):
442445
with open(redirected_filename, 'w') as f:
443446
f.write(TEMPLATE % urllib.parse.quote(to_path, '#/'))
444447

448+
449+
class CoreModuleTransform(SphinxTransform):
450+
default_priority = 870
451+
452+
def _convert_first_paragraph_into_title(self):
453+
title = self.document.next_node(nodes.title)
454+
paragraph = self.document.next_node(nodes.paragraph)
455+
if not title or not paragraph:
456+
return
457+
if isinstance(paragraph[0], nodes.paragraph):
458+
paragraph = paragraph[0]
459+
if all(isinstance(child, nodes.Text) for child in paragraph.children):
460+
for child in paragraph.children:
461+
title.append(nodes.Text(" \u2013 "))
462+
title.append(child)
463+
paragraph.parent.remove(paragraph)
464+
465+
def _enable_linking_to_nonclass_targets(self):
466+
for desc in self.document.traverse(addnodes.desc):
467+
for xref in desc.traverse(addnodes.pending_xref):
468+
if xref.attributes.get("reftype") == "class":
469+
xref.attributes.pop("refspecific", None)
470+
471+
def apply(self, **kwargs):
472+
docname = self.env.docname
473+
if docname.startswith(autoapi_root) and docname.endswith("/index"):
474+
self._convert_first_paragraph_into_title()
475+
self._enable_linking_to_nonclass_targets()
476+
477+
445478
def setup(app):
446479
app.add_css_file("customstyle.css")
447480
app.add_config_value('redirects_file', 'redirects', 'env')
448481
app.connect('builder-inited', generate_redirects)
482+
app.add_transform(CoreModuleTransform)

docs/autoapi/templates/python/module.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
{% set visible_subpackages = obj.subpackages|selectattr("display")|list %}
1919
{% if visible_subpackages %}
2020
.. toctree::
21-
:titlesonly:
22-
:maxdepth: 3
21+
:maxdepth: 2
2322

2423
{% for subpackage in visible_subpackages %}
2524
{{ subpackage.short_name }}/index.rst

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
sphinx<3
1+
sphinx<4
22
recommonmark==0.6.0
33
sphinxcontrib-svg2pdfconverter==0.1.0
44
astroid

shared-bindings/_bleio/Adapter.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ const mp_obj_property_t bleio_adapter_name_obj = {
145145
//| .. note: If you set ``anonymous=True``, then a timeout must be specified. If no timeout is
146146
//| specified, then the maximum allowed timeout will be selected automatically.
147147
//|
148-
//| :param buf data: advertising data packet bytes
149-
//| :param buf scan_response: scan response data packet bytes. ``None`` if no scan response is needed.
148+
//| :param ~_typing.ReadableBuffer data: advertising data packet bytes
149+
//| :param ~_typing.ReadableBuffer scan_response: scan response data packet bytes. ``None`` if no scan response is needed.
150150
//| :param bool connectable: If `True` then other devices are allowed to connect to this peripheral.
151151
//| :param bool anonymous: If `True` then this device's MAC address is randomized before advertising.
152152
//| :param int timeout: If set, we will only advertise for this many seconds.
@@ -219,7 +219,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_adapter_stop_advertising_obj, bleio_adapt
219219
//| """Starts a BLE scan and returns an iterator of results. Advertisements and scan responses are
220220
//| filtered and returned separately.
221221
//|
222-
//| :param sequence prefixes: Sequence of byte string prefixes to filter advertising packets
222+
//| :param ~_typing.ReadableBuffer prefixes: Sequence of byte string prefixes to filter advertising packets
223223
//| with. A packet without an advertising structure that matches one of the prefixes is
224224
//| ignored. Format is one byte for length (n) and n bytes of prefix and can be repeated.
225225
//| :param int buffer_size: the maximum number of advertising bytes to buffer.
@@ -334,7 +334,7 @@ const mp_obj_property_t bleio_adapter_connected_obj = {
334334
(mp_obj_t)&mp_const_none_obj },
335335
};
336336

337-
//| connections: tuple
337+
//| connections: Tuple[Connection]
338338
//| """Tuple of active connections including those initiated through
339339
//| :py:meth:`_bleio.Adapter.connect`. (read-only)"""
340340
//|

shared-bindings/_bleio/Address.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
//| """Create a new Address object encapsulating the address value.
4343
//| The value itself can be one of:
4444
//|
45-
//| :param buf address: The address value to encapsulate. A buffer object (bytearray, bytes) of 6 bytes.
45+
//| :param ~_typing.ReadableBuffer address: The address value to encapsulate. A buffer object (bytearray, bytes) of 6 bytes.
4646
//| :param int address_type: one of the integer values: `PUBLIC`, `RANDOM_STATIC`,
4747
//| `RANDOM_PRIVATE_RESOLVABLE`, or `RANDOM_PRIVATE_NON_RESOLVABLE`."""
4848
//| ...
@@ -128,7 +128,7 @@ const mp_obj_property_t bleio_address_type_obj = {
128128
(mp_obj_t)&mp_const_none_obj},
129129
};
130130

131-
//| def __eq__(self, other: Address) -> bool:
131+
//| def __eq__(self, other: object) -> bool:
132132
//| """Two Address objects are equal if their addresses and address types are equal."""
133133
//| ...
134134
//|

shared-bindings/_bleio/Characteristic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
//| is 512, or possibly 510 if ``fixed_length`` is False. The default, 20, is the maximum
6464
//| number of data bytes that fit in a single BLE 4.x ATT packet.
6565
//| :param bool fixed_length: True if the characteristic value is of fixed length.
66-
//| :param buf initial_value: The initial value for this characteristic. If not given, will be
66+
//| :param ~_typing.ReadableBuffer initial_value: The initial value for this characteristic. If not given, will be
6767
//| filled with zeros.
6868
//|
6969
//| :return: the new Characteristic."""

shared-bindings/_bleio/Connection.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_connection_pair_obj, 1, bleio_connection
111111

112112
//| def discover_remote_services(self, service_uuids_whitelist: Optional[Iterable[UUID]] = None) -> Tuple[Service, ...]:
113113
//| """Do BLE discovery for all services or for the given service UUIDS,
114-
//| to find their handles and characteristics, and return the discovered services.
115-
//| `Connection.connected` must be True.
114+
//| to find their handles and characteristics, and return the discovered services.
115+
//| `Connection.connected` must be True.
116116
//|
117117
//| :param iterable service_uuids_whitelist:
118118
//|
119-
//| an iterable of :py:class:~`UUID` objects for the services provided by the peripheral
119+
//| an iterable of :py:class:`UUID` objects for the services provided by the peripheral
120120
//| that you want to use.
121121
//|
122122
//| The peripheral may provide more services, but services not listed are ignored
@@ -126,7 +126,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_connection_pair_obj, 1, bleio_connection
126126
//| slow.
127127
//|
128128
//| If the service UUID is 128-bit, or its characteristic UUID's are 128-bit, you
129-
//| you must have already created a :py:class:~`UUID` object for that UUID in order for the
129+
//| you must have already created a :py:class:`UUID` object for that UUID in order for the
130130
//| service or characteristic to be discovered. Creating the UUID causes the UUID to be
131131
//| registered for use. (This restriction may be lifted in the future.)
132132
//|

shared-bindings/_bleio/Descriptor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
//| as part of remote Characteristics in the remote Services that are discovered."""
4747
//|
4848
//| @classmethod
49-
//| def add_to_characteristic(characteristic: Characteristic, uuid: UUID, *, read_perm: int = Attribute.OPEN, write_perm: int = Attribute.OPEN, max_length = 20, fixed_length: bool = False, initial_value: ReadableBuffer = b'') -> Descriptor:
49+
//| def add_to_characteristic(cls, characteristic: Characteristic, uuid: UUID, *, read_perm: int = Attribute.OPEN, write_perm: int = Attribute.OPEN, max_length: int = 20, fixed_length: bool = False, initial_value: ReadableBuffer = b'') -> Descriptor:
5050
//| """Create a new Descriptor object, and add it to this Service.
5151
//|
5252
//| :param Characteristic characteristic: The characteristic that will hold this descriptor
@@ -61,7 +61,7 @@
6161
//| is 512, or possibly 510 if ``fixed_length`` is False. The default, 20, is the maximum
6262
//| number of data bytes that fit in a single BLE 4.x ATT packet.
6363
//| :param bool fixed_length: True if the descriptor value is of fixed length.
64-
//| :param buf initial_value: The initial value for this descriptor.
64+
//| :param ~_typing.ReadableBuffer initial_value: The initial value for this descriptor.
6565
//|
6666
//| :return: the new Descriptor."""
6767
//| ...

shared-bindings/_bleio/UUID.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
//| temporary 16-bit UUID that can be used in place of the full 128-bit UUID.
4949
//|
5050
//| :param value: The uuid value to encapsulate
51-
//| :type value: int or typing.ByteString"""
51+
//| :type value: int, ~_typing.ReadableBuffer or str"""
5252
//| ...
5353
//|
5454
STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
@@ -248,7 +248,7 @@ STATIC mp_obj_t bleio_uuid_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
248248
}
249249
}
250250

251-
//| def __eq__(self, other: UUID) -> bool:
251+
//| def __eq__(self, other: object) -> bool:
252252
//| """Two UUID objects are equal if their values match and they are both 128-bit or both 16-bit."""
253253
//| ...
254254
//|

shared-bindings/_bleio/__init__.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
#include "shared-bindings/_bleio/Service.h"
4242
#include "shared-bindings/_bleio/UUID.h"
4343

44-
//| """
44+
//| """Bluetooth Low Energy (BLE) communication
45+
//|
4546
//| The `_bleio` module provides necessary low-level functionality for communicating
4647
//| using Bluetooth Low Energy (BLE). The '_' prefix indicates this module is meant
4748
//| for internal use by libraries but not by the end user. Its API may change incompatibly
@@ -50,12 +51,12 @@
5051
//| `adafruit_ble <https://circuitpython.readthedocs.io/projects/ble/en/latest/>`_
5152
//| CircuitPython library instead, which builds on `_bleio`, and
5253
//| provides higher-level convenience functionality, including predefined beacons, clients,
53-
//| servers.
54-
//|
55-
//| .. attribute:: adapter
54+
//| servers."""
5655
//|
57-
//| BLE Adapter used to manage device discovery and connections.
58-
//| This object is the sole instance of `_bleio.Adapter`."""
56+
57+
//| adapter: Adapter
58+
//| """BLE Adapter used to manage device discovery and connections.
59+
//| This object is the sole instance of `_bleio.Adapter`."""
5960
//|
6061

6162
//| class BluetoothError(Exception):

0 commit comments

Comments
 (0)