Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions extensions/vscode/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Credentials } from "./resources/Credentials";
import { ContentRecords } from "./resources/ContentRecords";
import { Configurations } from "./resources/Configurations";
import { Files } from "./resources/Files";
import { Interpreters } from "./resources/Interpreters";

import { Packages } from "./resources/Packages";
import { Secrets } from "./resources/Secrets";
import { SnowflakeConnections } from "./resources/SnowflakeConnections";
Expand All @@ -20,7 +20,6 @@ class PublishingClientApi {
private client;

configurations: Configurations;
interpreters: Interpreters;
credentials: Credentials;
contentRecords: ContentRecords;
files: Files;
Expand Down Expand Up @@ -57,7 +56,7 @@ class PublishingClientApi {
this.credentials = new Credentials(this.client);
this.contentRecords = new ContentRecords(this.client);
this.files = new Files(this.client);
this.interpreters = new Interpreters(this.client);

this.packages = new Packages(this.client);
this.secrets = new Secrets(this.client);
this.integrationRequests = new IntegrationRequests(this.client);
Expand Down
31 changes: 0 additions & 31 deletions extensions/vscode/src/api/resources/Interpreters.ts

This file was deleted.

86 changes: 84 additions & 2 deletions extensions/vscode/src/api/types/configurations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ describe("Configurations Types", () => {
version: "4.4.0",
packageFile: "renv.lock",
packageManager: "renv",
requiresR: ">= 4.4.0",
});
expect(config.configuration.python).toEqual({
version: "3.11.0",
packageFile: "requirements.txt",
packageManager: "pip",
requiresPython: ">=3.11",
});
});

Expand All @@ -74,8 +76,14 @@ describe("Configurations Types", () => {

UpdateConfigWithDefaults(config, interpreterDefaults);

const expectedRConf: RConfig = { ...incomingIntprConfig };
const expectedPythonConf: PythonConfig = { ...incomingIntprConfig };
const expectedRConf: RConfig = {
...incomingIntprConfig,
requiresR: ">= 4.4.0",
};
const expectedPythonConf: PythonConfig = {
...incomingIntprConfig,
requiresPython: ">=3.11",
};

if (version === "") {
expectedRConf.version = "4.4.0";
Expand All @@ -96,6 +104,78 @@ describe("Configurations Types", () => {
expect(config.configuration.python).toEqual(expectedPythonConf);
},
);

test("fills in requiresPython from defaults when config has no requiresPython", () => {
const config: Configuration = configurationFactory.build();
config.configuration.python = { ...blankIntprConf };

UpdateConfigWithDefaults(config, interpreterDefaults);
expect(config.configuration.python!.requiresPython).toBe(">=3.11");
});

test("preserves existing requiresPython when already set", () => {
const config: Configuration = configurationFactory.build();
config.configuration.python = {
...blankIntprConf,
requiresPython: ">=3.9,<4",
};

UpdateConfigWithDefaults(config, interpreterDefaults);
expect(config.configuration.python!.requiresPython).toBe(">=3.9,<4");
});

test("fills in requiresR from defaults when config has no requiresR", () => {
const config: Configuration = configurationFactory.build();
config.configuration.r = { ...blankIntprConf };

UpdateConfigWithDefaults(config, interpreterDefaults);
expect(config.configuration.r!.requiresR).toBe(">= 4.4.0");
});

test("preserves existing requiresR when already set", () => {
const config: Configuration = configurationFactory.build();
config.configuration.r = {
...blankIntprConf,
requiresR: ">= 4.1.0",
};

UpdateConfigWithDefaults(config, interpreterDefaults);
expect(config.configuration.r!.requiresR).toBe(">= 4.1.0");
});

test("does not set requiresPython when defaults have no requiresPython", () => {
const config: Configuration = configurationFactory.build();
config.configuration.python = { ...blankIntprConf };

const defaultsWithoutRequires: InterpreterDefaults = {
...interpreterDefaults,
python: {
version: "3.11.0",
packageFile: "requirements.txt",
packageManager: "pip",
},
};

UpdateConfigWithDefaults(config, defaultsWithoutRequires);
expect(config.configuration.python!.requiresPython).toBeUndefined();
});

test("does not set requiresR when defaults have no requiresR", () => {
const config: Configuration = configurationFactory.build();
config.configuration.r = { ...blankIntprConf };

const defaultsWithoutRequires: InterpreterDefaults = {
...interpreterDefaults,
r: {
version: "4.4.0",
packageFile: "renv.lock",
packageManager: "renv",
},
};

UpdateConfigWithDefaults(config, defaultsWithoutRequires);
expect(config.configuration.r!.requiresR).toBeUndefined();
});
});

describe("UpdateAllConfigsWithDefaults", () => {
Expand All @@ -119,11 +199,13 @@ describe("Configurations Types", () => {
version: "4.4.0",
packageFile: "renv.lock",
packageManager: "renv",
requiresR: ">= 4.4.0",
});
expect(cf.configuration.python).toEqual({
version: "3.11.0",
packageFile: "requirements.txt",
packageManager: "pip",
requiresPython: ">=3.11",
});
});
});
Expand Down
7 changes: 7 additions & 0 deletions extensions/vscode/src/api/types/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ export function UpdateConfigWithDefaults(
if (!config.configuration.r.packageManager) {
config.configuration.r.packageManager = defaults.r.packageManager;
}
if (!config.configuration.r.requiresR) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this (and the python equivalent below) seem obviously right, but I'm surprised this wasn't already here? This function predates the migration project. Was there an existing bug here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, yeah - I believe this was a bug. I should add that to the PR description, sorry.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're not just moving, we're improving!

config.configuration.r.requiresR = defaults.r.requiresR;
}
}
if (config.configuration.python !== undefined) {
if (!config.configuration.python.version) {
Expand All @@ -229,6 +232,10 @@ export function UpdateConfigWithDefaults(
config.configuration.python.packageManager =
defaults.python.packageManager;
}
if (!config.configuration.python.requiresPython) {
config.configuration.python.requiresPython =
defaults.python.requiresPython;
}
}
return config;
}
23 changes: 11 additions & 12 deletions extensions/vscode/src/state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ class mockApiClient {
list: vi.fn(),
reset: vi.fn(),
};

