Skip to content

Commit 210bb5d

Browse files
committed
Ignore files that can't be parsed due to parso not supporting some modern python syntax
1 parent 708493f commit 210bb5d

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

mutmut/__main__.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343
)
4444

4545
import click
46-
from parso import parse
46+
from parso import (
47+
parse,
48+
ParserSyntaxError,
49+
)
4750
from setproctitle import setproctitle
4851

4952
import mutmut
@@ -181,10 +184,10 @@ def _mutmut_trampoline(orig, mutants, *args, **kwargs):
181184
import os
182185
mutant_under_test = os.environ['MUTANT_UNDER_TEST']
183186
if mutant_under_test == 'fail':
184-
from __main__ import MutmutProgrammaticFailException
187+
from mutmut.__main__ import MutmutProgrammaticFailException
185188
raise MutmutProgrammaticFailException('Failed programmatically')
186189
elif mutant_under_test == 'stats':
187-
from __main__ import record_trampoline_hit
190+
from mutmut.__main__ import record_trampoline_hit
188191
record_trampoline_hit(orig.__module__ + '.' + orig.__name__)
189192
return orig(*args, **kwargs)
190193
prefix = orig.__module__ + '.' + orig.__name__ + '__mutmut_'
@@ -239,7 +242,7 @@ def create_mutants_for_file(filename, output_path):
239242
source = f.read()
240243

241244
with open(output_path, 'w') as out:
242-
mutant_names, hash_by_function_name = write_all_mutants_to_file(out=out, source=source)
245+
mutant_names, hash_by_function_name = write_all_mutants_to_file(out=out, source=source, filename=filename)
243246

244247
# validate no syntax errors of mutants
245248
with open(output_path) as f:
@@ -269,13 +272,20 @@ def ensure_ends_with_newline(source):
269272
return source
270273

271274

272-
def write_all_mutants_to_file(*, out, source):
275+
def write_all_mutants_to_file(*, out, source, filename):
273276
no_mutate_lines = pragma_no_mutate_lines(source)
274277

275278
hash_by_function_name = {}
276279
mutant_names = []
277280

278-
for type_, x, name_and_hash, mutant_name in yield_mutants_for_module(parse(ensure_ends_with_newline(source), error_recovery=False), no_mutate_lines):
281+
try:
282+
ast = parse(ensure_ends_with_newline(source), error_recovery=False)
283+
except ParserSyntaxError:
284+
print(f'Warning: unsupported syntax in {filename}, skipping')
285+
out.write(source)
286+
return [], {}
287+
288+
for type_, x, name_and_hash, mutant_name in yield_mutants_for_module(ast, no_mutate_lines):
279289
out.write(x)
280290
if mutant_name:
281291
mutant_names.append(mutant_name)

0 commit comments

Comments
 (0)