[PATCH 7 of 8] import-checker: fix list_stdlib_modules for Python3

timeless timeless at mozdev.org
Wed Mar 30 05:24:07 EDT 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1459325685 0
#      Wed Mar 30 08:14:45 2016 +0000
# Node ID b0d9bcd93d81e0683d8c980273055f9f4289a9b4
# Parent  d8be8db8119d2d716ad9ddaaaa077cf278f6273c
import-checker: fix list_stdlib_modules for Python3

Walking through Python3's available module list, will not find cPickle,
no matter how hard we try.

This is a sorted list of modules (Python2 and Python3).

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -11,7 +11,6 @@
 # Import a minimal set of stdlib modules needed for list_stdlib_modules()
 # to work when run from a virtualenv.  The modules were chosen empirically
 # so that the return value matches the return value without virtualenv.
-import BaseHTTPServer
 import zlib
 
 # Whitelist of modules that symbols can be directly imported from.
@@ -182,6 +181,138 @@
     for m in sys.builtin_module_names:
         yield m
     modules = [socket, zlib]
+    try:
+        import BaseHTTPServer
+        modules.append(BaseHTTPServer)
+    except ImportError:
+        # Python3
+        for m in ([
+            "argparse",
+            "array",
+            "atexit",
+            "base64",
+            "BaseHTTPServer",
+            "binascii",
+            "bisect",
+            "__builtin__",
+            "builtins",
+            "bz2",
+            "calendar",
+            "cgi",
+            "cmd",
+            "codecs",
+            "collections",
+            "commands",
+            "ConfigParser",
+            "contextlib",
+            "Cookie",
+            "copy",
+            "cPickle",
+            "cProfile",
+            "cStringIO",
+            "csv",
+            "datetime",
+            "dbm",
+            "decimal",
+            "difflib",
+            "dircache",
+            "dis",
+            "doctest",
+            "email",
+            "errno",
+            "exceptions",
+            "fcntl",
+            "filecmp",
+            "fnmatch",
+            "fractions",
+            "ftplib",
+            "functools",
+            "gc",
+            "getopt",
+            "getpass",
+            "gettext",
+            "glob",
+            "grp",
+            "gzip",
+            "hashlib",
+            "heapq",
+            "imp",
+            "inspect",
+            "io",
+            "itertools",
+            "json",
+            "locale",
+            "logging",
+            "mailbox",
+            "math",
+            "mimetypes",
+            "mmap",
+            "multiprocessing",
+            "operator",
+            "optparse",
+            "os",
+            "pathlib",
+            "pdb",
+            "pickle",
+            "pipes",
+            "pkgutil",
+            "platform",
+            "pprint",
+            "profile",
+            "pwd",
+            "pydoc",
+            "Queue",
+            "queue",
+            "quopri",
+            "random",
+            "re",
+            "readline",
+            "resource",
+            "sched",
+            "select",
+            "shelve",
+            "shlex",
+            "shutil",
+            "signal",
+            "site",
+            "sitecustomize",
+            "smtpd",
+            "smtplib",
+            "socket",
+            "SocketServer",
+            "ssl",
+            "statistics",
+            "string",
+            "StringIO",
+            "struct",
+            "subprocess",
+            "sys",
+            "sysconfig",
+            "tarfile",
+            "tempfile",
+            "textwrap",
+            "thread",
+            "threading",
+            "time",
+            "timeit",
+            "trace",
+            "traceback",
+            "unicodedata",
+            "unittest",
+            "urllib",
+            "urllib2",
+            "urlparse",
+            "uuid",
+            "warnings",
+            "weakref",
+            "xml",
+            "xmlrpclib",
+            "zipfile",
+            "zipimport",
+            "zlib",
+        ]):
+            yield m
+    yield "ctypes"
     # These modules only exist on windows, but we should always
     # consider them stdlib.
     for m in ['msvcrt', '_winreg']:


More information about the Mercurial-devel mailing list