Skip to content

Commit c16f559

Browse files
authored
Merge pull request #4907 from jepler/refine-stubs
refine stubs-building procedure
2 parents 698a392 + 3191357 commit c16f559

File tree

8 files changed

+74
-25
lines changed

8 files changed

+74
-25
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 11 deletions
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
@@ -57,9 +53,8 @@ jobs:
5753
- uses: actions/upload-artifact@v2
5854
with:
5955
name: stubs
60-
path: circuitpython-stubs*
56+
path: circuitpython-stubs/dist/*
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
@@ -129,17 +124,17 @@ jobs:
129124
[ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/mpy-cross.static s3://adafruit-circuit-python/bin/mpy-cross/mpy-cross.static-amd64-linux-${{ env.CP_VERSION }} --no-progress --region us-east-1
130125
[ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/mpy-cross.static.exe s3://adafruit-circuit-python/bin/mpy-cross/mpy-cross.static-x64-windows-${{ env.CP_VERSION }}.exe --no-progress --region us-east-1
131126
zip -9r circuitpython-stubs.zip circuitpython-stubs
132-
[ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp circuitpython-stubs.zip s3://adafruit-circuit-python/bin/stubs/circuitpython-stubs-${{ env.CP_VERSION }}.zip --no-progress --region us-east-1
127+
[ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp circuitpython-stubs/dist/*.tar.gz s3://adafruit-circuit-python/bin/stubs/circuitpython-stubs-${{ env.CP_VERSION }}.zip --no-progress --region us-east-1
133128
134129
- name: Upload stubs to PyPi
135-
if: github.event_name == 'push'
130+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'adafruit'
136131
env:
137132
TWINE_USERNAME: ${{ secrets.pypi_username }}
138133
TWINE_PASSWORD: ${{ secrets.pypi_password }}
139134
run: |
140-
echo "Uploading dev release to PyPi"
141-
python setup.py sdist
142-
[ -z "$TWINE_USERNAME" ] || twine upload dist/*
135+
# setup.py sdist was run by 'make stubs'
136+
if [ -z "$TWINE_USERNAME" ] || echo "Uploading dev release to PyPi"
137+
if [ -z "$TWINE_USERNAME" ] || twine upload circuitpython-stubs/dist/*
143138
144139
mpy-cross-mac:
145140
runs-on: macos-10.15

.gitignore

Lines changed: 1 addition & 0 deletions
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

MANIFEST.in-stubs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
recursive-include . *.pyi

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,23 @@ check-translate:
253253
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
254254
$(PYTHON) tools/check_translations.py locale/circuitpython.pot.tmp locale/circuitpython.pot; status=$$?; rm -f locale/circuitpython.pot.tmp; exit $$status
255255

256+
.PHONY: stubs
256257
stubs:
257-
@mkdir -p circuitpython-stubs
258+
@rm -rf circuitpython-stubs
259+
@mkdir circuitpython-stubs
258260
@$(PYTHON) tools/extract_pyi.py shared-bindings/ $(STUBDIR)
259261
@$(PYTHON) tools/extract_pyi.py extmod/ulab/code/ $(STUBDIR)/ulab
260262
@$(PYTHON) tools/extract_pyi.py ports/atmel-samd/bindings $(STUBDIR)
261263
@$(PYTHON) tools/extract_pyi.py ports/raspberrypi/bindings $(STUBDIR)
262-
@$(PYTHON) setup.py -q sdist
264+
@cp setup.py-stubs circuitpython-stubs/setup.py
265+
@cp README.rst-stubs circuitpython-stubs/README.rst
266+
@cp MANIFEST.in-stubs circuitpython-stubs/MANIFEST.in
267+
@(cd circuitpython-stubs && $(PYTHON) setup.py -q sdist)
263268

264269
.PHONY: check-stubs
265270
check-stubs: stubs
266-
MYPYPATH=$(STUBDIR) mypy --strict $(STUBDIR)
271+
@(cd $(STUBDIR) && set -- */__init__.pyi && mypy --strict "$${@%/*}")
272+
@tools/test-stubs.sh
267273

268274
update-frozen-libraries:
269275
@echo "Updating all frozen libraries to latest tagged version."

README.rst-stubs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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.
15+
16+
This package contains the "stubs", or type definitions for CircuitPython. With some advanced
17+
editors and other tools, this information can be identify TypeErrors, AttributeErrors, and other
18+
problems before you deploy your code to a device and can even help autocomplete your code.
19+
20+
.. |Build Status| image:: https://github.com/adafruit/circuitpython/workflows/Build%20CI/badge.svg
21+
:target: https://github.com/adafruit/circuitpython/actions?query=branch%3Amain
22+
.. |Doc Status| image:: https://readthedocs.org/projects/circuitpython/badge/?version=latest
23+
:target: http://circuitpython.readthedocs.io/
24+
.. |Discord| image:: https://img.shields.io/discord/327254708534116352.svg
25+
:target: https://adafru.it/discord
26+
.. |License| image:: https://img.shields.io/badge/License-MIT-brightgreen.svg
27+
:target: https://choosealicense.com/licenses/mit/
28+
.. |Weblate| image:: https://hosted.weblate.org/widgets/circuitpython/-/svg-badge.svg
29+
:target: https://hosted.weblate.org/engage/circuitpython/?utm_source=widget

conf.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
autoapi_type = 'python'
8787
# Uncomment this if debugging autoapi
8888
autoapi_keep_files = True
89-
autoapi_dirs = [os.path.join('circuitpython-stubs', x) for x in os.listdir('circuitpython-stubs')]
89+
autoapi_dirs = [os.path.join('circuitpython-stubs', x) for x in os.listdir('circuitpython-stubs') if os.path.exists(os.path.join("circuitpython-stubs", x, "__init__.pyi"))]
90+
print("autoapi_dirs", autoapi_dirs)
9091
autoapi_add_toctree_entry = False
9192
autoapi_options = ['members', 'undoc-members', 'private-members', 'show-inheritance', 'special-members', 'show-module-summary']
9293
autoapi_template_dir = 'docs/autoapi/templates'
@@ -203,7 +204,9 @@
203204
"shared-module",
204205
"supervisor",
205206
"tests",
206-
"tools"]
207+
"test-stubs",
208+
"tools",
209+
"circuitpython-stubs/README.rst"]
207210

208211
# The reST default role (used for this markup: `text`) to use for all
209212
# documents.

setup.py renamed to setup.py-stubs

Lines changed: 11 additions & 9 deletions
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
)

tools/test-stubs.sh

Lines changed: 12 additions & 0 deletions
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)