diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | modutils.py | 18 | ||||
-rw-r--r-- | testlib.py | 3 |
3 files changed, 18 insertions, 7 deletions
@@ -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): @@ -1187,6 +1187,9 @@ succeeded test into", osp.join(os.getcwd(), FILE_RESTART) assertItemsEqual = unittest.TestCase.assertCountEqual else: assertCountEqual = unittest.TestCase.assertItemsEqual + if sys.version_info < (2,7): + def assertIsNotNone(self, value, *args, **kwargs): + self.assertNotEqual(None, value, *args, **kwargs) TestCase.assertItemsEqual = deprecated('assertItemsEqual is deprecated, use assertCountEqual')( TestCase.assertItemsEqual) |