Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add command-line interface. Discover that auto2to3 doesn't work in 3.2.

  • Loading branch information...
commit 54ba6e9b685709775373b8bcaf3ffb463dc2c417 1 parent d2e4306
@bdarnell authored
Showing with 16 additions and 0 deletions.
  1. +16 −0 auto2to3.py
View
16 auto2to3.py 100644 → 100755
@@ -1,14 +1,17 @@
+#!/usr/bin/env python3.2
#
# Import hook to run 2to3 transparently over imported files.
# Only works with files that have 'python2' in the first or second line.
#
+import argparse
import os
import sys
import imp
import runpy
from io import StringIO
from pkgutil import ImpImporter, ImpLoader
+import runpy
import tempfile
import lib2to3
@@ -25,6 +28,7 @@ def __getattr__(self, name):
rt = RefactoringTool(opt)
+PACKAGES = []
class ToThreeImporter(ImpImporter):
def find_module(self, fullname, path=None):
@@ -64,3 +68,15 @@ def find_module(self, fullname, path=None):
for key in sys.path_importer_cache:
if sys.path_importer_cache[key] is None:
sys.path_importer_cache[key] = ToThreeImporter(key)
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--package', action='append')
+ parser.add_argument('main')
+ args = parser.parse_args()
+ if args.package:
+ PACKAGES.extend(args.package)
+ runpy.run_module(args.main)
+
+if __name__ == '__main__':
+ main()
Please sign in to comment.
Something went wrong with that request. Please try again.