]> granicus.if.org Git - python/commitdiff
closes bpo-37675: Use pkgutil.iter_modules to find fixers in a package rather than...
authorBenjamin Peterson <benjamin@python.org>
Wed, 24 Jul 2019 23:38:50 +0000 (16:38 -0700)
committerGitHub <noreply@github.com>
Wed, 24 Jul 2019 23:38:50 +0000 (16:38 -0700)
Lib/lib2to3/refactor.py
Misc/NEWS.d/next/Tools-Demos/2019-07-24-16-20-54.bpo-37675.951Cvf.rst [new file with mode: 0644]

index 7841b99a5cd4c1ee7dcc48b405a1c8edb4340739..55fd60fa27c3da9ba0eed4fff1c472aac62e5d9d 100644 (file)
@@ -14,6 +14,7 @@ __author__ = "Guido van Rossum <guido@python.org>"
 # Python imports
 import io
 import os
+import pkgutil
 import sys
 import logging
 import operator
@@ -30,13 +31,12 @@ from . import btm_matcher as bm
 def get_all_fix_names(fixer_pkg, remove_prefix=True):
     """Return a sorted list of all available fix names in the given package."""
     pkg = __import__(fixer_pkg, [], [], ["*"])
-    fixer_dir = os.path.dirname(pkg.__file__)
     fix_names = []
-    for name in sorted(os.listdir(fixer_dir)):
-        if name.startswith("fix_") and name.endswith(".py"):
+    for finder, name, ispkg in pkgutil.iter_modules(pkg.__path__):
+        if name.startswith("fix_"):
             if remove_prefix:
                 name = name[4:]
-            fix_names.append(name[:-3])
+            fix_names.append(name)
     return fix_names
 
 
diff --git a/Misc/NEWS.d/next/Tools-Demos/2019-07-24-16-20-54.bpo-37675.951Cvf.rst b/Misc/NEWS.d/next/Tools-Demos/2019-07-24-16-20-54.bpo-37675.951Cvf.rst
new file mode 100644 (file)
index 0000000..e28fa20
--- /dev/null
@@ -0,0 +1 @@
+2to3 now works when run from a zipped standard library.