Completed
Push — pyup-update-pytest-3.2.5-to-3.... ( 637983 )
by Michael
09:35 queued 09:31
created

work_in()   A

Complexity

Conditions 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 4.048

Importance

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