Skip to content

Pyi integration #2810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 53 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
a18b991
Added pyi to SPI.c
evaherrada Apr 22, 2020
855c203
Reogranized pyi in spi.c
evaherrada Apr 23, 2020
55bdee6
Reorganized pyi again
evaherrada Apr 23, 2020
28430a9
Added inline pyi to I2C.c
evaherrada Apr 25, 2020
7070fe1
Added inline pyi to UART.c
evaherrada Apr 25, 2020
e787427
Fixed empty lines
evaherrada Apr 25, 2020
27e085e
Added pyi to OneWire.c
evaherrada Apr 25, 2020
8344fce
Added inline pyi to analogio
evaherrada Apr 27, 2020
e96235d
Added inline pyi to audiobusio
evaherrada Apr 27, 2020
088b5b1
Added inline pyi to audiocore
evaherrada Apr 27, 2020
1363e6e
Added inline pyi to audiocore
evaherrada Apr 27, 2020
8330471
Added inline pyi to audiomixer
evaherrada Apr 27, 2020
829da5c
Added inline pyi to audiomp3
evaherrada Apr 27, 2020
4671348
Add verification script
tannewt Apr 27, 2020
78ea3ff
Merge pull request #1 from tannewt/switch_to_inline_pyi
evaherrada Apr 27, 2020
724dcda
Fixed whitespace in busio
evaherrada Apr 28, 2020
c3897d0
Fixed whitespace in analogio
evaherrada Apr 28, 2020
aacca61
Fixed whitespace on audiocore
evaherrada Apr 28, 2020
c7b721f
Fixed some more whitespace
evaherrada Apr 28, 2020
8c77252
Better handle //| and do __init__.c first.
tannewt Apr 29, 2020
8cdc67a
Merge pull request #2 from tannewt/improve_verification
evaherrada Apr 29, 2020
93d1e53
Hopefully fixed whitespace issues
evaherrada Apr 29, 2020
deccdcc
Did the same for the rest of busio
evaherrada Apr 29, 2020
093461e
Fixed indentation
evaherrada Apr 29, 2020
a2a32fe
Added newlines after every ellipsis
evaherrada Apr 29, 2020
7ff9b9b
Did first 3
evaherrada Apr 29, 2020
d65e851
Did audioio, audiomixer, audiomp3
evaherrada Apr 30, 2020
0e465e6
Did audiopwmio, bitbangio, and _bleio
evaherrada May 1, 2020
2ebe303
Did board, digitalio, displayio
evaherrada May 7, 2020
a3d5adb
Did _eve, fontio, framebufferio, and frequencyio
evaherrada May 7, 2020
4f33a20
Added gamepad, gamepadshift, and i2cslave
evaherrada May 7, 2020
e31e9ee
Did math, microcontroller, and multiterminal
evaherrada May 7, 2020
d750096
Did neopixel, network, nvm
evaherrada May 7, 2020
09530e5
Did os, _pixelbuf, _pew
evaherrada May 8, 2020
838b6c5
Did ps2io, pulseio, random
evaherrada May 11, 2020
c7a9d49
Did rgbmatrix, rotaryio, and RTC
evaherrada May 11, 2020
603df58
Did stage, socket, storage
evaherrada May 11, 2020
991045b
Did struct, supervisor, terminalio
evaherrada May 12, 2020
e458954
Did time, touchio, uheap
evaherrada May 12, 2020
6490137
Did usb_hid, usb_midi, ustack, wiznet
evaherrada May 12, 2020
c534a87
Merge branch 'master' into master
evaherrada May 12, 2020
4e8de3c
Swap sphinx to autoapi and the inline stubs
tannewt May 13, 2020
c816cfe
Build stubs before docs
tannewt May 13, 2020
cde6651
Merge remote-tracking branch 'adafruit/master' into improve_verification
tannewt May 13, 2020
4e646ee
Move vectorio to stubs
tannewt May 13, 2020
2efe17b
Don't build in empty help.c
tannewt May 13, 2020
7546d47
Merge remote-tracking branch 'adafruit/master' into improve_verification
tannewt May 13, 2020
3ffa560
Update countio to python stub docs
tannewt May 13, 2020
794d5f5
Correct version numbering
tannewt May 13, 2020
b477c48
Fixed minor indentation issue
evaherrada May 14, 2020
afc84c2
Fix ulab, math and template.
tannewt May 14, 2020
15c2d16
Fix help doc
tannewt May 14, 2020
8ac3e79
Remove debug prints
tannewt May 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: |
sudo apt-get install -y eatmydata
sudo eatmydata apt-get install -y gettext librsvg2-bin mingw-w64
pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinxcontrib-svg2pdfconverter polib pyyaml
pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinx-autoapi sphinxcontrib-svg2pdfconverter polib pyyaml astroid
- name: Versions
run: |
gcc --version
Expand Down Expand Up @@ -64,6 +64,8 @@ jobs:
- name: mpy Tests
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -j1 --via-mpy -d basics float
working-directory: tests
- name: Stubs
run: make stubs -j2
- name: Docs
run: sphinx-build -E -W -b html . _build/html
- name: Translations
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
############
dist/
*.egg-info
.eggs

