Tor Norbye | 3a2425a5 | 2013-11-04 10:16:08 -0800 | [diff] [blame] | 1 | """Coverage.py's main entrypoint.""" |
| 2 | |
| 3 | import os |
| 4 | import sys |
| 5 | import imp |
| 6 | |
| 7 | helpers_root = os.getenv('PYCHARM_HELPERS_ROOT') |
| 8 | if helpers_root: |
| 9 | sys_path_backup = sys.path |
| 10 | sys.path = [p for p in sys.path if p!=helpers_root] |
| 11 | from coverage.cmdline import main |
| 12 | sys.path = sys_path_backup |
| 13 | else: |
| 14 | from coverage.cmdline import main |
| 15 | |
| 16 | coverage_file = os.getenv('PYCHARM_COVERAGE_FILE') |
| 17 | run_cov = os.getenv('PYCHARM_RUN_COVERAGE') |
| 18 | if os.getenv('JETBRAINS_REMOTE_RUN'): |
| 19 | line = 'LOG: PyCharm: File mapping:%s\t%s\n' |
| 20 | import tempfile |
| 21 | (h, new_cov_file) = tempfile.mkstemp(prefix='pycharm-coverage') |
| 22 | print(line%(coverage_file, new_cov_file)) |
| 23 | print(line%(coverage_file + '.syspath.txt', new_cov_file + '.syspath.txt')) |
| 24 | print(line%(coverage_file + '.xml', new_cov_file + '.xml')) |
| 25 | coverage_file = new_cov_file |
| 26 | |
| 27 | if coverage_file: |
| 28 | os.environ['COVERAGE_FILE'] = coverage_file |
| 29 | if run_cov: |
| 30 | a_file = open(coverage_file + '.syspath.txt', mode='w') |
| 31 | a_file.write(os.getcwd()+"\n") |
| 32 | for path in sys.path: a_file.write(path + "\n") |
| 33 | a_file.close() |
| 34 | main() |
| 35 | if run_cov: |
| 36 | main(["xml", "-o", coverage_file + ".xml", "--ignore-errors"]) |