Skip to content

Commit f51ca53

Browse files
committed
refine stubs-building procedure
* so that excess files are not included in sdist, perform build down in circuitpython-stubs * This means we need to * Remove the need-pypi check * Copy a setup.py, README, and MANIFEST.in into the stubs build location * Revamp how the overall `mypy --strict` check lists its inputs * Add a new test that actually installing the stubs lets us do type checking (tools/test-stubs.sh) * Add a missing return type to a __init__ function (why was this not an error under `mypy --strict`, I wonder)
1 parent 47a6b13 commit f51ca53

File tree

8 files changed

+277
-20
lines changed

8 files changed

+277
-20
lines changed

Diff for: .github/workflows/build.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ jobs:
4343
run: |
4444
gcc --version
4545
python3 --version
46-
- name: Check For setup.py
47-
id: need-pypi
48-
run: |
49-
echo ::set-output name=setup-py::$( find . -wholename './setup.py' )
5046
- name: New boards check
5147
run: python3 -u ci_new_boards_check.py
5248
working-directory: tools
@@ -59,7 +55,6 @@ jobs:
5955
name: stubs
6056
path: circuitpython-stubs*
6157
- name: Install pypi dependencies
62-
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
6358
run: |
6459
python -m pip install --upgrade pip
6560
pip install setuptools wheel twine
@@ -138,8 +133,7 @@ jobs:
138133
TWINE_PASSWORD: ${{ secrets.pypi_password }}
139134
run: |
140135
echo "Uploading dev release to PyPi"
141-
python setup.py sdist
142-
twine upload dist/*
136+
twine upload circuitpython-stubs/dist/*
143137
144138
mpy-cross-mac:
145139
runs-on: macos-10.15

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ dist/
3333
build/
3434
bin/
3535
circuitpython-stubs/
36+
test-stubs/
3637
build-*/
3738

3839
# Test failure outputs

Diff for: MANIFEST.in-stubs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
recursive-include . *.pyi

Diff for: Makefile

+9-3
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,23 @@ check-translate:
251251
find $(TRANSLATE_SOURCES) -type d \( $(TRANSLATE_SOURCES_EXC) \) -prune -o -type f \( -iname "*.c" -o -iname "*.h" \) -print | (LC_ALL=C sort) | xgettext -f- -L C -s --add-location=file --keyword=translate --keyword=MP_ERROR_TEXT -o circuitpython.pot.tmp -p locale
252252
$(PYTHON) tools/check_translations.py locale/circuitpython.pot.tmp locale/circuitpython.pot; status=$$?; rm -f locale/circuitpython.pot.tmp; exit $$status
253253

254+
.PHONY: stubs
254255
stubs:
255-
@mkdir -p circuitpython-stubs
256+
@rm -rf circuitpython-stubs
257+
@mkdir circuitpython-stubs
256258
@$(PYTHON) tools/extract_pyi.py shared-bindings/ $(STUBDIR)
257259
@$(PYTHON) tools/extract_pyi.py extmod/ulab/code/ $(STUBDIR)/ulab
258260
@$(PYTHON) tools/extract_pyi.py ports/atmel-samd/bindings $(STUBDIR)
259261
@$(PYTHON) tools/extract_pyi.py ports/raspberrypi/bindings $(STUBDIR)
260-
@$(PYTHON) setup.py -q sdist
262+
@cp setup.py-stubs circuitpython-stubs/setup.py
263+
@cp README.rst-stubs circuitpython-stubs/README.rst
264+
@cp MANIFEST.in-stubs circuitpython-stubs/MANIFEST.in
265+
@(cd circuitpython-stubs && $(PYTHON) setup.py -q sdist)
261266

262267
.PHONY: check-stubs
263268
check-stubs: stubs
264-
MYPYPATH=$(STUBDIR) mypy --strict $(STUBDIR)
269+
@(cd $(STUBDIR) && set -- */__init__.pyi && mypy --strict "$${@%/*}")
270+
@tools/test-stubs.sh
265271

