mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-25 01:25:36 -05:00
change to fs to write file (#4736)
* change to fs to write file * Added more env variables check as well * Resolve PR comments * Merge master * Add file name exist check and delete it after test is done
This commit is contained in:
@@ -8,7 +8,9 @@
|
||||
import 'mocha';
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as tempWrite from 'temp-write';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
|
||||
export class CellTypes {
|
||||
public static readonly Code = 'code';
|
||||
@@ -73,7 +75,12 @@ export const pythonKernelMetadata = {
|
||||
|
||||
export function writeNotebookToFile(pythonNotebook: azdata.nb.INotebookContents): vscode.Uri {
|
||||
let notebookContentString = JSON.stringify(pythonNotebook);
|
||||
let localFile = tempWrite.sync(notebookContentString, 'notebook.ipynb');
|
||||
let localFile = path.join(os.tmpdir(), 'notebook' + Math.floor(Math.random() * 101) + '.ipynb');
|
||||
while (fs.existsSync(localFile)) {
|
||||
localFile = path.join(os.tmpdir(), 'notebook' + Math.floor(Math.random() * 101) + '.ipynb');
|
||||
}
|
||||
fs.writeFileSync(localFile, notebookContentString);
|
||||
console.log(`Local file is created: '${localFile}'`);
|
||||
let uri = vscode.Uri.file(localFile);
|
||||
return uri;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user