Patchwork [2,of,2] import-checker: list package directory as stdlib module

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 4, 2016, 2:58 p.m.
Message ID <be0ee519b7a6a26839a7.1451919505@mimosa>
Download mbox | patch
Permalink /patch/12507/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 4, 2016, 2:58 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1451227034 -32400
#      Sun Dec 27 23:37:14 2015 +0900
# Node ID be0ee519b7a6a26839a712d3b481ca5b14aae187
# Parent  937c6a6dac98baaed78a5052890bc630e09b6848
import-checker: list package directory as stdlib module

Before this patch, a directory containing __init__.py wasn't counted as a
module and __init__.pyc was listed as foo.bar.__init__ module.

Patch

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -179,9 +179,6 @@  def list_stdlib_modules():
     # consider them stdlib.
     for m in ['msvcrt', '_winreg']:
         yield m
-    # These get missed too
-    for m in 'ctypes', 'email', 'logging', 'multiprocessing':
-        yield m
     yield 'builtins' # python3 only
     for m in 'fcntl', 'grp', 'pwd', 'termios':  # Unix only
         yield m
@@ -214,11 +211,12 @@  def list_stdlib_modules():
                     or top == libpath and d in ('hgext', 'mercurial')):
                     del dirs[i]
             for name in files:
-                if name == '__init__.py':
-                    continue
                 if not name.endswith(('.py', '.so', '.pyc', '.pyo', '.pyd')):
                     continue
-                full_path = os.path.join(top, name)
+                if name.startswith('__init__.py'):
+                    full_path = top
+                else:
+                    full_path = os.path.join(top, name)
                 rel_path = full_path[len(libpath) + 1:]
                 mod = dotted_name_of_path(rel_path)
                 yield mod