[modutils] don't propagate IOError when package's __init__.py file doesn't exist. Closes #174606

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changesetbf74411c45cb
branchdefault
phasepublic
hiddenno
parent revision#b0fb76389fbc testlib: assertIsNotNone missing for python 2.6
child revision#27140e34942b Backport fix done by Benedikt Morbach on pylint for python3 install on win32 platforms / cross compilation. Closes #180836, #34363df41323 fix assertIsNotNone py< 2.7 implementation, #ab88a0a73cfa Backport fix done by Tobias Rzepka on pylint for python3 install on win32 platforms. Closes #180836
files modified by this revision
ChangeLog
modutils.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1378196089 -7200
# Tue Sep 03 10:14:49 2013 +0200
# Node ID bf74411c45cb4c20fc40953ba67e897438fb1839
# Parent b0fb76389fbcdb8956582151af07e4d69b85837b
[modutils] don't propagate IOError when package's __init__.py file doesn't exist. Closes #174606

diff --git a/ChangeLog b/ChangeLog
@@ -1,8 +1,12 @@
1  ChangeLog for logilab.common
2  ============================
3 
4 +--
5 +   * modutils: don't propagate IOError when package's __init__.py file doesn't
6 +     exist (#174606)
7 +
8  2013-07-26  --  0.60.0
9      * configuration: rename option_name method into option_attrname (#140667)
10 
11      * deprecation: new DeprecationManager class (closes #108205)
12 
diff --git a/modutils.py b/modutils.py
@@ -654,18 +654,22 @@
13              if mtype != PKG_DIRECTORY:
14                  raise ImportError('No module %s in %s' % ('.'.join(modpath),
15                                                            '.'.join(imported)))
16              # XXX guess if package is using pkgutil.extend_path by looking for
17              # those keywords in the first four Kbytes
18 -            data = open(join(mp_filename, '__init__.py')).read(4096)
19 -            if 'pkgutil' in data and 'extend_path' in data:
20 -                # extend_path is called, search sys.path for module/packages of this name
21 -                # see pkgutil.extend_path documentation
22 -                path = [join(p, modname) for p in sys.path
23 -                        if isdir(join(p, modname))]
24 +            try:
25 +                data = open(join(mp_filename, '__init__.py')).read(4096)
26 +            except IOError:
27 +                path = [mp_filename]
28              else:
29 -                path = [mp_filename]
30 +                if 'pkgutil' in data and 'extend_path' in data:
31 +                    # extend_path is called, search sys.path for module/packages
32 +                    # of this name see pkgutil.extend_path documentation
33 +                    path = [join(p, modname) for p in sys.path
34 +                            if isdir(join(p, modname))]
35 +                else:
36 +                    path = [mp_filename]
37      return mtype, mp_filename
38 
39  def _is_python_file(filename):
40      """return true if the given filename should be considered as a python file
41