Skip to content

Commit 6b58255

Browse files
committed
🔨 fix StopIteration in tool/stubtest.py if no .venv exists
1 parent 7152a7d commit 6b58255

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

‎tool/stubtest.py‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@
3030
CWD = Path.cwd()
3131
TOOL_DIR = Path(__file__).parent
3232
SITE_DIR = Path(sysconfig.get_paths()["purelib"])
33-
ROOT_DIR = TOOL_DIR.parent
34-
3533

36-
ROOT_SITE_DIR = (
37-
ROOT_DIR / ".venv" / "Lib" / "site-packages"
38-
if sys.platform == "win32"
39-
else next((ROOT_DIR / ".venv" / "lib").glob("*/site-packages"))
40-
)
34+
ROOT_DIR = TOOL_DIR.parent
35+
if (ROOT_DIR / ".venv").is_dir():
36+
__root_venv = ROOT_DIR / ".venv"
37+
__root_site = (
38+
__root_venv / "Lib" / "site-packages"
39+
if sys.platform == "win32"
40+
else next((__root_venv / "lib").glob("*/site-packages"))
41+
)
42+
else:
43+
__root_site = None
44+
ROOT_SITE_DIR = __root_site
4145

4246
ALLOWLISTS = [
4347
"common.txt",
@@ -130,9 +134,10 @@ def _rewrite_mypy_output(line: bytes, /) -> bytes:
130134
if package_lib in line:
131135
line = line.replace(package_lib, package_src)
132136

133-
site_dir = str(SITE_DIR).encode()
134-
if site_dir in line:
135-
line = line.replace(site_dir, str(ROOT_SITE_DIR.relative_to(CWD)).encode())
137+
if ROOT_SITE_DIR is not None:
138+
site_dir = str(SITE_DIR).encode()
139+
if site_dir in line:
140+
line = line.replace(site_dir, str(ROOT_SITE_DIR.relative_to(CWD)).encode())
136141

137142
return line
138143

0 commit comments

Comments
 (0)