Skip to content

Commit 78ea3ff

Browse files
authored
Merge pull request #1 from tannewt/switch_to_inline_pyi
Add verification script
2 parents 829da5c + 4671348 commit 78ea3ff

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ check-translate: locale/circuitpython.pot $(wildcard locale/*.po)
213213
$(PYTHON) tools/check_translations.py $^
214214

215215
stubs:
216-
rst2pyi $(VALIDATE) shared-bindings/ $(STUBDIR)
217-
python setup.py sdist
216+
python tools/extract_pyi.py shared-bindings/ $(STUBDIR)
217+
#python setup.py sdist
218218

219219
update-frozen-libraries:
220220
@echo "Updating all frozen libraries to latest tagged version."

tools/extract_pyi.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import os
2+
import sys
3+
import astroid
4+
import traceback
5+
6+
top_level = sys.argv[1].strip("/")
7+
stub_directory = sys.argv[2]
8+
9+
if top_level.count("/") == 1:
10+
top_level, module = top_level.split("/")
11+
modules = [module]
12+
else:
13+
modules = os.listdir(top_level)
14+
modules = sorted(modules)
15+
16+
ok = 0
17+
total = 0
18+
for module in modules:
19+
module_path = os.path.join(top_level, module)
20+
if not os.path.isdir(module_path):
21+
continue
22+
pyi_lines = []
23+
for class_file in os.listdir(module_path):
24+
class_path = os.path.join(module_path, class_file)
25+
with open(class_path, "r") as f:
26+
for line in f:
27+
if line.startswith("//| "):
28+
pyi_lines.append(line[4:])
29+
30+
stub_filename = os.path.join(stub_directory, module + ".pyi")
31+
print(stub_filename)
32+
stub_contents = "".join(pyi_lines)
33+
with open(stub_filename, "w") as f:
34+
f.write(stub_contents)
35+
36+
# Validate that the module is a parseable stub.
37+
total += 1
38+
try:
39+
astroid.parse(stub_contents)
40+
ok += 1
41+
except astroid.exceptions.AstroidSyntaxError as e:
42+
e = e.__cause__
43+
traceback.print_exception(type(e), e, e.__traceback__)
44+
print()
45+
46+
print(f"{ok} ok out of {total}")

0 commit comments

Comments
 (0)