Skip to content

Commit 0d8bca9

Browse files
authored
Merge pull request #2810 from dherrada/master
Pyi integration
2 parents bd78ab3 + 8ac3e79 commit 0d8bca9

File tree

157 files changed

+4686
-5574
lines changed

Some content is hidden

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

157 files changed

+4686
-5574
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
run: |
3535
sudo apt-get install -y eatmydata
3636
sudo eatmydata apt-get install -y gettext librsvg2-bin mingw-w64
37-
pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinxcontrib-svg2pdfconverter polib pyyaml
37+
pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinx-autoapi sphinxcontrib-svg2pdfconverter polib pyyaml astroid
3838
- name: Versions
3939
run: |
4040
gcc --version
@@ -64,6 +64,8 @@ jobs:
6464
- name: mpy Tests
6565
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -j1 --via-mpy -d basics float
6666
working-directory: tests
67+
- name: Stubs
68+
run: make stubs -j2
6769
- name: Docs
6870
run: sphinx-build -E -W -b html . _build/html
6971
- name: Translations

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
############
1515
dist/
1616
*.egg-info
17+
.eggs
1718

1819
# Logs and Databases
1920
######################
@@ -51,6 +52,7 @@ _build
5152
# Generated rst files
5253
######################
5354
genrst/
55+
/autoapi/
5456

5557
# ctags and similar
5658
###################

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ help:
6767

