Completed
Push — init-test ( 3e12e7 )
by Michael
07:46 queued 07:14
created

get_new_version()   A

Complexity

Conditions 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 4.3145

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
c 2
b 0
f 0
dl 0
loc 18
ccs 1
cts 6
cp 0.1666
crap 4.3145
rs 9.4285
1 3
from __future__ import (absolute_import, division,
2
                        print_function, unicode_literals)
3
4 3
import logging
5
6 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...
7 3
import semantic_version
0 ignored issues
show
Configuration introduced by
The import semantic_version 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...
8
9 3
from changes import attributes
10
11 3
log = logging.getLogger(__name__)
0 ignored issues
show
Coding Style Naming introduced by
The name log does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
12
13
14 3
def current_version(module_name):
15
    return attributes.extract_attribute(module_name, '__version__')
16
17
18 3
def get_new_version(module_name, current_version, no_input,
0 ignored issues
show
Comprehensibility Bug introduced by
current_version is re-defining a name which is already available in the outer-scope (previously defined on line 14).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
19
                    major=False, minor=False, patch=False):
20
21
    proposed_new_version = increment(
22
        current_version,
23
        major=major,
24
        minor=minor,
25
        patch=patch
26
    )
27
28
    if no_input:
29
        new_version = proposed_new_version
30
    else:
31
        new_version = click.prompt(
32
            'What is the release version for "{0}" '.format(module_name),
33
            default=proposed_new_version
34
        )
35
    return new_version.strip()
36
37
38 3
def increment(version, major=False, minor=False, patch=True):
39
    """
40
    Increment a semantic version
41
42
    :param version: str of the version to increment
43
    :param major: bool specifying major level version increment
44
    :param minor: bool specifying minor level version increment
45
    :param patch: bool specifying patch level version increment
46
    :return: str of the incremented version
47
    """
48
    version = semantic_version.Version(version)
49
    if major:
50
        version.major += 1
51
        version.minor = 0
52
        version.patch = 0
53
    elif minor:
54
        version.minor += 1
55
        version.patch = 0
56
    elif patch:
57
        version.patch += 1
58
59
    return str(version)
60
61
62 3
def increment_version(context):
63
    """Increments the __version__ attribute of your module's __init__."""
64
65
    attributes.replace_attribute(
66
        context.module_name,
67
        '__version__',
68
        context.new_version,
69
        dry_run=context.dry_run)
70
    log.info('Bumped version from %s to %s' % (context.current_version, context.new_version))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (93/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
71