summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--modutils.py18
2 files changed, 15 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index ffb718e..b1614dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,10 @@
ChangeLog for logilab.common
============================
+--
+ * modutils: don't propagate IOError when package's __init__.py file doesn't
+ exist (#174606)
+
2013-07-26 -- 0.60.0
* configuration: rename option_name method into option_attrname (#140667)
diff --git a/modutils.py b/modutils.py
index 9d0bb49..e9615d5 100644
--- a/modutils.py
+++ b/modutils.py
@@ -656,14 +656,18 @@ def _module_file(modpath, path=None):
'.'.join(imported)))
# XXX guess if package is using pkgutil.extend_path by looking for
# those keywords in the first four Kbytes
- data = open(join(mp_filename, '__init__.py')).read(4096)
- if 'pkgutil' in data and 'extend_path' in data:
- # extend_path is called, search sys.path for module/packages of this name
- # see pkgutil.extend_path documentation
- path = [join(p, modname) for p in sys.path
- if isdir(join(p, modname))]
- else:
+ try:
+ data = open(join(mp_filename, '__init__.py')).read(4096)
+ except IOError:
path = [mp_filename]
+ else:
+ if 'pkgutil' in data and 'extend_path' in data:
+ # extend_path is called, search sys.path for module/packages
+ # of this name see pkgutil.extend_path documentation
+ path = [join(p, modname) for p in sys.path
+ if isdir(join(p, modname))]
+ else:
+ path = [mp_filename]
return mtype, mp_filename
def _is_python_file(filename):