MCPcopy Index your code
hub / github.com/python/mypy / run_setup

Function run_setup

mypyc/test/test_run.py:113–145  ·  view source on GitHub ↗

Run a setup script in a somewhat controlled environment. This is adapted from code in distutils and our goal here is that is faster to not need to spin up a python interpreter to run it. We had to fork it because the real run_setup swallows errors and KeyboardInterrupt with no way

(script_name: str, script_args: list[str])

Source from the content-addressed store, hash-verified

111
112
113def run_setup(script_name: str, script_args: list[str]) -> bool:
114 """Run a setup script in a somewhat controlled environment.
115
116 This is adapted from code in distutils and our goal here is that is
117 faster to not need to spin up a python interpreter to run it.
118
119 We had to fork it because the real run_setup swallows errors
120 and KeyboardInterrupt with no way to recover them (!).
121 The real version has some extra features that we removed since
122 we weren't using them.
123
124 Returns whether the setup succeeded.
125 """
126 save_argv = sys.argv.copy()
127 g = {"__file__": script_name}
128 try:
129 try:
130 sys.argv[0] = script_name
131 sys.argv[1:] = script_args
132 with open(script_name, "rb") as f:
133 exec(f.read(), g)
134 finally:
135 sys.argv = save_argv
136 except SystemExit as e:
137 # distutils converts KeyboardInterrupt into a SystemExit with
138 # "interrupted" as the argument. Convert it back so that
139 # pytest will exit instead of just failing the test.
140 if e.code == "interrupted":
141 raise KeyboardInterrupt from e
142
143 return e.code == 0 or e.code is None
144
145 return True
146
147
148@contextlib.contextmanager

Callers 1

run_case_stepMethod · 0.85

Calls 2

copyMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…