Merge pull request #4907 from jepler/refine-stubs

refine stubs-building procedure
This commit is contained in:
Scott Shawcroft 2021-07-15 12:11:58 -07:00 committed by GitHub
commit c16f559574
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 74 additions and 25 deletions

View File

@ -43,10 +43,6 @@ jobs:
run: |
gcc --version
python3 --version
- name: Check For setup.py
id: need-pypi
run: |
echo ::set-output name=setup-py::$( find . -wholename './setup.py' )
- name: New boards check
run: python3 -u ci_new_boards_check.py
working-directory: tools
@ -57,9 +53,8 @@ jobs:
- uses: actions/upload-artifact@v2
with:
name: stubs
path: circuitpython-stubs*
path: circuitpython-stubs/dist/*
- name: Install pypi dependencies
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
@ -129,17 +124,17 @@ jobs:
[ -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
[ -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
zip -9r circuitpython-stubs.zip circuitpython-stubs
[ -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
[ -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
- name: Upload stubs to PyPi
if: github.event_name == 'push'
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'adafruit'
env:
TWINE_USERNAME: ${{ secrets.pypi_username }}
TWINE_PASSWORD: ${{ secrets.pypi_password }}
run: |
echo "Uploading dev release to PyPi"
python setup.py sdist
[ -z "$TWINE_USERNAME" ] || twine upload dist/*
# setup.py sdist was run by 'make stubs'
if [ -z "$TWINE_USERNAME" ] || echo "Uploading dev release to PyPi"
if [ -z "$TWINE_USERNAME" ] || twine upload circuitpython-stubs/dist/*
mpy-cross-mac:
runs-on: macos-10.15

1
.gitignore vendored
View File

@ -33,6 +33,7 @@ dist/
build/
bin/
circuitpython-stubs/
test-stubs/
build-*/
# Test failure outputs

1
MANIFEST.in-stubs Normal file
View File

@ -0,0 +1 @@
recursive-include . *.pyi

View File

@ -253,17 +253,23 @@ check-translate:
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
$(PYTHON) tools/check_translations.py locale/circuitpython.pot.tmp locale/circuitpython.pot; status=$$?; rm -f locale/circuitpython.pot.tmp; exit $$status
.PHONY: stubs
stubs:
@mkdir -p circuitpython-stubs
@rm -rf circuitpython-stubs
@mkdir circuitpython-stubs
@$(PYTHON) tools/extract_pyi.py shared-bindings/ $(STUBDIR)
@$(PYTHON) tools/extract_pyi.py extmod/ulab/code/ $(STUBDIR)/ulab
@$(PYTHON) tools/extract_pyi.py ports/atmel-samd/bindings $(STUBDIR)
@$(PYTHON) tools/extract_pyi.py ports/raspberrypi/bindings $(STUBDIR)
@$(PYTHON) setup.py -q sdist
@cp setup.py-stubs circuitpython-stubs/setup.py
@cp README.rst-stubs circuitpython-stubs/README.rst
@cp MANIFEST.in-stubs circuitpython-stubs/MANIFEST.in
@(cd circuitpython-stubs && $(PYTHON) setup.py -q sdist)
.PHONY: check-stubs
check-stubs: stubs
MYPYPATH=$(STUBDIR) mypy --strict $(STUBDIR)
@(cd $(STUBDIR) && set -- */__init__.pyi && mypy --strict "$${@%/*}")
@tools/test-stubs.sh
update-frozen-libraries:
@echo "Updating all frozen libraries to latest tagged version."

29
README.rst-stubs Normal file
View File

@ -0,0 +1,29 @@
CircuitPython
=============
.. image:: https://s3.amazonaws.com/adafruit-circuit-python/CircuitPython_Repo_header_logo.png
|Build Status| |Doc Status| |License| |Discord| |Weblate|
`circuitpython.org <https://circuitpython.org>`__ \| `Get CircuitPython <#get-circuitpython>`__ \|
`Documentation <#documentation>`__ \| `Contributing <#contributing>`__ \|
`Branding <#branding>`__ \| `Differences from Micropython <#differences-from-micropython>`__ \|
`Project Structure <#project-structure>`__
**CircuitPython** is a *beginner friendly*, open source version of Python for tiny, inexpensive
computers called microcontrollers.
This package contains the "stubs", or type definitions for CircuitPython. With some advanced
editors and other tools, this information can be identify TypeErrors, AttributeErrors, and other
problems before you deploy your code to a device and can even help autocomplete your code.
.. |Build Status| image:: https://github.com/adafruit/circuitpython/workflows/Build%20CI/badge.svg
:target: https://github.com/adafruit/circuitpython/actions?query=branch%3Amain
.. |Doc Status| image:: https://readthedocs.org/projects/circuitpython/badge/?version=latest
:target: http://circuitpython.readthedocs.io/
.. |Discord| image:: https://img.shields.io/discord/327254708534116352.svg
:target: https://adafru.it/discord
.. |License| image:: https://img.shields.io/badge/License-MIT-brightgreen.svg
:target: https://choosealicense.com/licenses/mit/
.. |Weblate| image:: https://hosted.weblate.org/widgets/circuitpython/-/svg-badge.svg
:target: https://hosted.weblate.org/engage/circuitpython/?utm_source=widget

View File

@ -86,7 +86,8 @@ 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_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"))]
print("autoapi_dirs", autoapi_dirs)
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'
@ -203,7 +204,9 @@ exclude_patterns = ["**/build*",
"shared-module",
"supervisor",
"tests",
"tools"]
"test-stubs",
"tools",
"circuitpython-stubs/README.rst"]
# The reST default role (used for this markup: `text`) to use for all
# documents.

View File

@ -9,18 +9,16 @@ from typing import Dict, List
from setuptools import setup
from pathlib import Path
STD_PACKAGES = set(('array', 'math', 'os', 'random', 'struct', 'sys', 'ssl', 'time'))
stub_root = Path("circuitpython-stubs")
stubs = [p.relative_to(stub_root).as_posix() for p in stub_root.glob("*.pyi")]
def local_scheme(version):
return ""
packages = set(os.listdir("circuitpython-stubs")) - STD_PACKAGES
package_dir = dict((f"{package}-stubs", f"circuitpython-stubs/{package}")
STD_PACKAGES = set(('array', 'math', 'os', 'random', 'struct', 'sys', 'ssl', 'time'))
stub_root = Path(".")
stubs = [p.relative_to(stub_root) for p in stub_root.glob("*/*.pyi")]
packages = set(stub.parent.as_posix() for stub in stubs) - STD_PACKAGES
package_dir = dict((f"{package}-stubs", package)
for package in packages)
print("package dir is", package_dir)
def build_package_data() -> Dict[str, List[str]]:
result = {}
@ -41,6 +39,10 @@ setup(
package_data=package_data,
package_dir = package_dir,
setup_requires=["setuptools_scm", "setuptools>=38.6.0"],
use_scm_version={"local_scheme": local_scheme},
use_scm_version = {
"root": "..",
"relative_to": __file__,
"local_scheme": local_scheme,
},
zip_safe=False,
)

12
tools/test-stubs.sh Executable file
View File

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