mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
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:
10
extensions/notebook/saw-kernels/powershell/kernel.json
Normal file
10
extensions/notebook/saw-kernels/powershell/kernel.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"argv": [
|
||||
"{ADS_PYTHONDIR}\\python",
|
||||
"{ADS_PYTHONDIR}\\Lib\\site-packages\\powershell_kernel\\__main__.py",
|
||||
"-f",
|
||||
"{connection_file}"
|
||||
],
|
||||
"display_name": "PowerShell",
|
||||
"language": "powershell"
|
||||
}
|
||||
@@ -20,6 +20,7 @@ export interface IKernelInfo {
|
||||
name: string;
|
||||
language?: string;
|
||||
display_name?: string;
|
||||
argv?: string[];
|
||||
}
|
||||
|
||||
export interface ILanguageInfo {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user