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

Commit 9fd5c81

Browse files
committed
Changed paths to use environment variables
1 parent 21ee6de commit 9fd5c81

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/Installer/WindowsInstaller.php

Lines changed: 22 additions & 4 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);
@@ -65,12 +65,30 @@ protected function executeSilentComposerCommand($installPath)
6565

6666
exec(
6767
$this->composerCmd . ' --prefer-dist --no-interaction --no-progress --working-dir="' .
68-
$installPath . '" create-project litipk/jupyter-php=dev-master pkgs > nul 2>&1 ',
68+
$installPath . '" create-project litipk/jupyter-php=dev-master' . ' pkgs > nul 2>&1 ',
6969

7070
$composerOutputLines,
7171
$composerStatus
7272
);
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)