GoRequirement   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 22 1
A is_installed() 0 7 1
A install_command() 0 11 1
1
from coalib.bears.requirements.PackageRequirement import PackageRequirement
2
from coalib.misc.Shell import call_without_output
3
4
5
class GoRequirement(PackageRequirement):
6
    """
7
    This class is a subclass of ``PackageRequirement``, and helps specifying
8
    requirements from ``go``, without using the manager name.
9
    """
10
11
    def __init__(self, package, version="", flag=""):
12
        """
13
        Constructs a new ``GoRequirement``, using the ``PackageRequirement``
14
        constructor.
15
16
        >>> pr = GoRequirement('github.com/golang/lint/golint', '19.2', '-u')
17
        >>> pr.manager
18
        'go'
19
        >>> pr.package
20
        'github.com/golang/lint/golint'
21
        >>> pr.version
22
        '19.2'
23
        >>> pr.flag
24
        '-u'
25
26
        :param package: A string with the name of the package to be installed.
27
        :param version: A version string. Leave empty to specify latest version.
28
        :param flag:    A string that specifies any additional flags, that
29
                        are passed to the manager.
30
        """
31
        PackageRequirement.__init__(self, 'go', package, version)
32
        self.flag = flag
33
34
    def install_command(self):
35
        """
36
        Creates the installation command for the instance of the class.
37
38
        >>> GoRequirement(
39
        ...     'github.com/golang/lint/golint', '' , '-u' ).install_command()
40
        ['go', 'get', '-u', 'github.com/golang/lint/golint']
41
42
        :param return: A string with the installation command.
43
        """
44
        return ['go', 'get', self.flag, self.package]
45
46
    def is_installed(self):
47
        """
48
        Checks if the dependency is installed.
49
50
        :param return: True if dependency is installed, false otherwise.
51
        """
52
        return not call_without_output(('go', 'doc', self.package))
53