# Logs and Databases
######################
Expand Down Expand Up @@ -51,6 +52,7 @@ _build
# Generated rst files
######################
genrst/
/autoapi/

# ctags and similar
###################
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ help:

clean:
rm -rf $(BUILDDIR)/*
rm -rf autoapi
rm -rf $(STUBDIR) $(DISTDIR) *.egg-info

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

stubs:
rst2pyi $(VALIDATE) shared-bindings/ $(STUBDIR)
python setup.py sdist
@mkdir -p circuitpython-stubs
@$(PYTHON) tools/extract_pyi.py shared-bindings/ $(STUBDIR)
@$(PYTHON) tools/extract_pyi.py ports/atmel-samd/bindings $(STUBDIR)
@$(PYTHON) setup.py -q sdist

update-frozen-libraries:
@echo "Updating all frozen libraries to latest tagged version."
Expand Down
15 changes: 12 additions & 3 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
'sphinx.ext.todo',
'sphinx.ext.coverage',
'rstjinja',
'c2rst',
'recommonmark',
]

Expand All @@ -66,9 +65,18 @@
source_suffix = {
'.rst': 'restructuredtext',
'.md': 'markdown',
'.c': ''
}

extensions.append('autoapi.extension')

autoapi_type = 'python'
# Uncomment this if debugging autoapi
autoapi_keep_files = True
autoapi_dirs = [os.path.join('circuitpython-stubs', x) for x in os.listdir('circuitpython-stubs')]
autoapi_add_toctree_entry = False
autoapi_options = ['members', 'undoc-members', 'private-members', 'show-inheritance', 'special-members', 'show-module-summary']
autoapi_template_dir = 'docs/autoapi/templates'
autoapi_python_use_implicit_namespaces = True

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

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

# These are overwritten on ReadTheDocs.
# The version info for the project you're documenting, acts as replacement for
Expand All @@ -105,6 +113,7 @@
".git",
".venv",
".direnv",
"docs/autoapi",
"docs/README.md",
"drivers",
"examples",
Expand Down
93 changes: 93 additions & 0 deletions docs/autoapi/templates/python/module.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{% if not obj.display %}
:orphan:

{% endif %}
:mod:`{{ obj.name }}`
======={{ "=" * obj.name|length }}

.. py:module:: {{ obj.name }}

{% if obj.docstring %}
.. autoapi-nested-parse::

{{ obj.docstring|prepare_docstring|indent(3) }}

{% endif %}

{% block subpackages %}
{% set visible_subpackages = obj.subpackages|selectattr("display")|list %}
{% if visible_subpackages %}
.. toctree::
:titlesonly:
:maxdepth: 3

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


{% endif %}
{% endblock %}
{% block submodules %}
{% set visible_submodules = obj.submodules|selectattr("display")|list %}
{% if visible_submodules %}

.. toctree::
:titlesonly:
:maxdepth: 1

{% for submodule in visible_submodules %}
{{ submodule.short_name }}/index.rst
{% endfor %}


{% endif %}
{% endblock %}
{% block content %}
{% if obj.all is not none %}
{% set visible_children = obj.children|selectattr("short_name", "in", obj.all)|list %}
{% elif obj.type is equalto("package") %}
{% set visible_children = obj.children|selectattr("display")|list %}
{% else %}
{% set visible_children = obj.children|selectattr("display")|rejectattr("imported")|list %}
{% endif %}
{% if visible_children %}

{% set visible_classes = visible_children|selectattr("type", "equalto", "class")|list %}
{% set visible_functions = visible_children|selectattr("type", "equalto", "function")|list %}
{% if "show-module-summary" in autoapi_options and (visible_classes or visible_functions) %}
{% block classes %}
{% if visible_classes %}
Classes
~~~~~~~

.. autoapisummary::

{% for klass in visible_classes %}
{{ klass.id }}
{% endfor %}


{% endif %}
{% endblock %}

{% block functions %}
{% if visible_functions %}
Functions
~~~~~~~~~

.. autoapisummary::

{% for function in visible_functions %}
{{ function.id }}
{% endfor %}


{% endif %}
{% endblock %}
{% endif %}
{% for obj_item in visible_children %}
{{ obj_item.rendered|indent(0) }}
{% endfor %}
{% endif %}
{% endblock %}
31 changes: 0 additions & 31 deletions docs/c2rst.py

This file was deleted.

2 changes: 1 addition & 1 deletion ports/atmel-samd/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Port Specific modules
---------------------

.. toctree::
bindings/samd/__init__
../../autoapi/samd/index
36 changes: 13 additions & 23 deletions ports/atmel-samd/bindings/samd/Clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,12 @@
#include "py/objproperty.h"
#include "py/runtime.h"

//| .. currentmodule:: samd
//| import typing
//| class Clock:
//| """Identifies a clock on the microcontroller.
//|
//| :class:`Clock` --- Clock reference
//| ------------------------------------------
//|
//| Identifies a clock on the microcontroller.
//|
//| .. class:: Clock
//|
//| Identifies a clock on the microcontroller. They are fixed by the
//| hardware so they cannot be constructed on demand. Instead, use
//| `samd.clock` to reference the desired clock.
//| They are fixed by the hardware so they cannot be constructed on demand. Instead, use
//| ``samd.clock`` to reference the desired clock."""
//|

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

//| .. attribute:: enabled
//|
//| Is the clock enabled? (read-only)
//| enabled: bool = ...
//| """Is the clock enabled? (read-only)"""
//|
STATIC mp_obj_t samd_clock_get_enabled(mp_obj_t self_in) {
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
Expand All @@ -69,9 +62,8 @@ const mp_obj_property_t samd_clock_enabled_obj = {
},
};

//| .. attribute:: parent
//|
//| Clock parent. (read-only)
//| parent: typing.Union(Clock | None) = ...
//| """Clock parent. (read-only)"""
//|
STATIC mp_obj_t samd_clock_get_parent(mp_obj_t self_in) {
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
Expand All @@ -98,9 +90,8 @@ const mp_obj_property_t samd_clock_parent_obj = {
},
};

//| .. attribute:: frequency
//|
//| Clock frequency. (read-only)
//| frequency: int = ...
//| """Clock frequency in Herz. (read-only)"""
//|
STATIC mp_obj_t samd_clock_get_frequency(mp_obj_t self_in) {
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
Expand All @@ -117,9 +108,8 @@ const mp_obj_property_t samd_clock_frequency_obj = {
},
};

//| .. attribute:: calibration
//|
//| Clock calibration. Not all clocks can be calibrated.
//| calibration: int = ...
//| """Clock calibration. Not all clocks can be calibrated."""
//|
STATIC mp_obj_t samd_clock_get_calibration(mp_obj_t self_in) {
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
Expand Down
19 changes: 3 additions & 16 deletions ports/atmel-samd/bindings/samd/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,16 @@

#include "bindings/samd/Clock.h"

//| :mod:`samd` --- SAMD implementation settings
//| =================================================
//|
//| .. module:: samd
//| :synopsis: SAMD implementation settings
//| :platform: SAMD21
//|
//| Libraries
//|
//| .. toctree::
//| :maxdepth: 3
//|
//| Clock
//|
//| """SAMD implementation settings"""

//| :mod:`samd.clock` --- samd clock names
//| """:mod:`samd.clock` --- samd clock names
//| --------------------------------------------------------
//|
//| .. module:: samd.clock
//| :synopsis: samd clock names
//| :platform: SAMD21
//|
//| References to clocks as named by the microcontroller
//| References to clocks as named by the microcontroller"""
//|
const mp_obj_module_t samd_clock_module = {
.base = { &mp_type_module },
Expand Down
1 change: 0 additions & 1 deletion py/circuitpy_defns.mk
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ $(filter $(SRC_PATTERNS), \
)

SRC_BINDINGS_ENUMS += \
help.c \
util.c

SRC_SHARED_MODULE_ALL = \
Expand Down
18 changes: 16 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
from datetime import datetime
from setuptools import setup
from pathlib import Path
import subprocess
import re

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

now = datetime.utcnow()
version = now.strftime("%Y.%m.%d")
git_out = subprocess.check_output(["git", "describe", "--tags"])
version = git_out.strip().decode("utf-8")

# Detect a development build and mutate it to be valid semver and valid python version.
pieces = version.split("-")
if len(pieces) > 2:
# Merge the commit portion onto the commit count since the tag.
pieces[-2] += "+" + pieces[-1]
pieces.pop()
# Merge the commit count and build to the pre-release identifier.
pieces[-2] += ".dev." + pieces[-1]
pieces.pop()
version = "-".join(pieces)

setup(
name="circuitpython-stubs",
description="PEP 561 type stubs for CircuitPython",
url="https://github.com/adafruit/circuitpython",
maintainer="CircuitPythonistas",
maintainer_email="[email protected]",
author_email="[email protected]",
version=version,
license="MIT",
Expand Down
Loading