10
10
import sys
11
11
import logging
12
12
import optparse
13
+ import os
13
14
14
15
from lib2to3 .main import warn , StdoutRefactoringTool
15
16
from lib2to3 import refactor
23
24
Usage: modernize [options] file|dir ...
24
25
""" % __version__
25
26
27
+
26
28
def format_usage (usage ):
27
29
"""Method that doesn't output "Usage:" prefix"""
28
30
return usage
29
31
32
+
30
33
def main (args = None ):
31
34
"""Main program.
32
35
@@ -41,11 +44,13 @@ def main(args=None):
41
44
parser .add_option ("--no-diffs" , action = "store_true" ,
42
45
help = "Don't show diffs of the refactoring." )
43
46
parser .add_option ("-l" , "--list-fixes" , action = "store_true" ,
44
- help = "List available transformations." )
47
+ help = "List standard transformations." )
45
48
parser .add_option ("-d" , "--doctests_only" , action = "store_true" ,
46
49
help = "Fix up doctests only." )
47
50
parser .add_option ("-f" , "--fix" , action = "append" , default = [],
48
51
help = "Each FIX specifies a transformation; '-f default' includes default fixers." )
52
+ parser .add_option ("--fixers-here" , action = "store_true" ,
53
+ help = "Add current working directory to python path (so fixers can be found)" )
49
54
parser .add_option ("-j" , "--processes" , action = "store" , default = 1 ,
50
55
type = "int" , help = "Run 2to3 concurrently." )
51
56
parser .add_option ("-x" , "--nofix" , action = "append" , default = [],
@@ -80,7 +85,7 @@ def main(args=None):
80
85
if not options .write and options .nobackups :
81
86
parser .error ("Can't use '-n' without '-w'." )
82
87
if options .list_fixes :
83
- print ("Available transformations for the -f/--fix and -x/--nofix options:" )
88
+ print ("Standard transformations available for the -f/--fix and -x/--nofix options:" )
84
89
for fixname in sorted (avail_fixes ):
85
90
print (" {} ({})" .format (fixname , fixname .split (".fix_" , 1 )[1 ]))
86
91
print ()
@@ -97,6 +102,8 @@ def main(args=None):
97
102
return 2
98
103
if options .print_function :
99
104
flags ["print_function" ] = True
105
+ if options .fixers_here :
106
+ sys .path .append (os .getcwd ())
100
107
101
108
# Set up logging handler
102
109
level = logging .DEBUG if options .verbose else logging .INFO
@@ -113,7 +120,8 @@ def main(args=None):
113
120
if tgt == fix or tgt .endswith (".fix_{}" .format (fix )):
114
121
matched = tgt
115
122
unwanted_fixes .add (matched )
116
- if matched is None :
123
+ break
124
+ else :
117
125
print ("Error: fix '{}' was not found" .format (fix ),
118
126
file = sys .stderr )
119
127
return 2
@@ -147,10 +155,10 @@ def main(args=None):
147
155
if tgt == fix or tgt .endswith (".fix_{}" .format (fix )):
148
156
matched = tgt
149
157
explicit .add (matched )
150
- if matched is None :
151
- print ( "Error: fix '{}' was not found" . format ( fix ),
152
- file = sys . stderr )
153
- return 2
158
+ break
159
+ else :
160
+ # A non-standard fix -- trust user to have supplied path
161
+ explicit . add ( fix )
154
162
requested = default_fixes .union (explicit ) if default_present else explicit
155
163
else :
156
164
requested = default_fixes
0 commit comments