Skip to content

Commit f210d25

Browse files
Explicitly list which modules to translate/export. (#58)
1 parent 7a41062 commit f210d25

File tree

3 files changed

+39
-31
lines changed

3 files changed

+39
-31
lines changed

scripts/common.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def module_name_for_path(file_path: str):
3838
return os.path.splitext(name)[0]
3939

4040

41-
def get_stub_files() -> list[TypeshedFile]:
41+
def get_stub_files(approved_modules: list[str]) -> list[TypeshedFile]:
4242
top = os.path.join(DIR, "..", "lang/en/typeshed/stdlib")
4343
files_to_process: list[TypeshedFile] = []
4444
for root, dirs, files in os.walk(top):
@@ -47,26 +47,25 @@ def get_stub_files() -> list[TypeshedFile]:
4747
# Skip audio stubs file that imports from microbit audio
4848
# (so we don't include its docstring)
4949
if (
50-
os.path.basename(os.path.dirname(file_path)) != "microbit"
51-
and name == "audio.pyi"
50+
os.path.basename(os.path.dirname(file_path)) in approved_modules
51+
or os.path.splitext(name)[0] in approved_modules
5252
):
53-
continue
54-
if name.endswith(".pyi"):
55-
files_to_process.append(
56-
TypeshedFile(
57-
file_path=file_path,
58-
module_name=module_name_for_path(file_path),
59-
python_file=True,
53+
if name.endswith(".pyi"):
54+
files_to_process.append(
55+
TypeshedFile(
56+
file_path=file_path,
57+
module_name=module_name_for_path(file_path),
58+
python_file=True,
59+
)
6060
)
61-
)
62-
else:
63-
files_to_process.append(
64-
TypeshedFile(
65-
file_path=file_path,
66-
module_name="",
67-
python_file=False,
61+
else:
62+
files_to_process.append(
63+
TypeshedFile(
64+
file_path=file_path,
65+
module_name="",
66+
python_file=False,
67+
)
6868
)
69-
)
7069
return sorted(files_to_process, key=lambda x: x.file_path)
7170

7271

scripts/crowdin_convert.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,29 @@
1818
EN_JSON_PATH = os.path.join(DIR, "../crowdin/api.en.json")
1919
TRANSLATED_JSON_DIR = os.path.join(DIR, "../crowdin/translated")
2020

21+
modules = [
22+
"gc",
23+
"log",
24+
"machine",
25+
"math",
26+
"microbit",
27+
"micropython",
28+
"music",
29+
"neopixel",
30+
"os",
31+
"radio",
32+
"random",
33+
"speech",
34+
"struct",
35+
"sys",
36+
"time",
37+
]
38+
2139

2240
def typeshed_to_crowdin():
2341
"""Entrypoint to convert from English typeshed files to a JSON file for Crowdin translation."""
2442
data = {}
25-
files_to_process = get_stub_files()
43+
files_to_process = get_stub_files(modules)
2644
for ts_file in files_to_process:
2745
if not ts_file.python_file:
2846
continue
@@ -231,7 +249,7 @@ def crowdin_to_typeshed():
231249
"""Entrypoint to convert from Crowdin (translated) JSON to individual typeshed files."""
232250
en_json = read_json(EN_JSON_PATH)
233251
translations_to_process = get_translated_json_files()
234-
stubs_to_process = get_stub_files()
252+
stubs_to_process = get_stub_files(modules)
235253
for translated in translations_to_process:
236254
translated_json = read_json(translated)
237255
lang = os.path.basename(translated).split(".")[1]

scripts/export_api_ids.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
def export_api_ids():
4040
data_list = []
41-
files_to_process = get_stub_files()
41+
files_to_process = get_stub_files(modules)
4242
for ts_file in files_to_process:
4343
if ts_file.python_file:
4444
data_list = data_list + get_api_ids(ts_file)
@@ -53,14 +53,6 @@ def save_api_ids(data):
5353
file.write(json.dumps(data, indent=2))
5454

5555

56-
def checkModuleRequired(module_name):
57-
if module_name in modules:
58-
return True
59-
if "microbit" in module_name:
60-
return True
61-
return False
62-
63-
6456
def get_api_ids(ts_file: TypeshedFile):
6557
source = get_source(ts_file.file_path)
6658
tree = ast.parse(source)
@@ -83,8 +75,7 @@ def handle_docstring(self, node: ast.AST, name: str) -> None:
8375
suffix += 1
8476
key = f"{key_root}-{suffix}"
8577
self.used_keys.add(key)
86-
if checkModuleRequired(ts_file.module_name):
87-
self.data.append(key)
78+
self.data.append(key)
8879

8980
collector = DocStringCollector()
9081
collector.visit(tree)

0 commit comments

Comments
 (0)