Skip to content

Commit ba368a4

Browse files
authored
[DECO-323] Allow running ipynb files as workflows (#226)
![Screenshot 2022-11-16 at 11 43 47](https://user-images.githubusercontent.com/40952/202160235-d2742975-a9d3-457c-bfa1-e64efe5fe0fa.png)
1 parent bfcc55c commit ba368a4

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

packages/databricks-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@
316316
},
317317
{
318318
"command": "databricks.run.runEditorContentsAsWorkflow",
319-
"when": "resourceLangId == python",
319+
"when": "resourceLangId == python || resourceExtname == .ipynb",
320320
"group": "navigation@1"
321321
}
322322
],

packages/databricks-vscode/src/configuration/SyncDestination.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class SyncDestination {
7878
localToRemoteNotebook(localPath: Uri): string {
7979
assert.equal(localPath.scheme, "file");
8080
return this.localToRemote(localPath).replace(
81-
/^\/Workspace(\/.*).py/g,
81+
/^\/Workspace(\/.*)\.(py|ipynb)/g,
8282
"$1"
8383
);
8484
}

packages/databricks-vscode/src/utils/fileUtils.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ describe(__filename, async () => {
1515
});
1616
});
1717

18+
it("should detect ipynb files", async () => {
19+
assert.ok(await isNotebook(Uri.parse("/home/fabian/hello.ipynb")));
20+
});
21+
1822
it("should detect if not notebook", async () => {
1923
withFile(async (file) => {
2024
await fs.writeFile(file.path, Buffer.from("content"));

packages/databricks-vscode/src/utils/fileUtils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import {TextDecoder} from "util";
22
import {Uri, workspace} from "vscode";
33

44
export async function isNotebook(uri: Uri): Promise<boolean> {
5+
if (uri.path.match(/\.ipynb$/)) {
6+
return true;
7+
}
58
const bytes = await workspace.fs.readFile(uri);
69
const lines = new TextDecoder().decode(bytes).split(/\r?\n/);
710
return (

0 commit comments

Comments
 (0)