1
|
|
|
from coalib.bears.requirements.PackageRequirement import PackageRequirement |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
class PythonRequirement(PackageRequirement): |
5
|
|
|
""" |
6
|
|
|
This class is a subclass of ``PackageRequirement``, and helps specifying |
7
|
|
|
requirements from ``pip``, without using the manager name. |
8
|
|
|
|
9
|
|
|
You should use the ``multiple`` method if you have more |
10
|
|
|
requirements from the same manager. This can receive both tuples of |
11
|
|
|
strings, in case you want a specific version, or a simple string, in |
12
|
|
|
case you want the latest version to be specified. |
13
|
|
|
|
14
|
|
|
This is the case where you would provide strings only, to specify the |
15
|
|
|
latest version automatically: |
16
|
|
|
|
17
|
|
|
>>> REQUIREMENTS = PythonRequirement.multiple( |
18
|
|
|
... 'coala_decorators', 'setuptools') |
19
|
|
|
|
20
|
|
|
And if you choose to mix them, specifying version for some and for some |
21
|
|
|
not: |
22
|
|
|
|
23
|
|
|
>>> REQUIREMENTS = PythonRequirement.multiple( |
24
|
|
|
... 'coala_decorators', ('setuptools', '19.2')) |
25
|
|
|
|
26
|
|
|
Lists are also valid arguments: |
27
|
|
|
|
28
|
|
|
>>> REQUIREMENTS = PythonRequirement.multiple( |
29
|
|
|
... ['coala_decorators', '19.2'],) |
30
|
|
|
|
31
|
|
|
In case you provide too many arguments into the tuple, an error will be |
32
|
|
|
raised: |
33
|
|
|
|
34
|
|
|
>>> REQUIREMENTS = PythonRequirement.multiple( |
35
|
|
|
... 'coala_decorators', ('setuptools', '19.2', 'colorama')) |
36
|
|
|
Traceback (most recent call last): |
37
|
|
|
... |
38
|
|
|
TypeError: Too many elements provided. |
39
|
|
|
""" |
40
|
|
|
|
41
|
|
|
def __init__(self, package, version=""): |
42
|
|
|
""" |
43
|
|
|
Constructs a new ``PythonRequirement``, using the ``PackageRequirement`` |
44
|
|
|
constructor. |
45
|
|
|
|
46
|
|
|
>>> pr = PythonRequirement('setuptools', '19.2') |
47
|
|
|
>>> pr.manager |
48
|
|
|
'pip' |
49
|
|
|
>>> pr.package |
50
|
|
|
'setuptools' |
51
|
|
|
>>> pr.version |
52
|
|
|
'19.2' |
53
|
|
|
|
54
|
|
|
:param package: A string with the name of the package to be installed. |
55
|
|
|
:param version: A version string. Leave empty to specify latest version. |
56
|
|
|
""" |
57
|
|
|
PackageRequirement.__init__(self, 'pip', package, version) |
58
|
|
|
|