Commits

Philip Jenvey committed 8315612

unmonkeypatch the 2to3 preprocessor so we don't disturb subsequent runs
patch from mcdonc
fixes #2421

Comments (0)

Files changed (1)

     raise Exception("SQLAlchemy requires Python 2.4 or higher.")
 elif sys.version_info >= (3, 0):
     py3k = True
-    # monkeypatch our preprocessor
-    # onto the 2to3 tool.
-    from sa2to3 import refactor_string
-    from lib2to3.refactor import RefactoringTool
-    RefactoringTool.refactor_string = refactor_string
-
     if has_setuptools:
         extra.update(
             use_2to3=True,
             **kwargs
           )
 
+def monkeypatch2to3():
+    from sa2to3 import refactor_string
+    from lib2to3.refactor import RefactoringTool
+    RefactoringTool.old_refactor_string = RefactoringTool.refactor_string
+    RefactoringTool.refactor_string = refactor_string
+
+def unmonkeypatch2to3():
+    from lib2to3.refactor import RefactoringTool
+    if hasattr(RefactoringTool, 'old_refactor_string'):
+        RefactoringTool.refactor_string = RefactoringTool.old_refactor_string
+
 if pypy or jython or py3k:
-    run_setup(False)
+    if py3k:
+        # monkeypatch our preprocessor onto the 2to3 tool.
+        monkeypatch2to3()
+    try:
+        run_setup(False)
+    finally:
+        if py3k:
+            # unmonkeypatch to not stomp other setup.py's that are compiled
+            # and exec'd and which also require 2to3 fixing
+            unmonkeypatch2to3()
     status_msgs(
         "WARNING: C extensions are not supported on " +
             "this Python platform, speedups are not enabled.",
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.