Changes to use bundled python package (#12967)

* Set python path in kernel specs when running on SAW devices.

* Use tab spacer for kernel json.

* Update path to jupyter kernelspec.

* removing the kernelspec write

* Changed powershell kernel.json to use  appdata folder

* Addressed PR and added try catches around the code.

* removed redundant try catch

* removed redundant try catch

* removed another try catch

* removed space

Co-authored-by: Cory Rivera <corivera@microsoft.com>
This commit is contained in:
rajeshka
2020-10-19 18:20:48 -07:00
committed by GitHub
parent eb36a275a2
commit c4f649a849
4 changed files with 47 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ export interface IKernelInfo {
name: string;
language?: string;
display_name?: string;
argv?: string[];
}
export interface ILanguageInfo {

View File

@@ -17,6 +17,7 @@ import * as constants from '../common/constants';
import * as utils from '../common/utils';
import { Deferred } from '../common/promise';
import { ConfigurePythonWizard } from '../dialog/configurePython/configurePythonWizard';
import { IKernelInfo } from '../contracts/content';
const localize = nls.loadMessageBundle();
const msgInstallPkgProgress = localize('msgInstallPkgProgress', "Notebook dependencies installation is in progress");
@@ -79,6 +80,8 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
private readonly _runningOnSAW: boolean;
private _kernelSpecsUpdated = false;
constructor(extensionPath: string, outputChannel: vscode.OutputChannel) {
this.extensionPath = extensionPath;
this.outputChannel = outputChannel;
@@ -708,6 +711,30 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
public getRequiredPackagesForKernel(kernelName: string): PythonPkgDetails[] {
return this._requiredKernelPackages.get(kernelName) ?? [];
}
public get runningOnSaw(): boolean {
return this._runningOnSAW;
}
public async updateKernelSpecPaths(kernelsFolder: string): Promise<void> {
if (!this._runningOnSAW || this._kernelSpecsUpdated) {
return;
}
let fileNames = await fs.readdir(kernelsFolder);
let filePaths = fileNames.map(name => path.join(kernelsFolder, name));
let fileStats = await Promise.all(filePaths.map(path => fs.stat(path)));
let folderPaths = filePaths.filter((value, index) => value && fileStats[index].isDirectory());
let kernelFiles = folderPaths.map(folder => path.join(folder, 'kernel.json'));
await Promise.all(kernelFiles.map(file => this.updateKernelSpecPath(file)));
this._kernelSpecsUpdated = true;
}
private async updateKernelSpecPath(kernelPath: string): Promise<void> {
let fileContents = await fs.readFile(kernelPath);
let kernelSpec = <IKernelInfo>JSON.parse(fileContents.toString());
kernelSpec.argv = kernelSpec.argv?.map(arg => arg.replace('{ADS_PYTHONDIR}', this._pythonInstallationPath));
await fs.writeFile(kernelPath, JSON.stringify(kernelSpec, undefined, '\t'));
}
}
export interface PythonPkgDetails {

View File

@@ -174,12 +174,20 @@ export class PerFolderServerInstance implements IServerInstance {
}
private async copyKernelsToSystemJupyterDirs(): Promise<void> {
let kernelsExtensionSource = path.join(this.options.install.extensionPath, 'kernels');
let kernelsExtensionSource: string;
if (this.options.install.runningOnSaw) {
kernelsExtensionSource = path.join(this.options.install.extensionPath, 'saw-kernels');
} else {
kernelsExtensionSource = path.join(this.options.install.extensionPath, 'kernels');
}
this._systemJupyterDir = path.join(this.getSystemJupyterHomeDir(), 'kernels');
if (!(await utils.exists(this._systemJupyterDir))) {
await utils.mkDir(this._systemJupyterDir, this.options.install.outputChannel);
}
await fs.copy(kernelsExtensionSource, this._systemJupyterDir);
if (this.options.install.runningOnSaw) {
await this.options.install.updateKernelSpecPaths(this._systemJupyterDir);
}
}
private getSystemJupyterHomeDir(): string {