Patchwork [3,of,8] import-checker: add socket for virtualenv

login
register
mail settings
Submitter timeless@mozdev.org
Date March 30, 2016, 9:24 a.m.
Message ID <b051243155761ace5b23.1459329843@waste.org>
Download mbox | patch
Permalink /patch/14180/
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 1459325194 0
#      Wed Mar 30 08:06:34 2016 +0000
# Node ID b051243155761ace5b23e98f8dd7a1b527ed1077
# Parent  044a54c5a3b80596f4c0c3625905248b7557691a
import-checker: add socket for virtualenv

zlib and BaseHTTPServer were within the virtualenv, but
socket and ctypes were in global space...

Adding socket seems to be enough to satisfy my virtualenv
Yuya Nishihara - March 31, 2016, 2:13 p.m.
On Wed, 30 Mar 2016 04:24:03 -0500, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1459325194 0
> #      Wed Mar 30 08:06:34 2016 +0000
> # Node ID b051243155761ace5b23e98f8dd7a1b527ed1077
> # Parent  044a54c5a3b80596f4c0c3625905248b7557691a
> import-checker: add socket for virtualenv
> 
> zlib and BaseHTTPServer were within the virtualenv, but
> socket and ctypes were in global space...
> 
> Adding socket seems to be enough to satisfy my virtualenv
> 
> diff --git a/contrib/import-checker.py b/contrib/import-checker.py
> --- a/contrib/import-checker.py
> +++ b/contrib/import-checker.py
> @@ -5,6 +5,7 @@
>  import ast
>  import collections
>  import os
> +import socket
>  import sys
>  
>  # Import a minimal set of stdlib modules needed for list_stdlib_modules()
> @@ -158,6 +159,9 @@
>      >>> 'BaseHTTPServer' in mods  
>      True
>  
> +    >>> 'socket' in mods
> +    True
> +
>      os.path isn't really a module, so it's missing:
>  
>      >>> 'os.path' in mods  
> @@ -177,6 +181,7 @@
>      """
>      for m in sys.builtin_module_names:
>          yield m
> +    modules = [socket, zlib]
>      # These modules only exist on windows, but we should always
>      # consider them stdlib.
>      for m in ['msvcrt', '_winreg']:
> @@ -187,7 +192,7 @@
>      stdlib_prefixes = set([sys.prefix, sys.exec_prefix])
>      # We need to supplement the list of prefixes for the search to work
>      # when run from within a virtualenv.
> -    for mod in (BaseHTTPServer, zlib):
> +    for mod in (modules):

I'm not sure why we can drop BaseHTTPServer from the modules list. Can you
elaborate?

Patch

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -5,6 +5,7 @@ 
 import ast
 import collections
 import os
+import socket
 import sys
 
 # Import a minimal set of stdlib modules needed for list_stdlib_modules()
@@ -158,6 +159,9 @@ 
     >>> 'BaseHTTPServer' in mods
     True
 
+    >>> 'socket' in mods
+    True
+
     os.path isn't really a module, so it's missing:
 
     >>> 'os.path' in mods
@@ -177,6 +181,7 @@ 
     """
     for m in sys.builtin_module_names:
         yield m
+    modules = [socket, zlib]
     # These modules only exist on windows, but we should always
     # consider them stdlib.
     for m in ['msvcrt', '_winreg']:
@@ -187,7 +192,7 @@ 
     stdlib_prefixes = set([sys.prefix, sys.exec_prefix])
     # We need to supplement the list of prefixes for the search to work
     # when run from within a virtualenv.
-    for mod in (BaseHTTPServer, zlib):
+    for mod in (modules):
         try:
             # Not all module objects have a __file__ attribute.
             filename = mod.__file__