|
1
|
|
|
from coalib.bears.requirements.PackageRequirement import PackageRequirement |
|
2
|
|
|
from coalib.misc.Shell import call_without_output |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class GemRequirement(PackageRequirement): |
|
6
|
|
|
""" |
|
7
|
|
|
This class is a subclass of ``PackageRequirement``, and helps specifying |
|
8
|
|
|
requirements from ``gem``, without using the manager name. |
|
9
|
|
|
""" |
|
10
|
|
|
|
|
11
|
|
|
def __init__(self, package, version="", require=""): |
|
12
|
|
|
""" |
|
13
|
|
|
Constructs a new ``GemRequirement``, using the ``PackageRequirement`` |
|
14
|
|
|
constructor. |
|
15
|
|
|
|
|
16
|
|
|
>>> pr = GemRequirement('setuptools', '19.2', 'flag') |
|
17
|
|
|
>>> pr.manager |
|
18
|
|
|
'gem' |
|
19
|
|
|
>>> pr.package |
|
20
|
|
|
'setuptools' |
|
21
|
|
|
>>> pr.version |
|
22
|
|
|
'19.2' |
|
23
|
|
|
>>> pr.require |
|
24
|
|
|
'flag' |
|
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 require: A string that specifies any additional flags, that |
|
29
|
|
|
would be used with ``require``. |
|
30
|
|
|
""" |
|
31
|
|
|
PackageRequirement.__init__(self, 'gem', package, version) |
|
32
|
|
|
self.require = require |
|
33
|
|
|
|
|
34
|
|
|
def install_command(self): |
|
35
|
|
|
""" |
|
36
|
|
|
Creates the installation command for the instance of the class. |
|
37
|
|
|
|
|
38
|
|
|
>>> GemRequirement('rubocop').install_command() |
|
39
|
|
|
'gem install rubocop' |
|
40
|
|
|
|
|
41
|
|
|
>>> GemRequirement('scss_lint', '', 'false').install_command() |
|
42
|
|
|
"gem install 'scss_lint', require: false" |
|
43
|
|
|
|
|
44
|
|
|
:param return: A string with the installation command. |
|
45
|
|
|
""" |
|
46
|
|
|
if self.require: |
|
47
|
|
|
return "gem install '{}', require: {}".format(self.package, |
|
48
|
|
|
self.require) |
|
49
|
|
|
return "gem install {}".format(self.package) |
|
50
|
|
|
|
|
51
|
|
|
def is_installed(self): |
|
52
|
|
|
""" |
|
53
|
|
|
Checks if the dependency is installed. |
|
54
|
|
|
|
|
55
|
|
|
:param return: True if dependency is installed, false otherwise. |
|
56
|
|
|
""" |
|
57
|
|
|
return not call_without_output(('gem', 'list', '-i', self.package),) |
|
58
|
|
|
|