forked from TheKevJames/coveralls-python
/
cli.py
104 lines (81 loc) · 3.22 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
Publish coverage results online via coveralls.io.
Puts your coverage results on coveralls.io for everyone to see.
This tool makes custom reports for data generated by coverage.py package and
sends it to the coveralls.io service API.
All Python files in your coverage analysis are posted to this service along
with coverage stats, so please make sure you're not ruining your own security!
Usage:
coveralls [options]
coveralls debug [options]
Debug mode doesn't send anything, just outputs json to stdout. It also
forces verbose output. Please use debug mode when submitting bug reports.
Global options:
--service=<name> Provide an alternative service name to submit.
--rcfile=<file> Specify configuration file. [default: .coveragerc]
--basedir=<dir> Base directory that is removed from reported paths.
--output=<file> Write report to file. Doesn't send anything.
--submit=<file> Upload a previously generated file.
--merge=<file> Merge report from file when submitting.
--finish Finish parallel jobs.
-h --help Display this help.
-v --verbose Print extra info, always enabled when debugging.
Example:
-------
$ coveralls
Submitting coverage to coveralls.io...
Coverage submitted!
Job #38.1
https://coveralls.io/jobs/92059
"""
import logging
import sys
import docopt
from .api import Coveralls
from .exception import CoverallsException
from .version import __version__
log = logging.getLogger('coveralls')
def main(argv=None):
options = docopt.docopt(__doc__, argv=argv, version=__version__)
if options['debug']:
options['--verbose'] = True
level = logging.DEBUG if options['--verbose'] else logging.INFO
log.addHandler(logging.StreamHandler())
log.setLevel(level)
token_required = not options['debug'] and not options['--output']
try:
coverallz = Coveralls(token_required,
config_file=options['--rcfile'],
service_name=options['--service'],
base_dir=options.get('--basedir') or '')
if options['--merge']:
coverallz.merge(options['--merge'])
if options['debug']:
log.info('Testing coveralls-python...')
coverallz.wear(dry_run=True)
return
if options['--output']:
log.info('Write coverage report to file...')
coverallz.save_report(options['--output'])
return
if options['--submit']:
with open(options['--submit']) as report_file:
coverallz.submit_report(report_file.read())
return
if options['--finish']:
log.info('Finishing parallel jobs...')
coverallz.parallel_finish()
log.info('Done')
return
log.info('Submitting coverage to coveralls.io...')
result = coverallz.wear()
log.info('Coverage submitted!')
log.debug(result)
if result:
log.info(result.get('message'))
log.info(result.get('url'))
except KeyboardInterrupt: # pragma: no cover
log.info('Aborted')
except CoverallsException as e:
log.exception(e)
sys.exit(1)