diff options
author | Brett Cannon <brett@python.org> | 2011-02-26 13:29:40 -0800 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2011-02-26 13:29:40 -0800 |
commit | d4dd809d27ad7f31431a4ef61309b6951ad41d9b (patch) | |
tree | 125833eacbd53d3dac94fb0808e97601d8486100 | |
parent | fe825dfa906ee4c37e192c14d24b3abe78aa94d5 (diff) | |
download | python-coveragepy-d4dd809d27ad7f31431a4ef61309b6951ad41d9b.tar.gz |
Allow coverage.py to be executed by pointing Python at a repository's
directory.
Since Python 2.6 one can specify a __main__.py in a directory to tell
Python what to do if it is pointed at simply a directory. For
instance, assuming one has a clone of coverage.py sitting at
../coveragepy, this patch allows for::
python ../coveragepy run ...
This is extremely handy if you want to use coverage.py straight from a
clone without adding the clone's directory to sys.path (which can be
an issue at least in the stdlib as that will pick up 'test' as a
package, masking the stdlib's own 'test' package).
-rw-r--r-- | MANIFEST.in | 1 | ||||
-rw-r--r-- | __main__.py | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/MANIFEST.in b/MANIFEST.in index 65a60a0..19663a2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -9,3 +9,4 @@ include README.txt include CHANGES.txt include AUTHORS.txt prune test +prune __main__.py diff --git a/__main__.py b/__main__.py new file mode 100644 index 0000000..7ad6d73 --- /dev/null +++ b/__main__.py @@ -0,0 +1,16 @@ +"""Be able to execute coverage.py by pointing Python at the repository's +directory.""" +import os +import runpy + + +PKG = 'coverage' + +try: + run_globals = runpy.run_module(PKG, run_name='__main__', alter_sys=True) + executed = os.path.splitext(os.path.basename(run_globals['__file__']))[0] + if executed != '__main__': # For Python 2.5 compatibility + raise ImportError('Incorrectly executed %s instead of __main__' % + executed) +except ImportError: # For Python 2.6 compatibility + runpy.run_module('%s.__main__' % PKG, run_name='__main__', alter_sys=True) |