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