2020-06-03 18:40:05 -04:00
|
|
|
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MIT
|
2021-06-01 21:38:56 -04:00
|
|
|
import os
|
|
|
|
import site
|
2019-05-11 23:00:22 -04:00
|
|
|
from datetime import datetime
|
setup.py: Improve installation of stubs
* Don't include a full path from the build system
* Rename all packages to "foo-stubs"
* Don't install stubs for standard packages like "os"
After this, I can `python setup.py install --user` to install the stubs
to my local environment, and successfully check code against the stubs,
such as
```
/$ mypy -c 'import busio; b: busio.I2C; b.readfrom_into(0x30, b"")'
<string>:1: error: Argument 2 to "readfrom_into" of "I2C" has incompatible type "bytes"; expected "Union[bytearray, memoryview, array[Any], ndarray, RGBMatrix]"
Found 1 error in 1 file (checked 1 source file)
```
The structure of a wheel built with `python setup.py bdist_wheel` looks
more like lxml-stubs, as well.
```
Archive: dist/circuitpython_stubs-7.0.0a3.dev28+g124c7b785-py3-none-any.whl
Length Date Time Name
--------- ---------- ----- ----
30705 2021-06-10 13:50 _bleio-stubs/__init__.pyi…
```
Finally, by eliminating `site.getsitepackages()`, this **may** fix
the doc building problem on readthedocs.
2021-06-10 10:26:59 -04:00
|
|
|
from typing import Dict, List
|
2021-06-01 21:38:56 -04:00
|
|
|
|
2019-05-11 23:00:22 -04:00
|
|
|
from setuptools import setup
|
|
|
|
from pathlib import Path
|
2020-05-13 17:45:09 -04:00
|
|
|
import subprocess
|
|
|
|
import re
|
2019-05-11 23:00:22 -04:00
|
|
|
|
setup.py: Improve installation of stubs
* Don't include a full path from the build system
* Rename all packages to "foo-stubs"
* Don't install stubs for standard packages like "os"
After this, I can `python setup.py install --user` to install the stubs
to my local environment, and successfully check code against the stubs,
such as
```
/$ mypy -c 'import busio; b: busio.I2C; b.readfrom_into(0x30, b"")'
<string>:1: error: Argument 2 to "readfrom_into" of "I2C" has incompatible type "bytes"; expected "Union[bytearray, memoryview, array[Any], ndarray, RGBMatrix]"
Found 1 error in 1 file (checked 1 source file)
```
The structure of a wheel built with `python setup.py bdist_wheel` looks
more like lxml-stubs, as well.
```
Archive: dist/circuitpython_stubs-7.0.0a3.dev28+g124c7b785-py3-none-any.whl
Length Date Time Name
--------- ---------- ----- ----
30705 2021-06-10 13:50 _bleio-stubs/__init__.pyi…
```
Finally, by eliminating `site.getsitepackages()`, this **may** fix
the doc building problem on readthedocs.
2021-06-10 10:26:59 -04:00
|
|
|
STD_PACKAGES = set(('array', 'math', 'os', 'random', 'struct', 'sys', 'ssl', 'time'))
|
|
|
|
|
2019-05-11 23:00:22 -04:00
|
|
|
stub_root = Path("circuitpython-stubs")
|
|
|
|
stubs = [p.relative_to(stub_root).as_posix() for p in stub_root.glob("*.pyi")]
|
|
|
|
|
2020-05-13 17:45:09 -04:00
|
|
|
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.py: Improve installation of stubs
* Don't include a full path from the build system
* Rename all packages to "foo-stubs"
* Don't install stubs for standard packages like "os"
After this, I can `python setup.py install --user` to install the stubs
to my local environment, and successfully check code against the stubs,
such as
```
/$ mypy -c 'import busio; b: busio.I2C; b.readfrom_into(0x30, b"")'
<string>:1: error: Argument 2 to "readfrom_into" of "I2C" has incompatible type "bytes"; expected "Union[bytearray, memoryview, array[Any], ndarray, RGBMatrix]"
Found 1 error in 1 file (checked 1 source file)
```
The structure of a wheel built with `python setup.py bdist_wheel` looks
more like lxml-stubs, as well.
```
Archive: dist/circuitpython_stubs-7.0.0a3.dev28+g124c7b785-py3-none-any.whl
Length Date Time Name
--------- ---------- ----- ----
30705 2021-06-10 13:50 _bleio-stubs/__init__.pyi…
```
Finally, by eliminating `site.getsitepackages()`, this **may** fix
the doc building problem on readthedocs.
2021-06-10 10:26:59 -04:00
|
|
|
packages = set(os.listdir("circuitpython-stubs")) - STD_PACKAGES
|
|
|
|
package_dir = dict((f"{package}-stubs", f"circuitpython-stubs/{package}")
|
|
|
|
for package in packages)
|
|
|
|
print("package dir is", package_dir)
|
|
|
|
|
|
|
|
def build_package_data() -> Dict[str, List[str]]:
|
|
|
|
result = {}
|
|
|
|
for package in packages:
|
|
|
|
result[f"{package}-stubs"] = ["*.pyi", "*/*.pyi"]
|
2021-06-01 21:38:56 -04:00
|
|
|
return result
|
|
|
|
|
setup.py: Improve installation of stubs
* Don't include a full path from the build system
* Rename all packages to "foo-stubs"
* Don't install stubs for standard packages like "os"
After this, I can `python setup.py install --user` to install the stubs
to my local environment, and successfully check code against the stubs,
such as
```
/$ mypy -c 'import busio; b: busio.I2C; b.readfrom_into(0x30, b"")'
<string>:1: error: Argument 2 to "readfrom_into" of "I2C" has incompatible type "bytes"; expected "Union[bytearray, memoryview, array[Any], ndarray, RGBMatrix]"
Found 1 error in 1 file (checked 1 source file)
```
The structure of a wheel built with `python setup.py bdist_wheel` looks
more like lxml-stubs, as well.
```
Archive: dist/circuitpython_stubs-7.0.0a3.dev28+g124c7b785-py3-none-any.whl
Length Date Time Name
--------- ---------- ----- ----
30705 2021-06-10 13:50 _bleio-stubs/__init__.pyi…
```
Finally, by eliminating `site.getsitepackages()`, this **may** fix
the doc building problem on readthedocs.
2021-06-10 10:26:59 -04:00
|
|
|
package_data=build_package_data()
|
2019-05-11 23:00:22 -04:00
|
|
|
setup(
|
|
|
|
name="circuitpython-stubs",
|
|
|
|
description="PEP 561 type stubs for CircuitPython",
|
|
|
|
url="https://github.com/adafruit/circuitpython",
|
2019-06-02 18:08:48 -04:00
|
|
|
maintainer="CircuitPythonistas",
|
2020-05-13 17:45:09 -04:00
|
|
|
maintainer_email="circuitpython@adafruit.com",
|
2019-06-02 18:08:48 -04:00
|
|
|
author_email="circuitpython@adafruit.com",
|
2020-05-13 17:45:09 -04:00
|
|
|
version=version,
|
2019-05-11 23:00:22 -04:00
|
|
|
license="MIT",
|
setup.py: Improve installation of stubs
* Don't include a full path from the build system
* Rename all packages to "foo-stubs"
* Don't install stubs for standard packages like "os"
After this, I can `python setup.py install --user` to install the stubs
to my local environment, and successfully check code against the stubs,
such as
```
/$ mypy -c 'import busio; b: busio.I2C; b.readfrom_into(0x30, b"")'
<string>:1: error: Argument 2 to "readfrom_into" of "I2C" has incompatible type "bytes"; expected "Union[bytearray, memoryview, array[Any], ndarray, RGBMatrix]"
Found 1 error in 1 file (checked 1 source file)
```
The structure of a wheel built with `python setup.py bdist_wheel` looks
more like lxml-stubs, as well.
```
Archive: dist/circuitpython_stubs-7.0.0a3.dev28+g124c7b785-py3-none-any.whl
Length Date Time Name
--------- ---------- ----- ----
30705 2021-06-10 13:50 _bleio-stubs/__init__.pyi…
```
Finally, by eliminating `site.getsitepackages()`, this **may** fix
the doc building problem on readthedocs.
2021-06-10 10:26:59 -04:00
|
|
|
packages=list(package_data.keys()),
|
|
|
|
package_data=package_data,
|
|
|
|
package_dir = package_dir,
|
2020-05-13 17:45:09 -04:00
|
|
|
setup_requires=["setuptools>=38.6.0"],
|
setup.py: Improve installation of stubs
* Don't include a full path from the build system
* Rename all packages to "foo-stubs"
* Don't install stubs for standard packages like "os"
After this, I can `python setup.py install --user` to install the stubs
to my local environment, and successfully check code against the stubs,
such as
```
/$ mypy -c 'import busio; b: busio.I2C; b.readfrom_into(0x30, b"")'
<string>:1: error: Argument 2 to "readfrom_into" of "I2C" has incompatible type "bytes"; expected "Union[bytearray, memoryview, array[Any], ndarray, RGBMatrix]"
Found 1 error in 1 file (checked 1 source file)
```
The structure of a wheel built with `python setup.py bdist_wheel` looks
more like lxml-stubs, as well.
```
Archive: dist/circuitpython_stubs-7.0.0a3.dev28+g124c7b785-py3-none-any.whl
Length Date Time Name
--------- ---------- ----- ----
30705 2021-06-10 13:50 _bleio-stubs/__init__.pyi…
```
Finally, by eliminating `site.getsitepackages()`, this **may** fix
the doc building problem on readthedocs.
2021-06-10 10:26:59 -04:00
|
|
|
zip_safe=False,
|
2019-06-02 18:08:48 -04:00
|
|
|
)
|