Skip to content

Commit 4c04b1c

Browse files
committed
[mypyc] Add hidden flag to skip the generation of C files
This can be useful when debugging mypyc issues. For example, you can manually add some debug prints into the generated C and rerun mypyc with `--skip-c-gen`. Now mypyc will build the code again, with your manual changes included (this assumes everything else is the same as during the previous run). There are not plans currently to advertise this as an end-user feature.
1 parent 380cb8d commit 4c04b1c

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

mypy/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,11 @@ def add_invertible_flag(
11281128
report_group.add_argument(
11291129
"-a", dest="mypyc_annotation_file", type=str, default=None, help=argparse.SUPPRESS
11301130
)
1131+
# Hidden mypyc feature: do not write any C files (keep existing ones and assume they exist).
1132+
# This can be useful when debugging mypyc bugs.
1133+
report_group.add_argument(
1134+
"--skip-c-gen", dest="mypyc_skip_c_generation", action="store_true", help=argparse.SUPPRESS
1135+
)
11311136

11321137
other_group = parser.add_argument_group(title="Miscellaneous")
11331138
other_group.add_argument("--quickstart-file", help=argparse.SUPPRESS)

mypy/options.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ def __init__(self) -> None:
408408

409409
# Output html file for mypyc -a
410410
self.mypyc_annotation_file: str | None = None
411+
# Skip writing C output files, but perform all other steps of a build (allows
412+
# preserving manual tweaks to generated C file)
413+
self.mypyc_skip_c_generation: bool = False
411414

412415
def use_lowercase_names(self) -> bool:
413416
if self.python_version >= (3, 9):

mypyc/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ def mypyc_build(
452452
cfilenames = []
453453
for cfile, ctext in cfiles:
454454
cfile = os.path.join(compiler_options.target_dir, cfile)
455-
write_file(cfile, ctext)
455+
if not options.mypyc_skip_c_generation:
456+
write_file(cfile, ctext)
456457
if os.path.splitext(cfile)[1] == ".c":
457458
cfilenames.append(cfile)
458459

0 commit comments

Comments
 (0)