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 requests |
|
23 | 1 | import colorama |
|
24 | 1 | from backports.shutil_get_terminal_size import get_terminal_size |
|
0 ignored issues
–
show
|
|||
25 | |||
26 | 1 | from . import API, VERSION |
|
27 | |||
28 | 1 | from .plugins import get_coverage |
|
29 | |||
30 | |||
31 | 1 | def main(): |
|
32 | """Run the program.""" |
||
33 | 1 | colorama.init(autoreset=True) |
|
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(), |
|
58 | colorama.Fore.YELLOW + colorama.Style.BRIGHT) |
||
59 | 1 | return False |
|
60 | |||
61 | else: |
||
62 | display("coverage unknown", response.json(), |
||
63 | colorama.Fore.RED + colorama.Style.BRIGHT) |
||
64 | return False |
||
65 | |||
66 | |||
67 | 1 | def display(title, data, color=""): |
|
68 | """Write colored text to the console.""" |
||
69 | 1 | width, _ = get_terminal_size() |
|
70 | 1 | six.print_(color + "{0:=^{1}}".format(' ' + title + ' ', width)) |
|
71 | 1 | six.print_(color + json.dumps(data, indent=4)) |
|
72 | six.print_(color + '=' * width) |
||
73 |
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.