mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-10 10:12:34 -05:00
Change configure Jupyter server steps from async to sync (#13937)
* change config steps to sync * fix tests * use pathexistsSync * remove pathExistsSync call * address PR comments
This commit is contained in:
@@ -22,13 +22,13 @@ export function getLivyUrl(serverName: string, port: string): string {
|
||||
return this.getKnoxUrl(serverName, port) + '/default/livy/v1/';
|
||||
}
|
||||
|
||||
export async function mkDir(dirPath: string, outputChannel?: vscode.OutputChannel): Promise<void> {
|
||||
if (!await fs.pathExists(dirPath)) {
|
||||
if (outputChannel) {
|
||||
outputChannel.appendLine(localize('mkdirOutputMsg', "... Creating {0}", dirPath));
|
||||
}
|
||||
await fs.ensureDir(dirPath);
|
||||
}
|
||||
export async function ensureDir(dirPath: string, outputChannel?: vscode.OutputChannel): Promise<void> {
|
||||
outputChannel?.appendLine(localize('ensureDirOutputMsg', "... Ensuring {0} exists", dirPath));
|
||||
await fs.ensureDir(dirPath);
|
||||
}
|
||||
export function ensureDirSync(dirPath: string, outputChannel?: vscode.OutputChannel): void {
|
||||
outputChannel?.appendLine(localize('ensureDirOutputMsg', "... Ensuring {0} exists", dirPath));
|
||||
fs.ensureDirSync(dirPath);
|
||||
}
|
||||
|
||||
export function getErrorMessage(error: Error | string): string {
|
||||
|
||||
@@ -259,7 +259,7 @@ export class JupyterSession implements nb.ISession {
|
||||
|
||||
public async configureKernel(): Promise<void> {
|
||||
let sparkmagicConfDir = path.join(utils.getUserHome(), '.sparkmagic');
|
||||
await utils.mkDir(sparkmagicConfDir);
|
||||
await utils.ensureDir(sparkmagicConfDir);
|
||||
|
||||
// Default to localhost in config file.
|
||||
let creds: ICredentials = {
|
||||
|
||||
@@ -142,34 +142,34 @@ export class PerFolderServerInstance implements IServerInstance {
|
||||
}
|
||||
|
||||
private async configureJupyter(): Promise<void> {
|
||||
await this.createInstanceFolders();
|
||||
this.createInstanceFolders();
|
||||
let resourcesFolder = path.join(this.options.install.extensionPath, 'resources', constants.jupyterConfigRootFolder);
|
||||
await this.copyInstanceConfig(resourcesFolder);
|
||||
await this.CopyCustomJs(resourcesFolder);
|
||||
this.copyInstanceConfig(resourcesFolder);
|
||||
this.copyCustomJs(resourcesFolder);
|
||||
await this.copyKernelsToSystemJupyterDirs();
|
||||
}
|
||||
|
||||
private async createInstanceFolders(): Promise<void> {
|
||||
private createInstanceFolders(): void {
|
||||
this.baseDir = path.join(this.getSystemJupyterHomeDir(), 'instances', `${UUID.generateUuid()}`);
|
||||
this.instanceConfigRoot = path.join(this.baseDir, 'config');
|
||||
this.instanceDataRoot = path.join(this.baseDir, 'data');
|
||||
await utils.mkDir(this.baseDir, this.options.install.outputChannel);
|
||||
await utils.mkDir(this.instanceConfigRoot, this.options.install.outputChannel);
|
||||
await utils.mkDir(this.instanceDataRoot, this.options.install.outputChannel);
|
||||
utils.ensureDirSync(this.baseDir, this.options.install.outputChannel);
|
||||
utils.ensureDirSync(this.instanceConfigRoot, this.options.install.outputChannel);
|
||||
utils.ensureDirSync(this.instanceDataRoot, this.options.install.outputChannel);
|
||||
}
|
||||
|
||||
private async copyInstanceConfig(resourcesFolder: string): Promise<void> {
|
||||
private copyInstanceConfig(resourcesFolder: string): void {
|
||||
let configSource = path.join(resourcesFolder, NotebookConfigFilename);
|
||||
let configDest = path.join(this.instanceConfigRoot, NotebookConfigFilename);
|
||||
await fs.copy(configSource, configDest);
|
||||
fs.copySync(configSource, configDest);
|
||||
}
|
||||
|
||||
private async CopyCustomJs(resourcesFolder: string): Promise<void> {
|
||||
private copyCustomJs(resourcesFolder: string): void {
|
||||
let customPath = path.join(this.instanceConfigRoot, 'custom');
|
||||
await utils.mkDir(customPath, this.options.install.outputChannel);
|
||||
utils.ensureDirSync(customPath, this.options.install.outputChannel);
|
||||
let customSource = path.join(resourcesFolder, CustomJsFilename);
|
||||
let customDest = path.join(customPath, CustomJsFilename);
|
||||
await fs.copy(customSource, customDest);
|
||||
fs.copySync(customSource, customDest);
|
||||
}
|
||||
|
||||
private async copyKernelsToSystemJupyterDirs(): Promise<void> {
|
||||
@@ -180,10 +180,8 @@ export class PerFolderServerInstance implements IServerInstance {
|
||||
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);
|
||||
utils.ensureDirSync(this._systemJupyterDir, this.options.install.outputChannel);
|
||||
fs.copySync(kernelsExtensionSource, this._systemJupyterDir);
|
||||
if (this.options.install.runningOnSaw) {
|
||||
await this.options.install.updateKernelSpecPaths(this._systemJupyterDir);
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ describe('Utils Tests', function () {
|
||||
should(utils.getLivyUrl(host, port)).endWith('/gateway/default/livy/v1/');
|
||||
});
|
||||
|
||||
it('mkDir', async () => {
|
||||
it('ensureDir', async () => {
|
||||
const dirPath = path.join(os.tmpdir(), uuid.v4());
|
||||
await should(fs.stat(dirPath)).be.rejected();
|
||||
await utils.mkDir(dirPath, new MockOutputChannel());
|
||||
await utils.ensureDir(dirPath, new MockOutputChannel());
|
||||
should.exist(await fs.stat(dirPath), `Folder ${dirPath} did not exist after creation`);
|
||||
});
|
||||
|
||||
|
||||
@@ -55,17 +55,15 @@ describe('Jupyter server instance', function (): void {
|
||||
|
||||
it('Should create config and data directories on configure', async function (): Promise<void> {
|
||||
// Given a server instance
|
||||
let mkdirStub = sinon.stub(utils,'mkDir').withArgs(sinon.match.any,sinon.match.any).returns(Promise.resolve());
|
||||
let copyStub = sinon.stub(fs,'copy').returns();
|
||||
let pathStub = sinon.stub(utils,'exists').withArgs(sinon.match.any).returns(Promise.resolve(false));
|
||||
let ensureDirSyncStub = sinon.stub(utils,'ensureDirSync').withArgs(sinon.match.any,sinon.match.any).returns();
|
||||
let copyStub = sinon.stub(fs,'copySync').returns();
|
||||
|
||||
// When I run configure
|
||||
await serverInstance.configure();
|
||||
|
||||
// Then I expect a folder to have been created with config and data subdirs
|
||||
sinon.assert.callCount(mkdirStub,5);
|
||||
sinon.assert.callCount(ensureDirSyncStub,5);
|
||||
sinon.assert.callCount(copyStub,3);
|
||||
sinon.assert.callCount(pathStub,1);
|
||||
});
|
||||
|
||||
it('Should have URI info after start', async function (): Promise<void> {
|
||||
@@ -152,8 +150,8 @@ describe('Jupyter server instance', function (): void {
|
||||
|
||||
it('Should remove directory on close', async function (): Promise<void> {
|
||||
// Given configure and startup are done
|
||||
sinon.stub(utils,'mkDir').withArgs(sinon.match.any,sinon.match.any).returns(Promise.resolve());
|
||||
sinon.stub(fs,'copy').returns();
|
||||
sinon.stub(utils,'ensureDirSync').withArgs(sinon.match.any,sinon.match.any).returns();
|
||||
sinon.stub(fs,'copySync').returns();
|
||||
|
||||
let process = setupSpawn({
|
||||
sdtout: (listener: (msg: string) => void) => { },
|
||||
|
||||
Reference in New Issue
Block a user