-
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
5 changed files
with
88 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Autopilot\Drivers; | ||
|
||
use Autopilot\Drivers\Concerns\RequiresRunning; | ||
use Autopilot\Tasks\Python\RunScript; | ||
|
||
class PythonScriptDriver extends Driver implements RequiresRunning | ||
{ | ||
public function matches(): bool | ||
{ | ||
return $this->repository->dir()->find() | ||
->name('*.py') | ||
->count() > 0; | ||
} | ||
|
||
public function runningTasks(): array | ||
{ | ||
return [ | ||
RunScript::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,42 @@ | ||
<?php | ||
|
||
namespace Autopilot\Tasks\Python; | ||
|
||
use Autopilot\Repository; | ||
use Autopilot\Tasks\Task; | ||
|
||
class RunScript extends Task | ||
{ | ||
private $primaryFile; | ||
|
||
public function __construct(Repository $repository) | ||
{ | ||
parent::__construct($repository); | ||
|
||
$this->primaryFile = $this->getPrimaryFile(); | ||
} | ||
|
||
public function run() | ||
{ | ||
$path = $this->repository()->dir()->getPath($this->primaryFile); | ||
|
||
chdir($this->repository()->dir()->getPath()); | ||
passthru("python $path"); // @todo does not work with pythons `input` function | ||
} | ||
|
||
public function message(): string | ||
{ | ||
return "Guessed primary file: $this->primaryFile. Executing..." . PHP_EOL . PHP_EOL; | ||
} | ||
|
||
private function getPrimaryFile(): string | ||
{ | ||
$finder = $this->repository()->dir()->find() | ||
->depth(0) | ||
->name('*.py'); | ||
|
||
foreach ($finder as $file) { | ||
return $file->getFilename(); | ||
} | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Drivers; | ||
|
||
use Autopilot\Drivers\PythonScriptDriver; | ||
use Autopilot\Repository; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PythonScriptDriverTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_matches() | ||
{ | ||
$repository = new Repository("[email protected]:ceae8dbb-4b83-11ec-a0c6-4213e7ee7fac/2c811487-1082-11ec-a7a6-4213e7ee7fac/Hello-world-ca0aef52-63206bf1.git"); | ||
$repository->clone(); | ||
|
||
$driver = new PythonScriptDriver($repository); | ||
|
||
$this->assertTrue($driver->matches()); | ||
} | ||
} |