1
|
|
|
"""Update project metrics on The Coverage Space. |
2
|
|
|
|
3
|
|
|
Usage: |
4
|
|
|
coverage.space <owner/repo> <metric> [<value>] [--exit-code] |
5
|
|
|
coverage.space (-h | --help) |
6
|
|
|
coverage.space (-V | --version) |
7
|
|
|
|
8
|
|
|
Options: |
9
|
|
|
-h --help Show this help screen. |
10
|
|
|
-V --version Show the program version. |
11
|
|
|
--exit-code Return non-zero exit code on failures. |
12
|
|
|
|
13
|
|
|
""" |
14
|
|
|
|
15
|
1 |
|
from __future__ import unicode_literals |
16
|
|
|
|
17
|
1 |
|
import sys |
18
|
1 |
|
import json |
19
|
|
|
|
20
|
1 |
|
import six |
21
|
1 |
|
from docopt import docopt |
|
|
|
|
22
|
1 |
|
import blessings |
|
|
|
|
23
|
1 |
|
import requests |
24
|
|
|
|
25
|
1 |
|
from . import API, VERSION |
26
|
|
|
|
27
|
1 |
|
from .plugins import get_coverage |
28
|
|
|
|
29
|
1 |
|
term = blessings.Terminal() |
30
|
|
|
|
31
|
|
|
|
32
|
1 |
|
def main(): |
33
|
|
|
"""Run the program.""" |
34
|
1 |
|
arguments = docopt(__doc__, version=VERSION) |
35
|
|
|
|
36
|
1 |
|
slug = arguments['<owner/repo>'] |
37
|
1 |
|
metric = arguments['<metric>'] |
38
|
1 |
|
value = arguments.get('<value>') or get_coverage() |
39
|
|
|
|
40
|
1 |
|
success = call(slug, metric, value) |
41
|
|
|
|
42
|
1 |
|
if not success and arguments['--exit-code']: |
43
|
1 |
|
sys.exit(1) |
44
|
|
|
|
45
|
|
|
|
46
|
1 |
|
def call(slug, metric, value): |
47
|
|
|
"""Call the API and display errors.""" |
48
|
1 |
|
url = "{}/{}".format(API, slug) |
49
|
1 |
|
data = {metric: value} |
50
|
|
|
|
51
|
1 |
|
response = requests.put(url, data=data) |
52
|
|
|
|
53
|
1 |
|
if response.status_code == 200: |
54
|
1 |
|
return True |
55
|
|
|
|
56
|
1 |
|
elif response.status_code == 422: |
57
|
1 |
|
display("coverage decreased", response.json(), term.bold_yellow) |
58
|
1 |
|
return False |
59
|
|
|
|
60
|
|
|
else: |
61
|
|
|
display("coverage unknown", response.json(), term.bold_red) |
62
|
|
|
return False |
63
|
|
|
|
64
|
|
|
|
65
|
1 |
|
def display(title, data, color=term.normal): |
66
|
|
|
"""Write colored text to the console.""" |
67
|
1 |
|
width = term.width or 80 |
68
|
1 |
|
six.print_(color("{0:=^{1}}".format(' ' + title + ' ', width))) |
69
|
1 |
|
six.print_(color(json.dumps(data, indent=4))) |
70
|
|
|
six.print_(color('=' * width)) |
71
|
|
|
|
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.