Skip to content

refine stubs-building procedure #4907

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 10 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 6 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dist/
build/
bin/
circuitpython-stubs/
test-stubs/
build-*/

# Test failure outputs
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in-stubs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include . *.pyi
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,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."
Expand Down
29 changes: 29 additions & 0 deletions README.rst-stubs
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
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'
Expand Down Expand Up @@ -203,7 +204,9 @@
"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.
Expand Down
20 changes: 11 additions & 9 deletions setup.py → setup.py-stubs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@
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 = {}
Expand All @@ -41,6 +39,10 @@ def build_package_data() -> Dict[str, List[str]]:
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 changes: 12 additions & 0 deletions tools/test-stubs.sh
Original file line number Diff line number Diff line change
@@ -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)"