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

Commit 5c78a33

Browse files
authored
Merge pull request #15 from bstoney/master
Changed Windows paths to use environment variables
2 parents 6c3b706 + 3f36e5a commit 5c78a33

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/Installer/WindowsInstaller.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function getInstallPath()
2727
$currentUser = $this->system->getCurrentUser();
2828

2929
if ('Administrator' === $currentUser) {
30-
return 'C:\ProgramData\jupyter-php';
30+
return $this->getProgramDataPath() . '\jupyter-php';
3131
} else {
3232
return $this->system->getCurrentUserHome() . '\.jupyter-php';
3333
}
@@ -48,8 +48,8 @@ protected function installKernel()
4848
$currentUser = $this->system->getCurrentUser();
4949

5050
$kernelSpecPath = ('Administrator' === $currentUser) ?
51-
'C:\ProgramData\jupyter\kernels\jupyter-php' :
52-
$this->system->getCurrentUserHome() . '\AppData\Roaming\jupyter\kernels\jupyter-php';
51+
$this->getProgramDataPath() . '\jupyter\kernels\jupyter-php' :
52+
$this->getAppDataPath() . '\jupyter\kernels\jupyter-php';
5353

5454
$this->system->ensurePath($kernelSpecPath);
5555
file_put_contents($kernelSpecPath . '\kernel.json', $kernelDef);
@@ -73,4 +73,22 @@ protected function executeSilentComposerCommand($installPath)
7373

7474
return $composerStatus;
7575
}
76+
77+
private function getProgramDataPath()
78+
{
79+
if (function_exists('getenv') && false !== getenv('PROGRAMDATA')) {
80+
return getenv('PROGRAMDATA');
81+
} else {
82+
throw new \RuntimeException('Unable to obtain the program data directory.');
83+
}
84+
}
85+
86+
private function getAppDataPath()
87+
{
88+
if (function_exists('getenv') && false !== getenv('APPDATA')) {
89+
return getenv('APPDATA');
90+
} else {
91+
throw new \RuntimeException('Unable to obtain the app data directory.');
92+
}
93+
}
7694
}

0 commit comments

Comments
 (0)