|
13 | 13 | import argparse
|
14 | 14 | import os
|
15 | 15 | import re
|
16 |
| -import shutil |
17 | 16 | import subprocess
|
18 | 17 | import sys
|
19 | 18 |
|
@@ -46,24 +45,9 @@ def get_installed_package_info(project: str) -> tuple[str, str] | None:
|
46 | 45 | return search_pip_freeze_output(project, r.stdout)
|
47 | 46 |
|
48 | 47 |
|
49 |
| -def run_stubgen(package: str) -> None: |
50 |
| - print(f"Running stubgen: stubgen -p {package}") |
51 |
| - subprocess.run(["stubgen", "-p", package], check=True) |
52 |
| - |
53 |
| - |
54 |
| -def copy_stubs(src_base_dir: str, package: str, stub_dir: str) -> None: |
55 |
| - """Copy generated stubs to the target directory under stub_dir/.""" |
56 |
| - print(f"Copying stubs to {stub_dir}") |
57 |
| - if not os.path.isdir(stub_dir): |
58 |
| - os.mkdir(stub_dir) |
59 |
| - src_dir = os.path.join(src_base_dir, package) |
60 |
| - if os.path.isdir(src_dir): |
61 |
| - shutil.copytree(src_dir, os.path.join(stub_dir, package)) |
62 |
| - else: |
63 |
| - src_file = os.path.join("out", f"{package}.pyi") |
64 |
| - if not os.path.isfile(src_file): |
65 |
| - sys.exit("Error: Cannot find generated stubs") |
66 |
| - shutil.copy(src_file, stub_dir) |
| 48 | +def run_stubgen(package: str, output: str) -> None: |
| 49 | + print(f"Running stubgen: stubgen -o {output} -p {package}") |
| 50 | + subprocess.run(["stubgen", "-o", output, "-p", package], check=True) |
67 | 51 |
|
68 | 52 |
|
69 | 53 | def run_black(stub_dir: str) -> None:
|
@@ -106,7 +90,8 @@ def add_pyright_exclusion(stub_dir: str) -> None:
|
106 | 90 | assert i < len(lines), f"Error parsing {PYRIGHT_CONFIG}"
|
107 | 91 | while not lines[i].strip().startswith("]"):
|
108 | 92 | i += 1
|
109 |
| - line_to_add = f' "{stub_dir}",' |
| 93 | + # Must use forward slash in the .json file |
| 94 | + line_to_add = f' "{stub_dir}",'.replace("\\", "/") |
110 | 95 | initial = i - 1
|
111 | 96 | while lines[i].lower() > line_to_add.lower():
|
112 | 97 | i -= 1
|
@@ -171,10 +156,7 @@ def main() -> None:
|
171 | 156 | if os.path.exists(stub_dir):
|
172 | 157 | sys.exit(f"Error: {stub_dir} already exists (delete it first)")
|
173 | 158 |
|
174 |
| - run_stubgen(package) |
175 |
| - |
176 |
| - # Stubs were generated under out/. Copy them to stubs/. |
177 |
| - copy_stubs("out", package, stub_dir) |
| 159 | + run_stubgen(package, stub_dir) |
178 | 160 |
|
179 | 161 | run_isort(stub_dir)
|
180 | 162 | run_black(stub_dir)
|
|
0 commit comments