Chromium Code Reviews| Index: scripts/slave/unittests/test_env.py |
| diff --git a/scripts/slave/unittests/test_env.py b/scripts/slave/unittests/test_env.py |
| index f299b6f780c55ff28d36a3a6fe0f07718975122c..832b4bc79942c66d5fbe6d45320eeeb6c95bbb60 100644 |
| --- a/scripts/slave/unittests/test_env.py |
| +++ b/scripts/slave/unittests/test_env.py |
| @@ -22,22 +22,46 @@ sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'buildbot_slave_8_4')) |
| sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'twisted_10_2')) |
| sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'mock-1.0.1')) |
| -try: |
| - # The C-compiled coverage engine is WAY faster than the pure python version. |
| - # If we have it, then don't bother with the pure python one. |
| - import coverage |
| -except ImportError: |
| - sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'coverage-3.6')) |
| - import coverage |
| - |
| -def print_coverage_warning(): |
| - if not hasattr(coverage.collector, 'CTracer'): |
| - print "WARNING: Using the pure-python coverage module." |
| - print " Install the native python coverage module to speed recipe" |
| - print " training up by an order of magnitude." |
| - print " pip install coverage" |
| - print " OR" |
| - print " easy_install coverage" |
| +def ensure_coverage_importable(): |
| + try: |
| + from distutils.version import StrictVersion |
| + import coverage |
| + if (StrictVersion(coverage.__version__) < StrictVersion('3.7') or |
| + not coverage.collector.CTracer): |
| + del sys.modules['coverage'] |
| + del coverage |
| + else: |
| + return |
| + except ImportError: |
| + pass |
| + |
| + from pkg_resources import get_build_platform |
| + try: |
| + # Python 2.7 or >= 3.2 |
| + from sysconfig import get_python_version |
| + except ImportError: |
| + from distutils.sysconfig import get_python_version |
| + |
| + cov_dir = os.path.join(BASE_DIR, 'third_party', 'coverage-3.7.1') |
| + cov_egg = os.path.join(cov_dir, 'dist', 'coverage-3.7.1-py%s-%s.egg' % ( |
|
Vadim Sh.
2014/04/04 19:21:59
That's what bdist_egg produces? It there a way to
iannucci
2014/04/04 19:34:35
This is taken from setuptools' code. I can force g
|
| + get_python_version(), get_build_platform())) |
| + |
| + # The C-compiled coverage engine is WAY faster (and less buggy) than the pure |
| + # python version, so we build the dist_egg if necessary. |
| + if not os.path.exists(cov_egg): |
| + import subprocess |
| + print 'Building Coverage 3.7.1' |
| + p = subprocess.Popen([sys.executable, 'setup.py', 'bdist_egg'], cwd=cov_dir, |
|
Vadim Sh.
2014/04/04 19:21:59
It may be worth to add some instructions how to bu
Vadim Sh.
2014/04/04 19:32:21
Oh, it's already possible to import it from system
iannucci
2014/04/04 19:34:35
Yeah I wasn't sure how to support windows, but if
Vadim Sh.
2014/04/04 19:47:08
Also, bdist_egg needs python-dev and setuptools, r
|
| + stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| + stdout, stderr = p.communicate() |
| + if p.returncode != 0: |
| + print 'Error while building :(' |
| + print stdout |
| + print stderr |
| + sys.exit(1) |
| + |
| + sys.path.insert(0, cov_egg) |
|
Vadim Sh.
2014/04/04 19:21:59
Call 'ensure_coverage_importable' again, to ensure
iannucci
2014/04/04 19:34:35
? It's called below... it will either pass (and co
Vadim Sh.
2014/04/04 19:47:08
I mean second time, after egg is build, to assert
|
| + |
| +ensure_coverage_importable() |
| from common import find_depot_tools # pylint: disable=W0611 |