Skip to content

Commit 1778d66

Browse files
authored
Add script that prints compiled files when self compiling (#19260)
Patch various things and run setup.py to get compilation targets without compiling anything. This can be useful for setting up a custom way of compiling mypy/mypyc.
1 parent 3456684 commit 1778d66

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

misc/self_compile_info.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Print list of files compiled when compiling self (mypy and mypyc)."""
2+
3+
import argparse
4+
import sys
5+
from typing import Any
6+
7+
import setuptools
8+
9+
import mypyc.build
10+
11+
12+
class FakeExtension:
13+
def __init__(self, *args: Any, **kwargs: Any) -> None:
14+
pass
15+
16+
17+
def fake_mypycify(args: list[str], **kwargs: Any) -> list[FakeExtension]:
18+
for target in sorted(args):
19+
if not target.startswith("-"):
20+
print(target)
21+
return [FakeExtension()]
22+
23+
24+
def fake_setup(*args: Any, **kwargs: Any) -> Any:
25+
pass
26+
27+
28+
def main() -> None:
29+
parser = argparse.ArgumentParser(
30+
description="Print list of files compiled when compiling self. Run in repository root."
31+
)
32+
parser.parse_args()
33+
34+
# Prepare fake state for running setup.py.
35+
mypyc.build.mypycify = fake_mypycify # type: ignore[assignment]
36+
setuptools.Extension = FakeExtension # type: ignore[misc, assignment]
37+
setuptools.setup = fake_setup
38+
sys.argv = [sys.argv[0], "--use-mypyc"]
39+
40+
# Run setup.py at the root of the repository.
41+
import setup # noqa: F401
42+
43+
44+
if __name__ == "__main__":
45+
main()

0 commit comments

Comments
 (0)