Completed
Pull Request — master (#2435)
by
unknown
02:03
created

JuliaRequirement.is_installed()   A

Complexity

Conditions 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
dl 0
loc 9
rs 9.6666
1
from coalib.bears.requirements.PackageRequirement import PackageRequirement
2
from coalib.misc.Shell import call_without_output
3
4
5
class JuliaRequirement(PackageRequirement):
6
    """
7
    This class is a subclass of ``PackageRequirement``, and helps specifying
8
    requirements from ``julia``, without using the manager name.
9
    """
10
11
    def __init__(self, package, version="", flag=""):
12
        """
13
        Constructs a new ``JuliaRequirement``, using the ``PackageRequirement``
14
        constructor.
15
16
        >>> pr = JuliaRequirement('"Pkg.add(\"Lint\")"', '19.2', '-e')
17
        >>> pr.manager
18
        'julia'
19
        >>> pr.package
20
        '"Pkg.add(\"Lint\")"'
21
        >>> pr.version
22
        '19.2'
23
        >>> pr.flag
24
        '-e'
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, 'julia', 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
        >>> JuliaRequirement("Lint", '', '-e').install_command()
39
        'julia -e "Pkg.add(\"Lint\")'
40
41
        :param return: A string with the installation command.
42
        """
43
        return 'julia {} "Pkg.add(\"{}\")'.format(self.flag, self.package)
44
45
    def is_installed(self):
46
        """
47
        Checks if the dependency is installed.
48
49
        :param return: True if dependency is installed, false otherwise.
50
        """
51
52
        return not call_without_output(
53
            ('julia', self.flag, '"Pkg.installed(\"' + self.package + '\")"'))
54