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.
This commit is contained in:
parent
fb7dc9bcd5
commit
8e5c389c95
24
setup.py
24
setup.py
@ -4,13 +4,15 @@
|
|||||||
import os
|
import os
|
||||||
import site
|
import site
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List
|
from typing import Dict, List
|
||||||
|
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
STD_PACKAGES = set(('array', 'math', 'os', 'random', 'struct', 'sys', 'ssl', 'time'))
|
||||||
|
|
||||||
stub_root = Path("circuitpython-stubs")
|
stub_root = Path("circuitpython-stubs")
|
||||||
stubs = [p.relative_to(stub_root).as_posix() for p in stub_root.glob("*.pyi")]
|
stubs = [p.relative_to(stub_root).as_posix() for p in stub_root.glob("*.pyi")]
|
||||||
|
|
||||||
@ -28,13 +30,18 @@ if len(pieces) > 2:
|
|||||||
pieces.pop()
|
pieces.pop()
|
||||||
version = "-".join(pieces)
|
version = "-".join(pieces)
|
||||||
|
|
||||||
def build_data_files_list() -> List[tuple]:
|
packages = set(os.listdir("circuitpython-stubs")) - STD_PACKAGES
|
||||||
result = []
|
package_dir = dict((f"{package}-stubs", f"circuitpython-stubs/{package}")
|
||||||
for package in os.listdir("circuitpython-stubs"):
|
for package in packages)
|
||||||
result.append((site.getsitepackages()[0] + "/" + package + "/",
|
print("package dir is", package_dir)
|
||||||
["circuitpython-stubs/{}/__init__.pyi".format(package)]))
|
|
||||||
|
def build_package_data() -> Dict[str, List[str]]:
|
||||||
|
result = {}
|
||||||
|
for package in packages:
|
||||||
|
result[f"{package}-stubs"] = ["*.pyi", "*/*.pyi"]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
package_data=build_package_data()
|
||||||
setup(
|
setup(
|
||||||
name="circuitpython-stubs",
|
name="circuitpython-stubs",
|
||||||
description="PEP 561 type stubs for CircuitPython",
|
description="PEP 561 type stubs for CircuitPython",
|
||||||
@ -44,6 +51,9 @@ setup(
|
|||||||
author_email="circuitpython@adafruit.com",
|
author_email="circuitpython@adafruit.com",
|
||||||
version=version,
|
version=version,
|
||||||
license="MIT",
|
license="MIT",
|
||||||
data_files=build_data_files_list(),
|
packages=list(package_data.keys()),
|
||||||
|
package_data=package_data,
|
||||||
|
package_dir = package_dir,
|
||||||
setup_requires=["setuptools>=38.6.0"],
|
setup_requires=["setuptools>=38.6.0"],
|
||||||
|
zip_safe=False,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user