Skip to content

Commit

Permalink
Merge branch 'master' into feat/query-panel-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
saravmajestic authored May 17, 2024
2 parents 45e2455 + 2a9db5e commit e790c55
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 22 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@
"ms-python.python"
],
"dependencies": {
"@vscode/codicons": "^0.0.35",
"@vscode/codicons": "^0.0.36",
"@vscode/extension-telemetry": "^0.9.6",
"@vscode/vsce": "^2.24.0",
"@vscode/webview-ui-toolkit": "^1.4.0",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/sqlToModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class SqlToModel {
if (!event) {
window.showErrorMessage(
extendErrorWithSupportLinks(
"Could not convert to model due to pending initiation, Please retry again.",
"The extension is still initializing, please retry again.",
),
);
this.telemetry.sendTelemetryError("sqlToModelNoManifestError");
Expand Down
17 changes: 15 additions & 2 deletions src/commands/walkthroughCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,14 @@ export class WalkthroughCommands {
const { stdout, stderr } = await this.commandProcessExecutionFactory
.createCommandProcessExecution({
command: this.pythonEnvironment.pythonPath,
args: ["-m", "pip", "install", "dbt", "--no-cache-dir"],
args: [
"-m",
"pip",
"install",
"dbt",
"--no-cache-dir",
"--force-reinstall",
],
cwd: getFirstWorkspacePath(),
envVars: this.pythonEnvironment.environmentVariables,
})
Expand Down Expand Up @@ -232,7 +239,13 @@ export class WalkthroughCommands {
},
async () => {
try {
const args = ["-m", "pip", "install"];
const args = [
"-m",
"pip",
"install",
"--no-cache-dir",
"--force-reinstall",
];
if (packageVersion >= "1.8") {
args.push(`dbt-core==${packageVersion}`);
args.push(`${packageName}>=${packageVersion}`);
Expand Down
92 changes: 81 additions & 11 deletions src/dbt_client/dbtCloudIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@ export class DBTCloudDetection implements DBTDetection {
throw new Error(stderr);
}
if (stdout.includes("dbt Cloud CLI")) {
const regex = /dbt Cloud CLI - (\d*\.\d*\.\d*)/gm;
const matches = regex.exec(stdout);
if (matches?.length === 2) {
const version = matches[1].split(".");
const minVersion = "0.37.6";
if (
parseInt(version[0]) <= 0 &&
parseInt(version[1]) <= 37 &&
parseInt(version[2]) <= 6
) {
window.showErrorMessage(
`This version of dbt Cloud is not supported. Please update to a dbt Cloud CLI version higher than ${minVersion}`,
);
this.terminal.debug(
"DBTCLIDetectionFailed",
"dbt cloud cli was found but version is not supported. Detection command returned : " +
stdout,
);
return true;
}
}
this.terminal.debug("DBTCLIDetectionSuccess", "dbt cloud cli detected");
return true;
} else {
Expand Down Expand Up @@ -169,6 +190,7 @@ export class DBTCloudProjectIntegration
private rebuildManifestCancellationTokenSource:
| CancellationTokenSource
| undefined;
private pathsInitalized = false;

constructor(
private executionInfrastructure: DBTCommandExecutionInfrastructure,
Expand Down Expand Up @@ -208,7 +230,13 @@ export class DBTCloudProjectIntegration
}

async refreshProjectConfig(): Promise<void> {
await this.initializePaths();
if (!this.pathsInitalized) {
// First time let,s block
await this.initializePaths();
this.pathsInitalized = true;
} else {
this.initializePaths();
}
this.findAdapterType();
}

Expand Down Expand Up @@ -489,7 +517,7 @@ export class DBTCloudProjectIntegration
),
);
command.addArgument("--source");
command.addArgument("dbtPowerUser");
command.addArgument("dbt-power-user");
return command;
}

Expand Down Expand Up @@ -774,14 +802,56 @@ export class DBTCloudProjectIntegration

// get dbt config
private async initializePaths() {
// all hardcoded as there is no way to get them reliably
// we can't parse jinja
// TODO: read from dbt_project.yml instead
this.targetPath = join(this.projectRoot.fsPath, "target");
this.modelPaths = [join(this.projectRoot.fsPath, "models")];
this.seedPaths = [join(this.projectRoot.fsPath, "seeds")];
this.macroPaths = [join(this.projectRoot.fsPath, "macros")];
this.packagesInstallPath = join(this.projectRoot.fsPath, "dbt_packages");
const packagePathsCommand = this.dbtCloudCommand(
new DBTCommand("Getting paths...", [
"environment",
"show",
"--project-paths",
]),
);
try {
const { stdout, stderr } = await packagePathsCommand.execute();
if (stderr) {
this.terminal.warn(
"DbtCloudIntegrationInitializePathsStdError",
"packaging paths command returns warning, ignoring",
true,
stderr,
);
}
const lookupEntries = (lookupString: string) => {
const regexString = `${lookupString}\\s*\\[(.*)\\]`;
const regexp = new RegExp(regexString, "gm");
const matches = regexp.exec(stdout);
if (matches?.length === 2) {
return matches[1].split(",").map((m) => m.slice(1, -1));
}
throw new Error(`Could not find any entries for ${lookupString}`);
};
this.targetPath = join(this.projectRoot.fsPath, "target");
this.modelPaths = lookupEntries("Model paths").map((p) =>
join(this.projectRoot.fsPath, p),
);
this.seedPaths = lookupEntries("Seed paths").map((p) =>
join(this.projectRoot.fsPath, p),
);
this.macroPaths = lookupEntries("Macro paths").map((p) =>
join(this.projectRoot.fsPath, p),
);
this.packagesInstallPath = join(this.projectRoot.fsPath, "dbt_packages");
} catch (error) {
this.terminal.warn(
"DbtCloudIntegrationInitializePathsExceptionError",
"adapter type throws error, ignoring",
true,
error,
);
this.targetPath = join(this.projectRoot.fsPath, "target");
this.modelPaths = [join(this.projectRoot.fsPath, "models")];
this.seedPaths = [join(this.projectRoot.fsPath, "seeds")];
this.macroPaths = [join(this.projectRoot.fsPath, "macros")];
this.packagesInstallPath = join(this.projectRoot.fsPath, "dbt_packages");
}
}

private async findAdapterType() {
Expand All @@ -800,7 +870,7 @@ export class DBTCloudProjectIntegration
const { stdout, stderr } = await adapterTypeCommand.execute();
if (stderr) {
this.terminal.warn(
"DbtCloudIntegrationAdapterDetectioStdErrError",
"DbtCloudIntegrationAdapterDetectionStdError",
"adapter type returns stderr, ignoring",
true,
stderr,
Expand Down

0 comments on commit e790c55

Please sign in to comment.