Skip to content
Browse files

Small code cleanups

  • Loading branch information...
1 parent fd525fc commit 33b149e356188ba56853cc65a1f75ac5f1a356d7 @bdarnell committed Feb 23, 2011
Showing with 7 additions and 10 deletions.
  1. +7 −10 auto2to3.py
View
17 auto2to3.py
@@ -28,8 +28,6 @@
import lib2to3
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
-sys.path.append(os.path.dirname(lib2to3.__file__))
-
fixes = get_fixers_from_package('lib2to3.fixes')
rt = RefactoringTool(fixes)
@@ -51,21 +49,20 @@ def find_module(self, fullname, path=None):
return None
if file and etc[2] == imp.PY_SOURCE:
if any(fullname.startswith(p) for p in PACKAGES):
- outfile = '/tmp/auto2to3-%s.py' % fullname
- if (not os.path.exists(outfile) or
- os.stat(filename).st_mtime > os.stat(outfile).st_mtime):
+ outfilename = '/tmp/auto2to3-%s.py' % fullname
+ if (not os.path.exists(outfilename) or
+ os.stat(filename).st_mtime > os.stat(outfilename).st_mtime):
try:
contents = file.read()
contents = rt.refactor_docstring(contents, filename)
tree = rt.refactor_string(contents, filename)
except Exception as err:
raise ImportError("2to3 couldn't convert %r" % filename)
- finally:
- file.close()
- file = open(outfile, 'wb')
- file.write(str(tree).encode('utf8'))
+ outfile = open(outfilename, 'wb')
+ outfile.write(str(tree).encode('utf8'))
+ outfile.close()
file.close()
- filename = outfile
+ filename = outfilename
file = open(filename, 'rb')
return ImpLoader(fullname, file, filename, etc)

0 comments on commit 33b149e

Please sign in to comment.
Something went wrong with that request. Please try again.