266272
update-frozen-libraries:
267273
@echo "Updating all frozen libraries to latest tagged version."

Diff for: README.rst-stubs

+241
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
CircuitPython
2+
=============
3+
4+
.. image:: https://s3.amazonaws.com/adafruit-circuit-python/CircuitPython_Repo_header_logo.png
5+
6+
|Build Status| |Doc Status| |License| |Discord| |Weblate|
7+
8+
`circuitpython.org <https://circuitpython.org>`__ \| `Get CircuitPython <#get-circuitpython>`__ \|
9+
`Documentation <#documentation>`__ \| `Contributing <#contributing>`__ \|
10+
`Branding <#branding>`__ \| `Differences from Micropython <#differences-from-micropython>`__ \|
11+
`Project Structure <#project-structure>`__
12+
13+
**CircuitPython** is a *beginner friendly*, open source version of Python for tiny, inexpensive
14+
computers called microcontrollers. Microcontrollers are the brains of many electronics including a
15+
wide variety of development boards used to build hobby projects and prototypes. CircuitPython in
16+
electronics is one of the best ways to learn to code because it connects code to reality. Simply
17+
install CircuitPython on a supported board via drag and drop and then edit a ``code.py`` file on
18+
the CIRCUITPY drive. The code will automatically reload. No software installs are needed besides a
19+
text editor (we recommend `Mu <https://codewith.mu/>`_ for beginners.)
20+
21+
CircuitPython features unified Python core APIs and a growing list of 150+ device libraries and
22+
drivers that work with it. These libraries also work on single board computers with regular
23+
Python via the `Adafruit Blinka Library <https://github.com/adafruit/Adafruit_Blinka>`_.
24+
25+
CircuitPython is based on `MicroPython <https://micropython.org>`_. See
26+
`below <#differences-from-micropython>`_ for differences. CircuitPython development is sponsored by
27+
`Adafruit <https://adafruit.com>`_ and is available on their educational development boards. Please
28+
support both MicroPython and Adafruit.
29+
30+
Get CircuitPython
31+
------------------
32+
33+
Official binaries for all supported boards are available through
34+
`circuitpython.org/downloads <https://circuitpython.org/downloads>`_. The site includes stable, unstable and
35+
continuous builds. Full release notes and assets are available through
36+
`GitHub releases <https://github.com/adafruit/circuitpython/releases>`_ as well.
37+
38+
Documentation
39+
-------------
40+
41+
Guides and videos are available through the `Adafruit Learning
42+
System <https://learn.adafruit.com/>`__ under the `CircuitPython
43+
category <https://learn.adafruit.com/category/circuitpython>`__. An API
44+
reference is also available on `Read the Docs
45+
<http://circuitpython.readthedocs.io/en/latest/?>`__. A collection of awesome
46+
resources can be found at `Awesome CircuitPython <https://github.com/adafruit/awesome-circuitpython>`__.
47+
48+
Specifically useful documentation when starting out:
49+
50+
- `Welcome to CircuitPython <https://learn.adafruit.com/welcome-to-circuitpython>`__
51+
- `CircuitPython Essentials <https://learn.adafruit.com/circuitpython-essentials>`__
52+
- `Example Code <https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/master/CircuitPython_Essentials>`__
53+
54+
Code Search
55+
------------
56+
GitHub doesn't currently support code search on forks. Therefore, CircuitPython doesn't have code search through GitHub because it is a fork of MicroPython. Luckily, `SourceGraph <https://sourcegraph.com/github.com/adafruit/circuitpython>`_ has free code search for public repos like CircuitPython. So, visit `sourcegraph.com/github.com/adafruit/circuitpython <https://sourcegraph.com/github.com/adafruit/circuitpython>`_ to search the CircuitPython codebase online.
57+
58+
Contributing
59+
------------
60+
61+
See
62+
`CONTRIBUTING.md <https://github.com/adafruit/circuitpython/blob/main/CONTRIBUTING.md>`__
63+
for full guidelines but please be aware that by contributing to this
64+
project you are agreeing to the `Code of
65+
Conduct <https://github.com/adafruit/circuitpython/blob/main/CODE_OF_CONDUCT.md>`__.
66+
Contributors who follow the `Code of
67+
Conduct <https://github.com/adafruit/circuitpython/blob/main/CODE_OF_CONDUCT.md>`__
68+
are welcome to submit pull requests and they will be promptly reviewed
69+
by project admins. Please join the
70+
`Discord <https://adafru.it/discord>`__ too.
71+
72+
Branding
73+
------------
74+
75+
While we are happy to see CircuitPython forked and modified, we'd appreciate it if forked releases
76+
not use the name "CircuitPython" or the Blinka logo. "CircuitPython" means something special to
77+
us and those who learn about it. As a result, we'd like to make sure products referring to it meet a
78+
common set of requirements.
79+
80+
If you'd like to use the term "CircuitPython" and Blinka for your product here is what we ask:
81+
82+
* Your product is supported by the primary
83+
`"adafruit/circuitpython" <https://github.com/adafruit/circuitpython>`_ repo. This way we can
84+
update any custom code as we update the CircuitPython internals.
85+
* Your product is listed on `circuitpython.org <https://circuitpython.org>`__ (source
86+
`here <https://github.com/adafruit/circuitpython-org/>`_). This is to ensure that a user of your
87+
product can always download the latest version of CircuitPython from the standard place.
88+
* Your product has a user accessible USB plug which appears as a CIRCUITPY drive when plugged in.
89+
90+
If you choose not to meet these requirements, then we ask you call your version of CircuitPython
91+
something else (for example, SuperDuperPython) and not use the Blinka logo. You can say it is
92+
"CircuitPython-compatible" if most CircuitPython drivers will work with it.
93+
94+
--------------
95+
96+
Differences from `MicroPython <https://github.com/micropython/micropython>`__
97+
-----------------------------------------------------------------------------
98+
99+
CircuitPython:
100+
101+
- Supports native USB on all boards, allowing file editing without special tools.
102+
- Floats (aka decimals) are enabled for all builds.
103+
- Error messages are translated into 10+ languages.
104+
- Does not support concurrency within Python (including interrupts and threading). Some concurrency
105+
is achieved with native modules for tasks that require it such as audio file playback.
106+
107+
Behavior
108+
~~~~~~~~
109+
110+
- The order that files are run and the state that is shared between
111+
them. CircuitPython's goal is to clarify the role of each file and
112+
make each file independent from each other.
113+
- ``boot.py`` (or ``settings.py``) runs only once on start up before
114+
USB is initialized. This lays the ground work for configuring USB at
115+
startup rather than it being fixed. Since serial is not available,
116+
output is written to ``boot_out.txt``.
117+
- ``code.py`` (or ``main.py``) is run after every reload until it
118+
finishes or is interrupted. After it is done running, the vm and
119+
hardware is reinitialized. **This means you cannot read state from**
120+
``code.py`` **in the REPL anymore, as the REPL is a fresh vm.** CircuitPython's goal for this
121+
change includes reducing confusion about pins and memory being used.
122+
- After the main code is finished the REPL can be entered by pressing any key.
123+
- Autoreload state will be maintained across reload.
124+
- Adds a safe mode that does not run user code after a hard crash or
125+
brown out. The hope is that this will make it easier to fix code that
126+
causes nasty crashes by making it available through mass storage
127+
after the crash. A reset (the button) is needed after it's fixed to
128+
get back into normal mode.
129+
- RGB status LED indicating CircuitPython state, and errors through a sequence of colored flashes.
130+
- Re-runs ``code.py`` or other main file after file system writes over USB mass storage. (Disable with
131+
``supervisor.disable_autoreload()``)
132+
- Autoreload is disabled while the REPL is active.
133+
- Main is one of these: ``code.txt``, ``code.py``, ``main.py``,
134+
``main.txt``
135+
- Boot is one of these: ``settings.txt``, ``settings.py``, ``boot.py``,
136+
``boot.txt``
137+
138+
API
139+
~~~
140+
141+
- Unified hardware APIs. Documented on
142+
`ReadTheDocs <https://circuitpython.readthedocs.io/en/latest/shared-bindings/index.html>`_.
143+
- API docs are rST within the C files in ``shared-bindings``.
144+
- No ``machine`` API.
145+
146+
Modules
147+
~~~~~~~
148+
149+
- No module aliasing. (``uos`` and ``utime`` are not available as
150+
``os`` and ``time`` respectively.) Instead ``os``, ``time``, and
151+
``random`` are CPython compatible.
152+
- New ``storage`` module which manages file system mounts.
153+
(Functionality from ``uos`` in MicroPython.)
154+
- Modules with a CPython counterpart, such as ``time``, ``os`` and
155+
``random``, are strict
156+
`subsets <https://circuitpython.readthedocs.io/en/latest/shared-bindings/time/__init__.html>`__
157+
of their `CPython
158+
version <https://docs.python.org/3.4/library/time.html?highlight=time#module-time>`__.
159+
Therefore, code from CircuitPython is runnable on CPython but not
160+
necessarily the reverse.
161+
- tick count is available as
162+
`time.monotonic() <https://circuitpython.readthedocs.io/en/latest/shared-bindings/time/__init__.html#time.monotonic>`__
163+
164+
--------------
165+
166+
Project Structure
167+
-----------------
168+
169+
Here is an overview of the top-level source code directories.
170+
171+
Core
172+
~~~~
173+
174+
The core code of
175+
`MicroPython <https://github.com/micropython/micropython>`__ is shared
176+
amongst ports including CircuitPython:
177+
178+
- ``docs`` High level user documentation in Sphinx reStructuredText
179+
format.
180+
- ``drivers`` External device drivers written in Python.
181+
- ``examples`` A few example Python scripts.
182+
- ``extmod`` Shared C code used in multiple ports' modules.
183+
- ``lib`` Shared core C code including externally developed libraries
184+
such as FATFS.
185+
- ``logo`` The CircuitPython logo.
186+
- ``mpy-cross`` A cross compiler that converts Python files to byte
187+
code prior to being run in MicroPython. Useful for reducing library
188+
size.
189+
- ``py`` Core Python implementation, including compiler, runtime, and
190+
core library.
191+
- ``shared-bindings`` Shared definition of Python modules, their docs
192+
and backing C APIs. Ports must implement the C API to support the
193+
corresponding module.
194+
- ``shared-module`` Shared implementation of Python modules that may be
195+
based on ``common-hal``.
196+
- ``tests`` Test framework and test scripts.
197+
- ``tools`` Various tools, including the pyboard.py module.
198+
199+
Ports
200+
~~~~~
201+
202+
Ports include the code unique to a microcontroller line.
203+
204+
================ ============================================================
205+
Supported Support status
206+
================ ============================================================
207+
atmel-samd ``SAMD21`` stable | ``SAMD51`` stable
208+
cxd56 stable
209+
esp32s2 stable
210+
litex alpha
211+
mimxrt10xx alpha
212+
nrf stable
213+
raspberrypi stable
214+
stm ``F4`` stable | ``others`` beta
215+
unix alpha
216+
================ ============================================================
217+
218+
- ``stable`` Highly unlikely to have bugs or missing functionality.
219+
- ``beta`` Being actively improved but may be missing functionality and have bugs.
220+
- ``alpha`` Will have bugs and missing functionality.
221+
222+
Boards
223+
~~~~~~
224+
225+
- Each ``port`` has a ``boards`` directory containing variations of boards
226+
which belong to a specific microcontroller line.
227+
- A list of native modules supported by a particular board can be found
228+
`here <https://circuitpython.readthedocs.io/en/latest/shared-bindings/support_matrix.html>`__.
229+
230+
`Back to Top <#circuitpython>`__
231+
232+
.. |Build Status| image:: https://github.com/adafruit/circuitpython/workflows/Build%20CI/badge.svg
233+
:target: https://github.com/adafruit/circuitpython/actions?query=branch%3Amain
234+
.. |Doc Status| image:: https://readthedocs.org/projects/circuitpython/badge/?version=latest
235+
:target: http://circuitpython.readthedocs.io/
236+
.. |Discord| image:: https://img.shields.io/discord/327254708534116352.svg
237+
:target: https://adafru.it/discord
238+
.. |License| image:: https://img.shields.io/badge/License-MIT-brightgreen.svg
239+
:target: https://choosealicense.com/licenses/mit/
240+
.. |Weblate| image:: https://hosted.weblate.org/widgets/circuitpython/-/svg-badge.svg
241+
:target: https://hosted.weblate.org/engage/circuitpython/?utm_source=widget

