Completed
Pull Request — master (#2185)
by Zatreanu
01:58
created

PythonRequirement.multiple()   A

Complexity

Conditions 4

Size

Total Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
c 2
b 0
f 0
dl 0
loc 54
rs 9.0306

1 Method

Rating   Name   Duplication   Size   Complexity  
A PythonRequirement.__init__() 0 17 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
from coalib.bears.requirements.PackageRequirement import PackageRequirement
2
3
4
class PythonRequirement(PackageRequirement):
5
    """
6
    This class is a subclass of ``PackageRequirement``, and helps specifying
7
    requirements from ``pip``, without using the manager name.
8
9
    You should use the ``multiple`` method if you have more
10
    requirements from the same manager. This can receive both tuples of
11
    strings, in case you want a specific version, or a simple string, in
12
    case you want the latest version to be specified.
13
14
    This is the case where you would provide strings only, to specify the
15
    latest version automatically:
16
17
    >>> REQUIREMENTS = PythonRequirement.multiple(
18
    ...     'coala_decorators', 'setuptools')
19
20
    And if you choose to mix them, specifying version for some and for some
21
    not:
22
23
    >>> REQUIREMENTS = PythonRequirement.multiple(
24
    ...     'coala_decorators', ('setuptools', '19.2'))
25
26
    Lists are also valid arguments:
27
28
    >>> REQUIREMENTS = PythonRequirement.multiple(
29
    ...     ['coala_decorators', '19.2'],)
30
31
    In case you provide too many arguments into the tuple, an error will be
32
    raised:
33
34
    >>> REQUIREMENTS = PythonRequirement.multiple(
35
    ...     'coala_decorators', ('setuptools', '19.2', 'colorama'))
36
    Traceback (most recent call last):
37
    ...
38
    TypeError: Too many elements provided.
39
    """
40
41
    def __init__(self, package, version=""):
42
        """
43
        Constructs a new ``PythonRequirement``, using the ``PackageRequirement``
44
        constructor.
45
46
        >>> pr = PythonRequirement('setuptools', '19.2')
47
        >>> pr.manager
48
        'pip'
49
        >>> pr.package
50
        'setuptools'
51
        >>> pr.version
52
        '19.2'
53
54
        :param package: A string with the name of the package to be installed.
55
        :param version: A version string. Leave empty to specify latest version.
56
        """
57
        PackageRequirement.__init__(self, 'pip', package, version)
58