hiqdev /
hidev
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Automation tool mixed with code generator for easier continuous development |
||
| 4 | * |
||
| 5 | * @link https://github.com/hiqdev/hidev |
||
| 6 | * @package hidev |
||
| 7 | * @license BSD-3-Clause |
||
| 8 | * @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/) |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace hidev\base; |
||
| 12 | |||
| 13 | use Yii; |
||
| 14 | |||
| 15 | class BinaryPython extends Binary |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Detects how to run the binary. |
||
| 19 | * Searches in this order: |
||
| 20 | * 1. exexcutable in project's root directory |
||
| 21 | * 2. XXX ??? vendor directory |
||
| 22 | * 3. /home/user/.local/bin. |
||
| 23 | * @param string $name |
||
| 24 | * @return string path to the binary |
||
| 25 | */ |
||
| 26 | public function detectPath($name) |
||
| 27 | { |
||
| 28 | $paths = [ |
||
| 29 | Yii::getAlias("@root/$name", false), |
||
| 30 | Yii::getAlias("@root/env/bin/$name", false), |
||
| 31 | "$_SERVER[HOME]/.local/bin/$name", |
||
| 32 | ]; |
||
| 33 | foreach ($paths as $path) { |
||
| 34 | if (file_exists($path)) { |
||
| 35 | return $path; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | return parent::detectPath($name); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Detect command execution string. |
||
| 44 | * @param mixed $path |
||
| 45 | * @return string |
||
| 46 | */ |
||
| 47 | public function detectCommand($path) |
||
| 48 | { |
||
| 49 | $path = parent::detectCommand($path); |
||
| 50 | |||
| 51 | return is_executable($path) ? $path : '/usr/bin/env python ' . $path; |
||
| 52 | } |
||
| 53 | |||
| 54 | public function install() |
||
| 55 | { |
||
| 56 | if ($this->installer) { |
||
| 57 | passthru('/usr/bin/env wget ' . escapeshellarg($this->installer) . ' -O- | /usr/bin/env python', $exitcode); |
||
| 58 | } elseif ($this->download) { |
||
| 59 | $dest = Yii::getAlias('@root/' . $this->name, false); |
||
| 60 | passthru('/usr/bin/env wget ' . escapeshellarg($this->download) . ' -O ' . $dest, $exitcode); |
||
| 61 | } else { |
||
| 62 | $args = ['pip', 'install']; |
||
| 63 | if (!$_SERVER['VIRTUAL_ENV']) { |
||
| 64 | $args[] = '--user'; |
||
| 65 | } |
||
| 66 | $args[] = $this->package; |
||
| 67 | $exitcode = passthru(implode(' ', $args)); |
||
|
0 ignored issues
–
show
Are you sure the assignment to
$exitcode is correct as passthru(implode(' ', $args)) seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 68 | } |
||
| 69 | |||
| 70 | return $exitcode; |
||
| 71 | } |
||
| 72 | } |
||
| 73 |