Skip to content

Commit 385d1fc

Browse files
Allow configuring current project with minimal config (#1039)
## Changes <!-- Summary of your changes that are easy to understand --> ## Tests <!-- How is this tested? -->
1 parent 661b66f commit 385d1fc

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

packages/databricks-vscode/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@
305305
"viewsWelcome": [
306306
{
307307
"view": "configurationView",
308-
"contents": "Configure your Databricks workspace:\n[Configure Databricks](command:databricks.bundle.startManualMigration)",
308+
"contents": "Initialise current project as a Databricks project:\n[Initialise Project](command:databricks.bundle.startManualMigration)",
309309
"when": "workspaceFolderCount > 0 && databricks.context.initialized && databricks.context.pendingManualMigration"
310310
},
311311
{
@@ -315,17 +315,22 @@
315315
},
316316
{
317317
"view": "configurationView",
318-
"contents": "Current workspace has no Databricks configuration at the root level, do you want to initialize a new Databricks project?\n[Initialize New Project](command:databricks.bundle.initNewProject)\n[Show Quickstart](command:databricks.quickstart.open)\nTo learn more about how to use Databricks with VS Code [read our docs](https://docs.databricks.com/dev-tools/vscode-ext.html).",
318+
"contents": "Create a new Databricks project?\n[Create a new Databricks Project](command:databricks.bundle.initNewProject)",
319319
"when": "workspaceFolderCount > 0 && databricks.context.initialized && !databricks.context.pendingManualMigration"
320320
},
321+
{
322+
"view": "configurationView",
323+
"contents": "[Show Quickstart](command:databricks.quickstart.open)\nTo learn more about how to use Databricks with VS Code [read our docs](https://docs.databricks.com/dev-tools/vscode-ext.html).",
324+
"when": "databricks.context.initialized"
325+
},
321326
{
322327
"view": "configurationView",
323328
"contents": "Initializing...",
324329
"when": "workspaceFolderCount > 0 && !databricks.context.initialized"
325330
},
326331
{
327332
"view": "configurationView",
328-
"contents": "The workspace is empty.\n[Initialize New Project](command:databricks.bundle.initNewProject)\n[Open Folder](command:vscode.openFolder)\nTo learn more about how to use Databricks with VS Code [read our docs](https://docs.databricks.com/dev-tools/vscode-ext.html).",
333+
"contents": "The workspace is empty.\n[Initialize New Project](command:databricks.bundle.initNewProject)",
329334
"when": "workspaceFolderCount == 0"
330335
}
331336
],

packages/databricks-vscode/resources/migration-template/databricks_template_schema.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
"compute_id": {
99
"type": "string",
1010
"description": "Compute id",
11+
"default": "",
1112
"order": 2
1213
},
1314
"root_path": {
1415
"type": "string",
1516
"description": "Root path",
17+
"default": "",
1618
"order": 3
1719
}
1820
}

packages/databricks-vscode/src/bundle/BundleProjectManager.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {ExtensionContext, Disposable, Uri, window} from "vscode";
22
import fs from "node:fs/promises";
33
import path from "path";
4+
import os from "node:os";
45
import {ConnectionManager} from "../configuration/ConnectionManager";
56
import {ConfigModel} from "../configuration/models/ConfigModel";
67
import {BundleFileSet, getSubProjects} from "./BundleFileSet";
@@ -91,6 +92,18 @@ export class BundleProjectManager {
9192
// configurationView with the configureManualMigration button.
9293
this.detectLegacyProjectConfig(),
9394
]);
95+
// This method checks if we are already in a project but don't have a legacy config. In this case, it sets pendingManualMigration
96+
// context to enable configurationView with the configureManualMigration button.
97+
await this.isInProjectWithoutConfig();
98+
}
99+
100+
private async isInProjectWithoutConfig() {
101+
if (
102+
this.legacyProjectConfig === undefined &&
103+
!(await this.isBundleProject())
104+
) {
105+
this.customWhenContext.setPendingManualMigration(true);
106+
}
94107
}
95108

96109
private async configureBundleProject() {
@@ -193,8 +206,8 @@ export class BundleProjectManager {
193206
authProvider = await saveNewProfile(profileName, authProvider);
194207
}
195208
await this.migrateProjectJsonToBundle(
196-
legacyProjectConfig,
197-
authProvider as ProfileAuthProvider
209+
authProvider as ProfileAuthProvider,
210+
legacyProjectConfig
198211
);
199212
}
200213

@@ -204,32 +217,29 @@ export class BundleProjectManager {
204217
},
205218
})
206219
public async startManualMigration() {
207-
if (!this.legacyProjectConfig) {
208-
throw new Error("Can't migrate without project configuration");
209-
}
210220
const authProvider = await LoginWizard.run(this.cli, this.configModel);
211221
if (
212222
authProvider instanceof ProfileAuthProvider &&
213223
(await authProvider.check())
214224
) {
215225
return this.migrateProjectJsonToBundle(
216-
this.legacyProjectConfig!,
217-
authProvider
226+
authProvider,
227+
this.legacyProjectConfig
218228
);
219229
} else {
220230
this.logger.debug("Incorrect auth for the project.json migration");
221231
}
222232
}
223233

224234
private async migrateProjectJsonToBundle(
225-
legacyProjectConfig: ProjectConfigFile,
226-
authProvider: ProfileAuthProvider
235+
authProvider: ProfileAuthProvider,
236+
legacyProjectConfig?: ProjectConfigFile
227237
) {
228238
const configVars = {
229239
/* eslint-disable @typescript-eslint/naming-convention */
230240
project_name: path.basename(this.workspaceUri.fsPath),
231-
compute_id: legacyProjectConfig.clusterId,
232-
root_path: legacyProjectConfig.workspacePath?.path,
241+
compute_id: legacyProjectConfig?.clusterId,
242+
root_path: legacyProjectConfig?.workspacePath?.path,
233243
/* eslint-enable @typescript-eslint/naming-convention */
234244
};
235245
this.logger.debug("Starting bundle migration, config:", configVars);
@@ -238,7 +248,15 @@ export class BundleProjectManager {
238248
".databricks",
239249
"migration-config.json"
240250
);
251+
await fs.mkdir(path.dirname(configFilePath), {recursive: true});
241252
await fs.writeFile(configFilePath, JSON.stringify(configVars, null, 4));
253+
254+
// TODO: Add to .gitignore only if it's not already there
255+
await fs.appendFile(
256+
path.join(path.dirname(path.dirname(configFilePath)), ".gitignore"),
257+
os.EOL + ".databricks" + os.EOL
258+
);
259+
242260
const templateDirPath = this.context.asAbsolutePath(
243261
path.join("resources", "migration-template")
244262
);

0 commit comments

Comments
 (0)