readonly interpreters = {
get: vi.fn(() => {
return {
data: {
dir: "/usr/proj",
r: "/usr/bin/r",
python: "/usr/bin/python",
},
};
}),
};
}

const mockClient = new mockApiClient();
Expand Down Expand Up @@ -71,6 +59,17 @@ vi.mock("src/utils/vscode", () => ({
getRInterpreterPath: vi.fn(),
}));

vi.mock("src/interpreters", () => ({
getInterpreterDefaults: vi.fn(() =>
Promise.resolve({
python: { version: "", packageFile: "", packageManager: "" },
preferredPythonPath: "",
r: { version: "", packageFile: "", packageManager: "" },
preferredRPath: "",
}),
),
}));

const mockSyncAllCredentials = vi.fn();
vi.mock("src/credentialSecretStorage", () => ({
syncAllCredentials: (...args: unknown[]) => mockSyncAllCredentials(...args),
Expand Down
20 changes: 10 additions & 10 deletions extensions/vscode/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
useApi,
} from "src/api";
import { normalizeURL } from "src/utils/url";
import { getInterpreterDefaults } from "src/interpreters";
import { showProgress } from "src/utils/progress";
import {
getStatusFromError,
Expand Down Expand Up @@ -249,15 +250,14 @@ export class PublisherState implements Disposable {
root,
);

const api = await useApi();
const python = await getPythonInterpreterPath();
const r = await getRInterpreterPath();
const defaults = await api.interpreters.get(
const defaults = await getInterpreterDefaults(
contentRecord.projectDir,
r,
python,
python?.pythonPath,
r?.rPath,
);
const updated = UpdateConfigWithDefaults(cfg, defaults.data);
const updated = UpdateConfigWithDefaults(cfg, defaults);
// its not foolproof, but it may help
if (!this.findConfig(updated.configurationName, updated.projectDir)) {
this.configurations.push(updated);
Expand Down Expand Up @@ -332,16 +332,16 @@ export class PublisherState implements Disposable {
return;
}

const api = await useApi();
const python = await getPythonInterpreterPath();
const r = await getRInterpreterPath();

const configs = await loadAllConfigurationsRecursive(root);
const defaults = await api.interpreters.get(".", r, python);
this.configurations = UpdateAllConfigsWithDefaults(
configs,
defaults.data,
const defaults = await getInterpreterDefaults(
".",
python?.pythonPath,
r?.rPath,
);
this.configurations = UpdateAllConfigsWithDefaults(configs, defaults);
},
);
} catch (error: unknown) {
Expand Down
2 changes: 2 additions & 0 deletions extensions/vscode/src/test/unit-test-utils/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ export const interpreterDefaultsFactory = Factory.define<InterpreterDefaults>(
packageFile: "requirements.txt",
packageManager: "pip",
version: "3.11.0",
requiresPython: ">=3.11",
},
preferredRPath: "usr/bin/R",
r: {
packageFile: "renv.lock",
packageManager: "renv",
version: "4.4.0",
requiresR: ">= 4.4.0",
},
}),
);
Expand Down
4 changes: 0 additions & 4 deletions internal/services/api/api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ func RouterHandlerFunc(base util.AbsolutePath, lister accounts.AccountList, log
r.Handle(ToPath("deployments", "{name}", "environment"), GetDeploymentEnvironmentHandlerFunc(base, log, lister)).
Methods(http.MethodGet)

// GET /api/interpreters
r.Handle(ToPath("interpreters"), GetActiveInterpretersHandlerFunc(base, log)).
Methods(http.MethodGet)

// POST /api/packages/python/scan
r.Handle(ToPath("packages", "python", "scan"), NewPostPackagesPythonScanHandler(base, log)).
Methods(http.MethodPost)
Expand Down
70 changes: 0 additions & 70 deletions internal/services/api/get_interpreters.go

This file was deleted.

Loading
Loading