[checker] use 'python -m coverage' to run the coverage tool (closes #5186883)
authorDavid Douard <david.douard@logilab.fr>
Fri, 24 Jul 2015 15:15:14 +0200
changeset 1826 239805c9132d
parent 1825 b859e64fc3ee
child 1827 604c6af48cd6
[checker] use 'python -m coverage' to run the coverage tool (closes #5186883) so we do not depend on the way it is installed
_narval/checkers/apycot/python.py
--- a/_narval/checkers/apycot/python.py	Mon Apr 13 11:12:49 2015 +0200
+++ b/_narval/checkers/apycot/python.py	Fri Jul 24 15:15:14 2015 +0200
@@ -17,21 +17,13 @@
 from test import test_support
 from warnings import warn
 from lxml import etree
-
+import coverage
 
 from logilab.common.testlib import find_tests, DEFAULT_PREFIXES
 from logilab.common.modutils import get_module_files
 from logilab.common.decorators import cached
 from logilab.common.proc import RESOURCE_LIMIT_EXCEPTION
 
-try:
-    import coverage
-    if coverage.__version__ < "3":
-        raise ImportError
-    COVERAGE_CMD = "/usr/bin/python-coverage" # XXX
-except ImportError:
-    coverage = None
-
 from apycotlib import register
 from apycotlib import SUCCESS, FAILURE, PARTIAL, NODATA, ERROR
 from apycotlib import SimpleOutputParser, ParsedCommand
@@ -222,7 +214,7 @@
             self.record_version_info('python', ', '.join(pyversions(self.test)))
 
     def enable_coverage(self):
-        if self.options.get('pycoverage') and coverage:
+        if self.options.get('pycoverage'):
             self.coverage_data = join(self.cwd, '.coverage')
             # XXX we need the environment variable to be considered by
             # "python-coverage run"
@@ -393,7 +385,7 @@
     def get_command(self, command, python):
         python = [python, '-W', 'ignore']
         if self.enable_coverage():
-            python += [COVERAGE_CMD, 'run', '-a', '--branch',
+            python += ['-m', 'coverage', 'run', '-a', '--branch',
                        '--source=%s' % pyinstall_path(self.test)]
         return python + command
 
@@ -596,9 +588,8 @@
     }
 
     def version_info(self):
-        if coverage:
-            version = getoutput('%s --version' % COVERAGE_CMD).strip()
-            self.record_version_info('python-coverage', version)
+        version = getoutput('python -m coverage --version').strip()
+        self.record_version_info('python-coverage', version)
 
     def do_check(self, test):
         """run the checker against <path> (usually a directory)"""
@@ -628,8 +619,6 @@
         return writer
 
     def _get_cover_info(self, test):
-        if coverage is None:
-            raise Exception('install python-coverage')
         covertool = coverage.coverage()
         covertool.use_cache(self.options.get('coverage_data'))
         covertool.load()
@@ -661,8 +650,7 @@
         finally:
             return (pc_cover, br_rate)
 
-if coverage is not None:
-    register('checker', PyCoverageChecker)
+register('checker', PyCoverageChecker)
 
 
 class PyCheckerOutputParser(SimpleOutputParser):