-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
/* | ||
* Automation tool mixed with code generator for easier continuous development | ||
* | ||
* @link https://github.com/hiqdev/hidev | ||
* @package hidev | ||
* @license BSD-3-Clause | ||
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) | ||
*/ | ||
|
||
namespace hidev\base; | ||
|
||
use Yii; | ||
|
||
class BinaryPython extends Binary | ||
{ | ||
/** | ||
* @var string package full name, e.g. pytest | ||
*/ | ||
public $package; | ||
|
||
/** | ||
* @var string package version constraint, e.g. ^1.1 | ||
*/ | ||
public $version; | ||
|
||
/** | ||
* @var string installer URL | ||
*/ | ||
public $installer; | ||
|
||
/** | ||
* @var string URL to download PHAR | ||
*/ | ||
public $download; | ||
|
||
/** | ||
* Detects how to run the binary. | ||
* Searches in this order: | ||
* 1. exexcutable in project's root directory | ||
* 2. XXX ??? vendor directory | ||
* 3. /home/user/.local/bin | ||
* | ||
* @param string $name | ||
* @return string path to the binary | ||
*/ | ||
public function detectPath($name) | ||
{ | ||
$paths = [ | ||
Yii::getAlias("@root/$name", false), | ||
Yii::getAlias("@root/env/bin/$name", false), | ||
"$_SERVER[HOME]/.local/bin/$name", | ||
]; | ||
foreach ($paths as $path) { | ||
if (file_exists($path)) { | ||
return $path; | ||
} | ||
} | ||
|
||
return parent::detectPath($name); | ||
} | ||
|
||
/** | ||
* Detect command execution string. | ||
* @param mixed $path | ||
* @return string | ||
*/ | ||
public function detectCommand($path) | ||
{ | ||
$path = parent::detectCommand($path); | ||
|
||
return is_executable($path) ? $path : '/usr/bin/env python ' . $path; | ||
} | ||
|
||
public function install() | ||
{ | ||
if ($this->installer) { | ||
passthru('/usr/bin/env wget ' . escapeshellarg($this->installer) . ' -O- | /usr/bin/env python', $exitcode); | ||
} elseif ($this->download) { | ||
$dest = Yii::getAlias('@root/' . $this->name, false); | ||
passthru('/usr/bin/env wget ' . escapeshellarg($this->download) . ' -O ' . $dest, $exitcode); | ||
} else { | ||
passthru("/usr/bin/pip install {$this->package}", $exitcode); | ||
} | ||
|
||
return $exitcode; | ||
} | ||
} |