-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyFilesGen.py
More file actions
59 lines (46 loc) · 1.73 KB
/
Copy pathpyFilesGen.py
File metadata and controls
59 lines (46 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import sys
from pathlib import Path
import subprocess
result_dir = Path(os.environ.get("PYSF_RESULT_DIR", "output/result"))
pysf_dir = result_dir / "pysf"
sys.path.insert(0, str(pysf_dir.resolve()))
if sys.platform == "win32":
import pysf as sf
elif sys.platform == "darwin":
import pysf as sf
else:
print("Unsupported operating system")
sys.exit(1)
def collect_pyi_paths(target_dir_name):
cwd = Path.cwd()
target_path = cwd / target_dir_name
if not target_path.exists():
raise FileNotFoundError(f"Directory not found: {target_path}")
pyi_files = []
for file_path in target_path.rglob("*.pyi"):
if file_path.is_file():
relative_path = file_path.relative_to(cwd)
pyi_files.append(str(relative_path))
return pyi_files
def replace_pyi(pyi_path):
with open(pyi_path, "r", encoding="utf-8") as file:
lines = file.readlines()
with open(pyi_path, "w", encoding="utf-8") as file:
for line in lines:
line = line.replace("pysf.", "")
file.write(line)
if __name__ == "__main__":
attrs = [attr for attr in dir(sf) if not (attr.startswith("__") and attr.endswith("__"))]
with open(pysf_dir / "__init__.py", "w") as file:
file.write("from . import pysf as _pysf\n")
file.write("from .pysf import (\n")
for attr in attrs:
file.write(f" {attr},\n")
file.write(")\n")
file.write("__doc__ = _pysf.__doc__\n")
print("Successfully generated __init__.py")
subprocess.run([sys.executable, "-m", "pybind11_stubgen", "--output-dir=.", "pysf"], cwd=pysf_dir)
for path in collect_pyi_paths(pysf_dir / "pysf"):
replace_pyi(path)
print("Successfully generated pyi")