Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit 552693c

Browse files
committed
More boring work
1 parent 712db67 commit 552693c

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

src/Installer/Installer.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,39 @@ public function install($installPath = null)
5252
}
5353

5454
$this->system->ensurePath($installPath);
55+
$this->executeComposerCommand($installPath);
56+
57+
$this->installKernel();
5558
}
5659

5760
/**
5861
* @return string
5962
*/
60-
public abstract function getInstallPath();
63+
protected abstract function getInstallPath();
64+
65+
/**
66+
*
67+
*/
68+
protected abstract function installKernel();
69+
70+
/**
71+
* @param string $installPath
72+
*/
73+
protected function executeComposerCommand($installPath)
74+
{
75+
$composerStatus = 0;
76+
77+
echo "\n";
78+
passthru(
79+
$this->composerCmd.' --working-dir="'.$installPath.'" create-project dawehner/jupyter-php pkgs',
80+
$composerStatus
81+
);
82+
echo "\n";
83+
84+
if ($composerStatus !== 0) {
85+
throw new \RuntimeException('Error while trying to download Jupyter-PHP dependencies with Composer.');
86+
}
87+
}
6188

6289
/**
6390
* Installer constructor.

src/Installer/LinuxInstaller.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(UnixSystem $system, $composerCmd)
2222
/**
2323
* @return string
2424
*/
25-
public function getInstallPath()
25+
protected function getInstallPath()
2626
{
2727
$currentUser = $this->system->getCurrentUser();
2828

@@ -32,4 +32,26 @@ public function getInstallPath()
3232
return $this->system->getCurrentUserHome().'/.jupyter-php';
3333
}
3434
}
35+
36+
/**
37+
*
38+
*/
39+
protected function installKernel()
40+
{
41+
$kernelDef = json_encode([
42+
'argv' => ['php', $this->getInstallPath().'/pkgs/src/kernel.php', '{connection_file}'],
43+
'display_name' => 'PHP',
44+
'language' => 'php',
45+
'env' => new \Stdclass
46+
]);
47+
48+
$currentUser = $this->system->getCurrentUser();
49+
50+
$kernelSpecPath = ('root' === $currentUser) ?
51+
'/usr/local/share/jupyter/kernels/jupyter-php' :
52+
$this->system->getCurrentUserHome().'/.local/share/jupyter/kernels/jupyter-php';
53+
54+
$this->system->ensurePath($kernelSpecPath);
55+
file_put_contents($kernelSpecPath.'/kernel.json', $kernelDef);
56+
}
3557
}

src/System/UnixSystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function ensurePath($path)
116116
{
117117
$absPath = $this->getAbsolutePath($path);
118118

119-
if (false === mkdir($this->getAbsolutePath($path), 0744, true)) {
119+
if (false === mkdir($this->getAbsolutePath($path), 0755, true)) {
120120
throw new \RuntimeException('Unable to create the specified directory ('.$absPath.').');
121121
}
122122

0 commit comments

Comments
 (0)