6868
clean:
6969
rm -rf $(BUILDDIR)/*
70+
rm -rf autoapi
7071
rm -rf $(STUBDIR) $(DISTDIR) *.egg-info
7172

72-
html:
73+
html: stubs
7374
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
7475
@echo
7576
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
@@ -213,8 +214,10 @@ check-translate: locale/circuitpython.pot $(wildcard locale/*.po)
213214
$(PYTHON) tools/check_translations.py $^
214215

215216
stubs:
216-
rst2pyi $(VALIDATE) shared-bindings/ $(STUBDIR)
217-
python setup.py sdist
217+
@mkdir -p circuitpython-stubs
218+
@$(PYTHON) tools/extract_pyi.py shared-bindings/ $(STUBDIR)
219+
@$(PYTHON) tools/extract_pyi.py ports/atmel-samd/bindings $(STUBDIR)
220+
@$(PYTHON) setup.py -q sdist
218221

219222
update-frozen-libraries:
220223
@echo "Updating all frozen libraries to latest tagged version."

conf.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
'sphinx.ext.todo',
5656
'sphinx.ext.coverage',
5757
'rstjinja',
58-
'c2rst',
5958
'recommonmark',
6059
]
6160

@@ -66,9 +65,18 @@
6665
source_suffix = {
6766
'.rst': 'restructuredtext',
6867
'.md': 'markdown',
69-
'.c': ''
7068
}
7169

70+
extensions.append('autoapi.extension')
71+
72+
autoapi_type = 'python'
73+
# Uncomment this if debugging autoapi
74+
autoapi_keep_files = True
75+
autoapi_dirs = [os.path.join('circuitpython-stubs', x) for x in os.listdir('circuitpython-stubs')]
76+
autoapi_add_toctree_entry = False
77+
autoapi_options = ['members', 'undoc-members', 'private-members', 'show-inheritance', 'special-members', 'show-module-summary']
78+
autoapi_template_dir = 'docs/autoapi/templates'
79+
autoapi_python_use_implicit_namespaces = True
7280

7381
# The encoding of source files.
7482
#source_encoding = 'utf-8-sig'
@@ -78,7 +86,7 @@
7886

7987
# General information about the project.
8088
project = 'Adafruit CircuitPython'
81-
copyright = '2014-2018, MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)'
89+
copyright = '2014-2020, MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)'
8290

8391
# These are overwritten on ReadTheDocs.
8492
# The version info for the project you're documenting, acts as replacement for
@@ -105,6 +113,7 @@
105113
".git",
106114
".venv",
107115
".direnv",
116+
"docs/autoapi",
108117
"docs/README.md",
109118
"drivers",
110119
"examples",
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{% if not obj.display %}
2+
:orphan:
3+
4+
{% endif %}
5+
:mod:`{{ obj.name }}`
6+
======={{ "=" * obj.name|length }}
7+
8+
.. py:module:: {{ obj.name }}
9+
10+
{% if obj.docstring %}
11+
.. autoapi-nested-parse::
12+
13+
{{ obj.docstring|prepare_docstring|indent(3) }}
14+
15+
{% endif %}
16+
17+
{% block subpackages %}
18+
{% set visible_subpackages = obj.subpackages|selectattr("display")|list %}
19+
{% if visible_subpackages %}
20+
.. toctree::
21+
:titlesonly:
22+
:maxdepth: 3
23+
24+
{% for subpackage in visible_subpackages %}
25+
{{ subpackage.short_name }}/index.rst
26+
{% endfor %}
27+
28+
29+
{% endif %}
30+
{% endblock %}
31+
{% block submodules %}
32+
{% set visible_submodules = obj.submodules|selectattr("display")|list %}
33+
{% if visible_submodules %}
34+
35+
.. toctree::
36+
:titlesonly:
37+
:maxdepth: 1
38+
39+
{% for submodule in visible_submodules %}
40+
{{ submodule.short_name }}/index.rst
41+
{% endfor %}
42+
43+
44+
{% endif %}
45+
{% endblock %}
46+
{% block content %}
47+
{% if obj.all is not none %}
48+
{% set visible_children = obj.children|selectattr("short_name", "in", obj.all)|list %}
49+
{% elif obj.type is equalto("package") %}
50+
{% set visible_children = obj.children|selectattr("display")|list %}
51+
{% else %}
52+
{% set visible_children = obj.children|selectattr("display")|rejectattr("imported")|list %}
53+
{% endif %}
54+
{% if visible_children %}
55+
56+
{% set visible_classes = visible_children|selectattr("type", "equalto", "class")|list %}
57+
{% set visible_functions = visible_children|selectattr("type", "equalto", "function")|list %}
58+
{% if "show-module-summary" in autoapi_options and (visible_classes or visible_functions) %}
59+
{% block classes %}
60+
{% if visible_classes %}
61+
Classes
62+
~~~~~~~
63+
64+
.. autoapisummary::
65+
66+
{% for klass in visible_classes %}
67+
{{ klass.id }}
68+
{% endfor %}
69+
70+
71+
{% endif %}
72+
{% endblock %}
73+
74+
{% block functions %}
75+
{% if visible_functions %}
76+
Functions
77+
~~~~~~~~~
78+
79+
.. autoapisummary::
80+
81+
{% for function in visible_functions %}
82+
{{ function.id }}
83+
{% endfor %}
84+
85+
86+
{% endif %}
87+
{% endblock %}
88+
{% endif %}
89+
{% for obj_item in visible_children %}
90+
{{ obj_item.rendered|indent(0) }}
91+
{% endfor %}
92+
{% endif %}
93+
{% endblock %}

docs/c2rst.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

ports/atmel-samd/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ Port Specific modules
2121
---------------------
2222

2323
.. toctree::
24-
bindings/samd/__init__
24+
../../autoapi/samd/index

ports/atmel-samd/bindings/samd/Clock.c

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,12 @@
3030
#include "py/objproperty.h"
3131
#include "py/runtime.h"
3232

33-
//| .. currentmodule:: samd
33+
//| import typing
34+
//| class Clock:
35+
//| """Identifies a clock on the microcontroller.
3436
//|
35-
//| :class:`Clock` --- Clock reference
36-
//| ------------------------------------------
37-
//|
38-
//| Identifies a clock on the microcontroller.
39-
//|
40-
//| .. class:: Clock
41-
//|
42-
//| Identifies a clock on the microcontroller. They are fixed by the
43-
//| hardware so they cannot be constructed on demand. Instead, use
44-
//| `samd.clock` to reference the desired clock.
37+
//| They are fixed by the hardware so they cannot be constructed on demand. Instead, use
38+
//| ``samd.clock`` to reference the desired clock."""
4539
//|
4640

4741
STATIC void samd_clock_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
@@ -50,9 +44,8 @@ STATIC void samd_clock_print(const mp_print_t *print, mp_obj_t self_in, mp_print
5044
mp_printf(print, "%q.%q.%q", MP_QSTR_samd, MP_QSTR_clock, self->name);
5145
}
5246

53-
//| .. attribute:: enabled
54-
//|
55-
//| Is the clock enabled? (read-only)
47+
//| enabled: bool = ...
48+
//| """Is the clock enabled? (read-only)"""
5649
//|
5750
STATIC mp_obj_t samd_clock_get_enabled(mp_obj_t self_in) {
5851
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -69,9 +62,8 @@ const mp_obj_property_t samd_clock_enabled_obj = {
6962
},
7063
};
7164

72-
//| .. attribute:: parent
73-
//|
74-
//| Clock parent. (read-only)
65+
//| parent: typing.Union(Clock | None) = ...
66+
//| """Clock parent. (read-only)"""
7567
//|
7668
STATIC mp_obj_t samd_clock_get_parent(mp_obj_t self_in) {
7769
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -98,9 +90,8 @@ const mp_obj_property_t samd_clock_parent_obj = {
9890
},
9991
};
10092

101-
//| .. attribute:: frequency
102-
//|
103-
//| Clock frequency. (read-only)
93+
//| frequency: int = ...
94+
//| """Clock frequency in Herz. (read-only)"""
10495
//|
10596
STATIC mp_obj_t samd_clock_get_frequency(mp_obj_t self_in) {
10697
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -117,9 +108,8 @@ const mp_obj_property_t samd_clock_frequency_obj = {
117108
},
118109
};
119110

120-
//| .. attribute:: calibration
121-
//|
122-
//| Clock calibration. Not all clocks can be calibrated.
111+
//| calibration: int = ...
112+
//| """Clock calibration. Not all clocks can be calibrated."""
123113
//|
124114
STATIC mp_obj_t samd_clock_get_calibration(mp_obj_t self_in) {
125115
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);

ports/atmel-samd/bindings/samd/__init__.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,16 @@
3030

3131
#include "bindings/samd/Clock.h"
3232

33-
//| :mod:`samd` --- SAMD implementation settings
34-
//| =================================================
35-
//|
36-
//| .. module:: samd
37-
//| :synopsis: SAMD implementation settings
38-
//| :platform: SAMD21
39-
//|
40-
//| Libraries
41-
//|
42-
//| .. toctree::
43-
//| :maxdepth: 3
44-
//|
45-
//| Clock
46-
//|
33+
//| """SAMD implementation settings"""
4734

48-
//| :mod:`samd.clock` --- samd clock names
35+
//| """:mod:`samd.clock` --- samd clock names
4936
//| --------------------------------------------------------
5037
//|
5138
//| .. module:: samd.clock
5239
//| :synopsis: samd clock names
5340
//| :platform: SAMD21
5441
//|
55-
//| References to clocks as named by the microcontroller
42+
//| References to clocks as named by the microcontroller"""
5643
//|
5744
const mp_obj_module_t samd_clock_module = {
5845
.base = { &mp_type_module },

py/circuitpy_defns.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ $(filter $(SRC_PATTERNS), \
323323
)
324324

325325
SRC_BINDINGS_ENUMS += \
326-
help.c \
327326
util.c
328327

329328
SRC_SHARED_MODULE_ALL = \

setup.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
from datetime import datetime
22
from setuptools import setup
33
from pathlib import Path
4+
import subprocess
5+
import re
46

57
stub_root = Path("circuitpython-stubs")
68
stubs = [p.relative_to(stub_root).as_posix() for p in stub_root.glob("*.pyi")]
79

8-
now = datetime.utcnow()
9-
version = now.strftime("%Y.%m.%d")
10+
git_out = subprocess.check_output(["git", "describe", "--tags"])
11+
version = git_out.strip().decode("utf-8")
12+
13+
# Detect a development build and mutate it to be valid semver and valid python version.
14+
pieces = version.split("-")
15+
if len(pieces) > 2:
16+
# Merge the commit portion onto the commit count since the tag.
17+
pieces[-2] += "+" + pieces[-1]
18+
pieces.pop()
19+
# Merge the commit count and build to the pre-release identifier.
20+
pieces[-2] += ".dev." + pieces[-1]
21+
pieces.pop()
22+
version = "-".join(pieces)
1023

1124
setup(
1225
name="circuitpython-stubs",
1326
description="PEP 561 type stubs for CircuitPython",
1427
url="https://github.com/adafruit/circuitpython",
1528
maintainer="CircuitPythonistas",
29+
maintainer_email="[email protected]",
1630
author_email="[email protected]",
1731
version=version,
1832
license="MIT",

0 commit comments

Comments
 (0)