Completed
Push — pyup-initial-update ( 5e7443 )
by Michael
17:36 queued 17:30
created

work_in()   A

Complexity

Conditions 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 3.6875

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 13
ccs 2
cts 8
cp 0.25
crap 3.6875
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 3
from changes.commands import stage as stage_command
11
12 3
VERSION = 'changes {}'.format(__version__)
13
14
15 3
@contextlib.contextmanager
16 3
def work_in(dirname=None):
17
    """
18
    Context manager version of os.chdir. When exited, returns to the working
19
    directory prior to entering.
20
    """
21
    curdir = os.getcwd()
22
    try:
23
        if dirname is not None:
24
            os.chdir(dirname)
25
        yield
26
    finally:
27
        os.chdir(curdir)
28
29
30 3
def print_version(context, param, value):
31
    if not value or context.resilient_parsing:
32
        return
33
    click.echo(VERSION)
34
    context.exit()
35
36
37 3
@click.option(
38
    '--dry-run',
39
    help='Prints (instead of executing) the operations to be performed.',
40
    is_flag=True,
41
    default=False,
42
)
43 3
@click.option(
44
    '--verbose',
45
    help='Enables verbose output.',
46
    is_flag=True,
47
    default=False,
48
)
49 3
@click.version_option(
50
    __version__,
51
    '-V',
52
    '--version',
53
    message=VERSION
54
)
55 3
@click.group(
56
    context_settings=dict(
57
        help_option_names=[u'-h', u'--help']
58
    ),
59
)
60
def main(dry_run, verbose):
61
    """Ch-ch-changes"""
62
63
64 3
@click.command()
65
def init():
66
    """
67
    Detects, prompts and initialises the project.
68
    """
69
    init_command.init()
70
71 3
main.add_command(init)
72
73
74 3
@click.command()
75 3
@click.argument('repo_directory', required=False)
76
def status(repo_directory):
77
    """
78
    Shows current project release status.
79
    """
80
    repo_directory = repo_directory if repo_directory else '.'
81
82
    with work_in(repo_directory):
83
        requests_cache.configure()
84
        status_command.status()
85
86 3
main.add_command(status)
87
88
89 3
@click.command()
90 3
@click.option(
91
    '--draft',
92
    help='Enables verbose output.',
93
    is_flag=True,
94
    default=False,
95
)
96 3
@click.argument('release_name', required=False)
97 3
@click.argument('release_description', required=False)
98
def stage(draft, release_name, release_description):
99
    """
100
    Stages a release
101
    """
102
    requests_cache.configure(expire_after=60*10*10)
103
    stage_command.stage(draft)
104
105
main.add_command(stage)
106