32
32
makedirs ,
33
33
walk ,
34
34
)
35
- from os .path import isdir
35
+ from os .path import (
36
+ isdir ,
37
+ isfile ,
38
+ )
36
39
from pathlib import Path
37
40
from signal import SIGTERM
38
41
from textwrap import (
@@ -111,23 +114,24 @@ def guess_paths_to_mutate():
111
114
"""
112
115
this_dir = os .getcwd ().split (os .sep )[- 1 ]
113
116
if isdir ('lib' ):
114
- return 'lib'
117
+ return [ 'lib' ]
115
118
elif isdir ('src' ):
116
- return 'src'
119
+ return [ 'src' ]
117
120
elif isdir (this_dir ):
118
- return this_dir
121
+ return [ this_dir ]
119
122
elif isdir (this_dir .replace ('-' , '_' )):
120
- return this_dir .replace ('-' , '_' )
123
+ return [ this_dir .replace ('-' , '_' )]
121
124
elif isdir (this_dir .replace (' ' , '_' )):
122
- return this_dir .replace (' ' , '_' )
125
+ return [ this_dir .replace (' ' , '_' )]
123
126
elif isdir (this_dir .replace ('-' , '' )):
124
- return this_dir .replace ('-' , '' )
127
+ return [ this_dir .replace ('-' , '' )]
125
128
elif isdir (this_dir .replace (' ' , '' )):
126
- return this_dir .replace (' ' , '' )
129
+ return [this_dir .replace (' ' , '' )]
130
+ if isfile (this_dir + '.py' ):
131
+ return [this_dir + '.py' ]
127
132
raise FileNotFoundError (
128
133
'Could not figure out where the code to mutate is. '
129
- 'Please specify it on the command line using --paths-to-mutate, '
130
- 'or by adding "paths_to_mutate=code_dir" in setup.cfg to the [mutmut] section.' )
134
+ 'Please specify it by adding "paths_to_mutate=code_dir" in setup.cfg to the [mutmut] section.' )
131
135
132
136
133
137
def record_trampoline_hit (name ):
@@ -147,8 +151,7 @@ def record_trampoline_hit(name):
147
151
148
152
149
153
def walk_all_files ():
150
- paths = [guess_paths_to_mutate ()]
151
- for path in paths :
154
+ for path in mutmut .config .paths_to_mutate :
152
155
for root , dirs , files in walk (path ):
153
156
for filename in files :
154
157
yield root , filename
@@ -947,6 +950,7 @@ class Config:
947
950
do_not_mutate : List [str ]
948
951
max_stack_depth : int
949
952
debug : bool
953
+ paths_to_mutate : List [Path ]
950
954
951
955
def should_ignore_for_mutation (self , path ):
952
956
if not str (path ).endswith ('.py' ):
@@ -1014,6 +1018,10 @@ def read_config():
1014
1018
],
1015
1019
max_stack_depth = s ('max_stack_depth' , - 1 ),
1016
1020
debug = s ('debug' , False ),
1021
+ paths_to_mutate = [
1022
+ Path (y )
1023
+ for y in s ('paths_to_mutate' , [])
1024
+ ] or guess_paths_to_mutate ()
1017
1025
)
1018
1026
1019
1027
@@ -1203,6 +1211,7 @@ def run(mutant_names, *, max_children):
1203
1211
read_config ()
1204
1212
1205
1213
start = datetime .now ()
1214
+ makedirs (Path ('mutants' ), exist_ok = True )
1206
1215
with CatchOutput (spinner_title = 'Generating mutants' ):
1207
1216
create_mutants ()
1208
1217
copy_also_copy_files ()
0 commit comments