No Python source warning for namespace modules · Issue #572 · nedbat/coveragepy (original) (raw)

Originally reported by Christian Heimes (Bitbucket: tiran, GitHub: tiran)


setuptools no longer installs a __init__.py for namespace packages. Now I'm getting a warning Coverage.py warning: Module custudia has no Python source. for a namespace package called custodia. You can easily reproduce the issue with a git checkout of https://github.com/latchset/custodia:

Reproducer:

$ git clone https://github.com/latchset/custodia.git
$ cd custodia
$ tox -e py27
...
=================================================================================== 101 passed in 11.23 seconds ====================================================================================
Coverage.py warning: Module custodia has no Python source.
_____________________________________________________________________________________________ summary ______________________________________________________________________________________________
  py27: commands succeeded
  congratulations :)

On both Python 2 and 3, a namespace module has a __path__ attribute but no __file__ attribute. May I suggest that you omit the warning when a module has no __file__ but a __path__?

$ cd /tmp
$ mkdir nsexample
$ touch nsexample/module.py
$ python3
>>> import nsexample
>>> import nsexample.module
>>> dir(nsexample)
['__doc__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'module']
>>> dir(nsexample.module)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__']