--- /home/haypo/prog/Python-3.0b2/Lib/lib2to3/refactor.py 2008-06-18 01:16:28.000000000 +0200 +++ /opt/py3k/lib/python3.0/lib2to3/refactor.py 2008-08-14 17:53:32.000000000 +0200 @@ -55,6 +55,13 @@ parser.add_option("-w", "--write", action="store_true", help="Write back modified files") + fixer_pkg = fixer_dir.replace(os.path.sep, ".") + if os.path.altsep: + fixer_pkg = fixer_pkg.replace(os.path.altsep, ".") + if not os.path.isabs(fixer_dir): + mod = __import__(fixer_pkg, {}, {}, ["*"]) + fixer_dir = os.path.dirname(mod.__file__) + # Parse command line arguments options, args = parser.parse_args(args) if options.list_fixes: @@ -78,7 +85,7 @@ logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO) # Initialize the refactoring tool - rt = RefactoringTool(fixer_dir, options) + rt = RefactoringTool(fixer_dir, fixer_pkg, options) # Refactor all files and directories passed as arguments if not rt.errors: @@ -140,7 +147,7 @@ class RefactoringTool(object): - def __init__(self, fixer_dir, options): + def __init__(self, fixer_dir, fixer_pkg, options): """Initializer. Args: @@ -148,6 +155,7 @@ options: an optparse.Values instance. """ self.fixer_dir = fixer_dir + self.fixer_pkg = fixer_pkg self.options = options self.errors = [] self.logger = logging.getLogger("RefactoringTool") @@ -172,9 +180,6 @@ want a pre-order AST traversal, and post_order is the list that want post-order traversal. """ - fixer_pkg = self.fixer_dir.replace(os.path.sep, ".") - if os.path.altsep: - fixer_pkg = fixer_pkg.replace(os.path.altsep, ".") pre_order_fixers = [] post_order_fixers = [] fix_names = self.options.fix @@ -182,7 +187,7 @@ fix_names = get_all_fix_names(self.fixer_dir) for fix_name in fix_names: try: - mod = __import__(fixer_pkg + ".fix_" + fix_name, {}, {}, ["*"]) + mod = __import__(self.fixer_pkg + ".fix_" + fix_name, {}, {}, ["*"]) except ImportError: self.log_error("Can't find transformation %s", fix_name) continue