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

login
register
mail settings
Submitter timeless@mozdev.org
Date March 30, 2016, 9:24 a.m.
Message ID <b0d9bcd93d81e0683d8c.1459329847@waste.org>
Download mbox | patch
Permalink /patch/14184/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

timeless@mozdev.org - March 30, 2016, 9:24 a.m.
# HG changeset patch
# User timeless <timeless@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).
Yuya Nishihara - March 31, 2016, 2:43 p.m.
On Wed, 30 Mar 2016 04:24:07 -0500, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@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 ([

I'm not saying no for this, but I'm not sure if we want to maintain this list.

Also, from the comment, it's hard to notice this is the list of modules in
Python2+Python3.

Patch

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']: