Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit baa7865

Browse files
Add flag to install mypyc/lib-rt alongside mypy (#205)
* Add flag to install `mypyc/lib-rt` alongside mypy * comment --------- Co-authored-by: Shantanu <[email protected]>
1 parent 0ee3d63 commit baa7865

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

mypy_primer/globals.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class _Args:
1717
repo: str | None
1818
type_checker: str
1919
mypyc_compile_level: int | None
20+
mypy_install_librt: bool
2021
debug_build: bool
2122

2223
custom_typeshed_repo: str
@@ -103,6 +104,12 @@ def parse_options(argv: list[str]) -> _Args:
103104
type=int,
104105
help="Compile mypy with the given mypyc optimisation level",
105106
)
107+
type_checker_group.add_argument(
108+
"--mypy-install-librt",
109+
action="store_true",
110+
help="(Experimental) Whether to install the mypyc C runtime library "
111+
"(mypyc/lib-rt) when using mypy as the type checker",
112+
)
106113

107114
type_checker_group.add_argument(
108115
"--custom-typeshed-repo",

mypy_primer/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ def setup_type_checker(
4343

4444
if ARGS.type_checker == "mypy":
4545
setup_fn = setup_mypy
46-
kwargs = {"repo": ARGS.repo, "mypyc_compile_level": ARGS.mypyc_compile_level}
46+
kwargs = {
47+
"repo": ARGS.repo,
48+
"mypyc_compile_level": ARGS.mypyc_compile_level,
49+
"install_librt": ARGS.mypy_install_librt,
50+
}
4751
elif ARGS.type_checker == "pyright":
4852
setup_fn = setup_pyright
4953
kwargs = {"repo": ARGS.repo}
@@ -281,6 +285,7 @@ async def bisect(ARGS: _Args) -> None:
281285
repo=ARGS.repo,
282286
mypyc_compile_level=ARGS.mypyc_compile_level,
283287
editable=True, # important
288+
install_librt=ARGS.mypy_install_librt,
284289
)
285290
repo_dir = ARGS.base_dir / "bisect_mypy" / "mypy"
286291
elif ARGS.type_checker == "pyright":

mypy_primer/type_checker.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ async def setup_mypy(
1818
repo: str | None,
1919
mypyc_compile_level: int | None,
2020
editable: bool = False,
21+
install_librt: bool = False,
2122
) -> Path:
2223
mypy_dir.mkdir(exist_ok=True)
2324
venv = Venv(mypy_dir / "venv")
@@ -36,6 +37,7 @@ async def pip_install(*targets: str) -> None:
3637
if isinstance(revision_like, str) and not editable and repo is None:
3738
# optimistically attempt to install the revision of mypy we want from pypi
3839
try:
40+
# TODO: support installing lib-rt when installing mypy from pypi?
3941
await pip_install(f"mypy=={revision_like}")
4042
install_from_repo = False
4143
except subprocess.CalledProcessError:
@@ -79,6 +81,19 @@ async def pip_install(*targets: str) -> None:
7981
targets.append("pathspec")
8082
await pip_install(*targets)
8183

84+
if install_librt:
85+
try:
86+
await run(
87+
[str(venv.python), "-m", "pip", "install", "./mypyc/lib-rt"],
88+
cwd=repo_dir,
89+
output=True,
90+
)
91+
except subprocess.CalledProcessError as e:
92+
print("Error while building lib-rt", file=sys.stderr)
93+
print(e.stdout, file=sys.stderr)
94+
print(e.stderr, file=sys.stderr)
95+
raise e
96+
8297
with open(venv.site_packages / "primer_plugin.pth", "w") as f:
8398
# pth file that lets us let mypy import plugins from another venv
8499
# importantly, this puts the plugin paths at the back of sys.path, so they cannot

0 commit comments

Comments
 (0)