-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_stub.py
More file actions
36 lines (31 loc) · 1.16 KB
/
generate_stub.py
File metadata and controls
36 lines (31 loc) · 1.16 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
import os
import sys
import runpy
from pathlib import Path
import shutil
#os.add_dll_directory(r"C:\Users\fogoz\AppData\Local\Programs\CLion Nova\bin\mingw\bin")
def detect_mingw_bin():
gpp = shutil.which("g++")
if not gpp:
return None
gpp_path = Path(gpp).resolve()
return gpp_path.parent if (gpp_path.parent / "libstdc++-6.dll").exists() else None
if sys.platform == "win32":
mingw_path = detect_mingw_bin()
if mingw_path:
print(f"[*] Adding MinGW DLL path: {mingw_path}")
os.add_dll_directory(str(mingw_path))
else:
print("[!] Could not detect MinGW DLL path; stubgen may fail.")
project_root = Path(__file__).parent.resolve() # <-- keep this a Path object
os.environ["PYTHONPATH"] = str(project_root)
build_dir = Path(os.environ.get("SKBUILD_BUILD_DIR", Path.cwd())).resolve()
stub_output_dir = build_dir / "generated_stubs" / "packet_handler"
stub_output_dir.mkdir(parents=True, exist_ok=True)
sys.argv = [
"pybind11_stubgen", # fake script name
"packet_handler",
"--output-dir", str(build_dir)
]
# Run pybind11_stubgen as if it was run from CLI
runpy.run_module("pybind11_stubgen", run_name="__main__")