1
|
|
|
from coalib.bears.requirements.PackageRequirement import PackageRequirement |
2
|
|
|
from coalib.misc.Shell import call_without_output |
3
|
|
|
import sys |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class PipRequirement(PackageRequirement): |
7
|
|
|
""" |
8
|
|
|
This class is a subclass of ``PackageRequirement``, and helps specifying |
9
|
|
|
requirements from ``pip``, without using the manager name. |
10
|
|
|
""" |
11
|
|
|
|
12
|
|
|
def __init__(self, package, version=""): |
13
|
|
|
""" |
14
|
|
|
Constructs a new ``PipRequirement``, using the ``PackageRequirement`` |
15
|
|
|
constructor. |
16
|
|
|
|
17
|
|
|
>>> pr = PipRequirement('setuptools', '19.2') |
18
|
|
|
>>> pr.manager |
19
|
|
|
'pip' |
20
|
|
|
>>> pr.package |
21
|
|
|
'setuptools' |
22
|
|
|
>>> pr.version |
23
|
|
|
'19.2' |
24
|
|
|
|
25
|
|
|
:param package: A string with the name of the package to be installed. |
26
|
|
|
:param version: A version string. Leave empty to specify latest version. |
27
|
|
|
""" |
28
|
|
|
PackageRequirement.__init__(self, 'pip', package, version) |
29
|
|
|
|
30
|
|
|
def install_command(self): |
31
|
|
|
""" |
32
|
|
|
Creates the installation command for the instance of the class. |
33
|
|
|
|
34
|
|
|
:param return: A list with the installation command parameters. |
35
|
|
|
""" |
36
|
|
|
result = [sys.executable, '-m', 'pip', 'install', |
37
|
|
|
self.package + '==' + self.version if self.version |
38
|
|
|
else self.package] |
39
|
|
|
return result |
40
|
|
|
|
41
|
|
|
def is_installed(self): |
42
|
|
|
""" |
43
|
|
|
Checks if the dependency is installed. |
44
|
|
|
|
45
|
|
|
:param return: True if dependency is installed, false otherwise. |
46
|
|
|
""" |
47
|
|
|
return not call_without_output((sys.executable, '-m', 'pip', |
48
|
|
|
'show', self.package)) |
49
|
|
|
|