| Total Complexity | 4 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | from coalib.bears.requirements.PackageRequirement import PackageRequirement |
||
| 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 | MANAGER = sys.executable + ' -m pip' |
||
| 13 | |||
| 14 | def __init__(self, package, version=""): |
||
| 15 | """ |
||
| 16 | Constructs a new ``PipRequirement``, using the ``PackageRequirement`` |
||
| 17 | constructor. |
||
| 18 | |||
| 19 | >>> pr = PipRequirement('setuptools', '19.2') |
||
| 20 | >>> pr.manager |
||
| 21 | 'pip' |
||
| 22 | >>> pr.package |
||
| 23 | 'setuptools' |
||
| 24 | >>> pr.version |
||
| 25 | '19.2' |
||
| 26 | |||
| 27 | :param package: A string with the name of the package to be installed. |
||
| 28 | :param version: A version string. Leave empty to specify latest version. |
||
| 29 | """ |
||
| 30 | PackageRequirement.__init__(self, 'pip', package, version) |
||
| 31 | |||
| 32 | def install_command(self): |
||
| 33 | """ |
||
| 34 | Creates the installation command for the instance of the class. |
||
| 35 | |||
| 36 | :param return: A string with the installation command. |
||
| 37 | """ |
||
| 38 | result = "{} install {}".format(self.MANAGER, self.package) |
||
| 39 | if self.version: |
||
| 40 | result += "=={}".format(self.version) |
||
| 41 | return result |
||
| 42 | |||
| 43 | def is_installed(self): |
||
| 44 | """ |
||
| 45 | Checks if the dependency is installed. |
||
| 46 | |||
| 47 | :param return: True if dependency is installed, false otherwise. |
||
| 48 | """ |
||
| 49 | return not call_without_output(('pip', 'show', self.package)) |
||
| 50 |