[Python-checkins] closes bpo-37675: Use pkgutil.iter_modules to find fixers in a package rather than listdir. (14942)
Miss Islington (bot)
webhook-mailer at python.org
Wed Jul 24 19:59:35 EDT 2019
https://github.com/python/cpython/commit/53639dd55a0d5b3b7b4ef6ae839a98008f22e2d3
commit: 53639dd55a0d5b3b7b4ef6ae839a98008f22e2d3
branch: 2.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-07-24T16:59:31-07:00
summary:
closes bpo-37675: Use pkgutil.iter_modules to find fixers in a package rather than listdir. (14942)
(cherry picked from commit 93e8aa62cfd0a61efed4a61a2ffc2283ae986ef2)
Co-authored-by: Benjamin Peterson <benjamin at python.org>
files:
A Misc/NEWS.d/next/Tools-Demos/2019-07-24-16-20-54.bpo-37675.951Cvf.rst
M Lib/lib2to3/refactor.py
diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py
index 98386c5f310d..8a40deb8ac21 100644
--- a/Lib/lib2to3/refactor.py
+++ b/Lib/lib2to3/refactor.py
@@ -15,6 +15,7 @@
# Python imports
import os
+import pkgutil
import sys
import logging
import operator
@@ -33,13 +34,12 @@
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
index 000000000000..e28fa207f918
--- /dev/null
+++ b/Misc/NEWS.d/next/Tools-Demos/2019-07-24-16-20-54.bpo-37675.951Cvf.rst
@@ -0,0 +1 @@
+2to3 now works when run from a zipped standard library.
More information about the Python-checkins
mailing list