vcs: respect preferred width of the options panel in commit dialog
[idea/community.git] / python / helpers / coverage_runner / run_coverage.py
1 """Coverage.py's main entrypoint."""
2
3 import os
4 import sys
5
6 bundled_coverage_path = os.getenv('BUNDLED_COVERAGE_PATH')
7 if bundled_coverage_path:
8     sys_path_backup = sys.path
9     sys.path = [p for p in sys.path if p != bundled_coverage_path]
10     from coverage.cmdline import main
11     sys.path = sys_path_backup
12 else:
13     from coverage.cmdline import main
14
15 coverage_file = os.getenv('PYCHARM_COVERAGE_FILE')
16 run_cov = os.getenv('PYCHARM_RUN_COVERAGE')
17 if os.getenv('CREATE_TEMP_COVERAGE_FILE'):
18     line = 'LOG: PyCharm: File mapping:%s\t%s\n'
19     import tempfile
20     (h, new_cov_file) = tempfile.mkstemp(prefix='pycharm-coverage')
21     print(line%(coverage_file, new_cov_file))
22     print(line%(coverage_file + '.syspath.txt', new_cov_file + '.syspath.txt'))
23     print(line%(coverage_file + '.xml', new_cov_file + '.xml'))
24     coverage_file = new_cov_file
25
26 if coverage_file:
27     os.environ['COVERAGE_FILE'] = coverage_file
28 if run_cov:
29     a_file = open(coverage_file + '.syspath.txt', mode='w')
30     a_file.write(os.getcwd()+"\n")
31     for path in sys.path: a_file.write(path + "\n")
32     a_file.close()
33
34 argv = []
35 for arg in sys.argv:
36     if arg.startswith('-m'):
37         argv.append('-m')
38         argv.append(arg[2:])
39     else:
40         argv.append(arg)
41 sys.argv = argv
42
43 cwd = os.getcwd()
44 main()
45 if run_cov:
46     os.chdir(cwd)
47     main(["xml", "-o", coverage_file + ".xml", "--ignore-errors"])