|
1
|
|
|
from coalib.bears.requirements.PackageRequirement import PackageRequirement |
|
2
|
|
|
from coalib.misc.Shell import run_shell_command |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class RscriptRequirement(PackageRequirement): |
|
6
|
|
|
""" |
|
7
|
|
|
This class is a subclass of ``PackageRequirement``, and helps specifying |
|
8
|
|
|
requirements from ``R``, without using the manager name. |
|
9
|
|
|
""" |
|
10
|
|
|
|
|
11
|
|
|
def __init__(self, package, version="", flag="", repo=""): |
|
12
|
|
|
""" |
|
13
|
|
|
Constructs a new ``RscriptRequirement``, using the |
|
14
|
|
|
``PackageRequirement`` constructor. |
|
15
|
|
|
|
|
16
|
|
|
>>> pr = RscriptRequirement( |
|
17
|
|
|
... 'formatR', version='1.4', flag='-e', |
|
18
|
|
|
... repo="http://cran.rstudio.com") |
|
19
|
|
|
>>> pr.manager |
|
20
|
|
|
'R' |
|
21
|
|
|
>>> pr.package |
|
22
|
|
|
'formatR' |
|
23
|
|
|
>>> pr.version |
|
24
|
|
|
'1.4' |
|
25
|
|
|
>>> pr.flag |
|
26
|
|
|
'-e' |
|
27
|
|
|
>>> pr.repo |
|
28
|
|
|
'http://cran.rstudio.com' |
|
29
|
|
|
|
|
30
|
|
|
:param package: A string with the name of the package to be installed. |
|
31
|
|
|
:param version: A version string. Leave empty to specify latest version. |
|
32
|
|
|
:param flag: A string that specifies any additional flags, that |
|
33
|
|
|
are passed to the manager. |
|
34
|
|
|
:param repo: The repository from which the package to be installed is |
|
35
|
|
|
from. |
|
36
|
|
|
""" |
|
37
|
|
|
PackageRequirement.__init__(self, 'R', package, version) |
|
38
|
|
|
self.flag = flag |
|
39
|
|
|
self.repo = repo |
|
40
|
|
|
|
|
41
|
|
|
def install_command(self): |
|
42
|
|
|
""" |
|
43
|
|
|
Creates the installation command for the instance of the class. |
|
44
|
|
|
|
|
45
|
|
|
>>> RscriptRequirement( |
|
46
|
|
|
... 'formatR', '' , '-e', |
|
47
|
|
|
... 'http://cran.rstudio.com').install_command() |
|
48
|
|
|
'R -e "install.packages(\"formatR\", repo=\"http://cran.rstudio.com\", dependencies=TRUE)"' |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
:param return: A string with the installation command. |
|
51
|
|
|
""" |
|
52
|
|
|
return ('R {} "install.packages(\"{}\", repo=\"{}\", ' |
|
53
|
|
|
'dependencies=TRUE)"'.format(self.flag, |
|
54
|
|
|
self.package, self.repo)) |
|
55
|
|
|
|
|
56
|
|
|
def is_installed(self): |
|
57
|
|
|
""" |
|
58
|
|
|
Checks if the dependency is installed. |
|
59
|
|
|
|
|
60
|
|
|
:param return: True if dependency is installed, false otherwise. |
|
61
|
|
|
""" |
|
62
|
|
|
return True if run_shell_command( |
|
63
|
|
|
('R -e \'library(\"{}\", quietly=TRUE)\'' |
|
64
|
|
|
.format(self.package)))[1] is '' else False |
|
65
|
|
|
|
This check looks for lines that are too long. You can specify the maximum line length.