Manually reading module source when inspect fails.
Apparently inspect.getsource() can fail if a module is empty. So when it does
fail, we manually attempt to read the source.
@@ -34,7 +34,10 @@ def get_ast(module):
if source_file.endswith('__init__.py'):
source = ''
else:
- LOG.warning("Unable to read source for module %s", module)
- raise
+ LOG.info('inspect.getsource() failed.'
+ 'Attempting to read source directly: %s',
+ module)
+ with open(source_file, mode='rt') as f:
+ source = f.read()
return ast.parse(source, source_file, 'exec')