Diff for: setup.py renamed to setup.py-stubs

+11-9
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@
99
from setuptools import setup
1010
from pathlib import Path
1111

12-
STD_PACKAGES = set(('array', 'math', 'os', 'random', 'struct', 'sys', 'ssl', 'time'))
13-
14-
stub_root = Path("circuitpython-stubs")
15-
stubs = [p.relative_to(stub_root).as_posix() for p in stub_root.glob("*.pyi")]
16-
1712
def local_scheme(version):
1813
return ""
1914

20-
packages = set(os.listdir("circuitpython-stubs")) - STD_PACKAGES
21-
package_dir = dict((f"{package}-stubs", f"circuitpython-stubs/{package}")
15+
STD_PACKAGES = set(('array', 'math', 'os', 'random', 'struct', 'sys', 'ssl', 'time'))
16+
17+
stub_root = Path(".")
18+
stubs = [p.relative_to(stub_root) for p in stub_root.glob("*/*.pyi")]
19+
packages = set(stub.parent.as_posix() for stub in stubs) - STD_PACKAGES
20+
package_dir = dict((f"{package}-stubs", package)
2221
for package in packages)
23-
print("package dir is", package_dir)
2422

2523
def build_package_data() -> Dict[str, List[str]]:
2624
result = {}
@@ -41,6 +39,10 @@ def build_package_data() -> Dict[str, List[str]]:
4139
package_data=package_data,
4240
package_dir = package_dir,
4341
setup_requires=["setuptools_scm", "setuptools>=38.6.0"],
44-
use_scm_version={"local_scheme": local_scheme},
42+
use_scm_version = {
43+
"root": "..",
44+
"relative_to": __file__,
45+
"local_scheme": local_scheme,
46+
},
4547
zip_safe=False,
4648
)

Diff for: shared-bindings/imagecapture/ParallelImageCapture.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
//| clock: microcontroller.Pin,
4444
//| vsync: Optional[microcontroller.Pin],
4545
//| href: Optional[microcontroller.Pin],
46-
//| ):
46+
//| ) -> None:
4747
//| """Create a parallel image capture object
4848
//|
4949
//| :param List[microcontroller.Pin] data_pins: The data pins.

Diff for: tools/test-stubs.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh -e
2+
rm -rf test-stubs
3+
python3 -mvenv test-stubs
4+
. test-stubs/bin/activate
5+
pip install mypy isort black wheel
6+
rm -rf circuitpython-stubs .mypy_cache
7+
make stubs
8+
pip install --force-reinstall circuitpython-stubs/dist/circuitpython-stubs-*.tar.gz
9+
mypy -c 'import busio; b: busio.I2C; b.writeto(0x30, b"")'
10+
! mypy -c 'import busio; b: busio.I2C; b.readfrom_into(0x30, b"")'
11+
! mypy -c 'import busio; b: busio.I2C; b.write(0x30, b"")'
12+
echo "(The above two tests are expected to show type errors)"

0 commit comments

Comments
 (0)