8000 setup.py: Improve installation of stubs · syntheticfuture/circuitpython@8e5c389 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e5c389

Browse files
committed
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.
1 parent fb7dc9b commit 8e5c389

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

setup.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import os
55
import site
66
from datetime import datetime
7-
from typing import List
7+
from typing import Dict, List
88

99
from setuptools import setup
1010
from pathlib import Path
1111
import subprocess
1212
import re
1313

14+
STD_PACKAGES = set(('array', 'math', 'os', 'random', 'struct', 'sys', 'ssl', 'time'))
15+
1416
stub_root = Path("circuitpython-stubs")
1517
stubs = [p.relative_to(stub_root).as_posix() for p in stub_root.glob("*.pyi")]
1618

@@ -28,13 +30,18 @@
2830
pieces.pop()
2931
version = "-".join(pieces)
3032

31-
def build_data_files_list() -> List[tuple]:
32-
result = []
33-
for package in os.listdir("circuitpython-stubs"):
34-
result.append((site.getsitepackages()[0] + "/" + package + "/",
35-
["circuitpython-stubs/{}/__init__.pyi".format(package)]))
33+
packages = set(os.listdir("circuitpython-stubs")) - STD_PACKAGES
34+
package_dir = dict((f"{package}-stubs", f"circuitpython-stubs/{package}")
35+
for package in packages)
36+
print("package dir is", package_dir)
37+
38+
def build_package_data() -> Dict[str, List[str]]:
39+
result = {}
40+
for package in packages:
41+
result[f"{package}-stubs"] = ["*.pyi", "*/*.pyi"]
3642
return result
3743

44+
package_data=build_package_data()
3845
setup(
3946
name="circuitpython-stubs",
4047
description="PEP 561 type stubs for CircuitPython",
@@ -44,6 +51,9 @@ def build_data_files_list() -> List[tuple]:
4451
author_email="circuitpython@adafruit.com",
4552
version=version,
4653
license="MIT",
47-
data_files=build_data_files_list(),
54+
packages=list(package_data.keys()),
55+
package_data=package_data,
56+
package_dir = package_dir,
4857
setup_requires=["setuptools>=38.6.0"],
58+
zip_safe=False,
4959
)

0 commit comments

Comments
 (0)
0