3232 makedirs ,
3333 walk ,
3434)
35- from os .path import isdir
35+ from os .path import (
36+ isdir ,
37+ isfile ,
38+ )
3639from pathlib import Path
3740from signal import SIGTERM
3841from textwrap import (
@@ -111,23 +114,24 @@ def guess_paths_to_mutate():
111114 """
112115 this_dir = os .getcwd ().split (os .sep )[- 1 ]
113116 if isdir ('lib' ):
114- return 'lib'
117+ return [ 'lib' ]
115118 elif isdir ('src' ):
116- return 'src'
119+ return [ 'src' ]
117120 elif isdir (this_dir ):
118- return this_dir
121+ return [ this_dir ]
119122 elif isdir (this_dir .replace ('-' , '_' )):
120- return this_dir .replace ('-' , '_' )
123+ return [ this_dir .replace ('-' , '_' )]
121124 elif isdir (this_dir .replace (' ' , '_' )):
122- return this_dir .replace (' ' , '_' )
125+ return [ this_dir .replace (' ' , '_' )]
123126 elif isdir (this_dir .replace ('-' , '' )):
124- return this_dir .replace ('-' , '' )
127+ return [ this_dir .replace ('-' , '' )]
125128 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' ]
127132 raise FileNotFoundError (
128133 '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.' )
131135
132136
133137def record_trampoline_hit (name ):
@@ -147,8 +151,7 @@ def record_trampoline_hit(name):
147151
148152
149153def walk_all_files ():
150- paths = [guess_paths_to_mutate ()]
151- for path in paths :
154+ for path in mutmut .config .paths_to_mutate :
152155 for root , dirs , files in walk (path ):
153156 for filename in files :
154157 yield root , filename
@@ -947,6 +950,7 @@ class Config:
947950 do_not_mutate : List [str ]
948951 max_stack_depth : int
949952 debug : bool
953+ paths_to_mutate : List [Path ]
950954
951955 def should_ignore_for_mutation (self , path ):
952956 if not str (path ).endswith ('.py' ):
@@ -1014,6 +1018,10 @@ def read_config():
10141018 ],
10151019 max_stack_depth = s ('max_stack_depth' , - 1 ),
10161020 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 ()
10171025 )
10181026
10191027
@@ -1203,6 +1211,7 @@ def run(mutant_names, *, max_children):
12031211 read_config ()
12041212
12051213 start = datetime .now ()
1214+ makedirs (Path ('mutants' ), exist_ok = True )
12061215 with CatchOutput (spinner_title = 'Generating mutants' ):
12071216 create_mutants ()
12081217 copy_also_copy_files ()
0 commit comments