-
Notifications
You must be signed in to change notification settings - Fork 0
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
13 changed files
with
136 additions
and
5 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
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
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
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,34 @@ | ||
<?php | ||
|
||
namespace Autopilot\Drivers; | ||
|
||
use Autopilot\Drivers\Concerns\RequiresRunning; | ||
use Autopilot\Drivers\Concerns\RequiresSetup; | ||
use Autopilot\Tasks\General\ChdirToRepository; | ||
use Autopilot\Tasks\Python\InstallPythonDependencies; | ||
use Autopilot\Tasks\Python\RunScriptInVirtualEnvironment; | ||
use Autopilot\Tasks\Python\SetupVirtualEnvironment; | ||
|
||
class PythonVirtualEnvDriver extends Driver implements RequiresSetup, RequiresRunning | ||
{ | ||
public function matches(): bool | ||
{ | ||
return $this->repository->dir()->contains('requirements.txt'); | ||
} | ||
|
||
public function setupTasks(): array | ||
{ | ||
return [ | ||
ChdirToRepository::class, | ||
SetupVirtualEnvironment::class, | ||
InstallPythonDependencies::class, | ||
]; | ||
} | ||
|
||
public function runningTasks(): array | ||
{ | ||
return [ | ||
RunScriptInVirtualEnvironment::class, | ||
]; | ||
} | ||
} |
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
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,18 @@ | ||
<?php | ||
|
||
namespace Autopilot\Tasks\General; | ||
|
||
use Autopilot\Tasks\Task; | ||
|
||
class ChdirToRepository extends Task | ||
{ | ||
public function run() | ||
{ | ||
chdir($this->repository()->dir()->getPath()); | ||
} | ||
|
||
public function message(): string | ||
{ | ||
return 'Setting working directory'; | ||
} | ||
} |
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
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
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,20 @@ | ||
<?php | ||
|
||
namespace Autopilot\Tasks\Python; | ||
|
||
use Autopilot\Tasks\Task; | ||
|
||
class InstallPythonDependencies extends Task | ||
{ | ||
public function run() | ||
{ | ||
$executable = $this->repository()->dir()->getPath('venv/bin/pip'); | ||
|
||
exec("$executable install -r requirements.txt"); | ||
} | ||
|
||
public function message(): string | ||
{ | ||
return 'Installing dependencies from requirements.txt'; | ||
} | ||
} |
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
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,15 @@ | ||
<?php | ||
|
||
namespace Autopilot\Tasks\Python; | ||
|
||
class RunScriptInVirtualEnvironment extends RunScript | ||
{ | ||
public function run() | ||
{ | ||
$executable = $this->repository()->dir()->getPath('venv/bin/python'); | ||
$path = $this->repository()->dir()->getPath($this->primaryFile); | ||
|
||
// -u is to prevent input calls from buffering until after the script is executed | ||
passthru("$executable -u $path"); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Autopilot\Tasks\Python; | ||
|
||
use Autopilot\Tasks\Task; | ||
|
||
class SetupVirtualEnvironment extends Task | ||
{ | ||
public function run() | ||
{ | ||
exec('virtualenv venv'); | ||
} | ||
|
||
public function message(): string | ||
{ | ||
return 'Setting up virtual environment'; | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace Drivers; | ||
|
||
use Autopilot\Drivers\PythonVirtualEnvDriver; | ||
use Autopilot\Repository; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PythonVirtualEnvDriverTest extends TestCase | ||
{ | ||
|
||
/** @test */ | ||
public function it_matches() | ||
{ | ||
$repository = new Repository('[email protected]:1f92ce4c-4b84-11ec-a0c6-4213e7ee7fac/e2a0997b-4219-11ec-a0c6-4213e7ee7fac/Bieps-Per-Minute-11e57750-fcd48921.git'); | ||
$repository->clone(); | ||
|
||
$driver = new PythonVirtualEnvDriver($repository); | ||
|
||
$this->assertTrue($driver->matches()); | ||
} | ||
} |