Completed
Push — fix-ci-failures ( 4b308a...3c0b05 )
by Michael
02:37
created

work_in()   A

Complexity

Conditions 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 2
rs 9.4285
1 3
import contextlib
2 3
import os
3
4 3
import click
0 ignored issues
show
Configuration introduced by
The import click could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

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.

Loading history...
5 3
import requests_cache
0 ignored issues
show
Configuration introduced by
The import requests_cache could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

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.

Loading history...
6
7 3
from . import __version__
8 3
from changes.commands import init as init_command
9 3
from changes.commands import status as status_command
10
11 3
VERSION = 'changes {}'.format(__version__)
12
13
14 3
@contextlib.contextmanager
15 3
def work_in(dirname=None):
16
    """
17
    Context manager version of os.chdir. When exited, returns to the working
18
    directory prior to entering.
19
    """
20 3
    curdir = os.getcwd()
21 3
    try:
22 3
        if dirname is not None:
23 3
            os.chdir(dirname)
24 3
        yield
25
    finally:
26 3
        os.chdir(curdir)
27
28
29 3
def print_version(context, param, value):
30
    if not value or context.resilient_parsing:
31
        return
32
    click.echo(VERSION)
33
    context.exit()
34
35
36 3
@click.option(
37
    '--dry-run',
38
    help='Prints (instead of executing) the operations to be performed.',
39
    is_flag=True,
40
    default=False,
41
)
42 3
@click.option(
43
    '--verbose',
44
    help='Enables verbose output.',
45
    is_flag=True,
46
    default=False,
47
)
48 3
@click.version_option(
49
    __version__,
50
    '-V',
51
    '--version',
52
    message=VERSION
53
)
54 3
@click.group(
55
    context_settings=dict(
56
        help_option_names=[u'-h', u'--help']
57
    ),
58
)
59
def main(dry_run, verbose):
60
    """Ch-ch-changes"""
61
62
63 3
@click.command()
64
def init():
65
    """
66
    Detects, prompts and initialises the project.
67
    """
68 3
    init_command.init()
69
70 3
main.add_command(init)
71
72
73 3
@click.command()
74 3
@click.argument('repo_directory', required=False)
75
def status(repo_directory):
76
    """
77
    Shows current project release status.
78
    """
79 3
    repo_directory = repo_directory if repo_directory else '.'
80
81 3
    with work_in(repo_directory):
82 3
        requests_cache.configure()
83 3
        status_command.status()
84
85
main.add_command(status)