Skip to content
Merged
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
16 changes: 15 additions & 1 deletion src/features/projectManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,21 @@ export class PythonProjectManagerImpl implements PythonProjectManager {

// For each override, resolve its path and add as a project if not already present
for (const o of overrides) {
const uri = Uri.file(path.resolve(w.uri.fsPath, o.path));
let uriFromWorkspace: Uri | undefined = undefined;
// if override has a workspace property, resolve the path relative to that workspace
if (o.workspace) {
//
const workspaceFolder = workspaces.find((ws) => ws.name === o.workspace);
if (workspaceFolder) {
if (workspaceFolder.uri.toString() !== w.uri.toString()) {
continue; // skip if the workspace is not the same as the current workspace
}
uriFromWorkspace = Uri.file(path.resolve(workspaceFolder.uri.fsPath, o.path));
}
}
const uri = uriFromWorkspace ? uriFromWorkspace : Uri.file(path.resolve(w.uri.fsPath, o.path));

// Check if the project already exists in the newProjects array
if (!newProjects.some((p) => p.uri.toString() === uri.toString())) {
newProjects.push(new PythonProjectsImpl(o.path, uri));
}
Expand Down
16 changes: 14 additions & 2 deletions src/features/settings/settingHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { PythonProject } from '../../api';
import { DEFAULT_ENV_MANAGER_ID, DEFAULT_PACKAGE_MANAGER_ID } from '../../common/constants';
import { traceError, traceInfo } from '../../common/logging';
import { getWorkspaceFile } from '../../common/workspace.apis';
import { getWorkspaceFile, getWorkspaceFolders } from '../../common/workspace.apis';
import { PythonProjectManager, PythonProjectSettings } from '../../internal.api';

function getSettings(
Expand Down Expand Up @@ -284,6 +284,7 @@ export interface EditProjectSettings {
project: PythonProject;
envManager?: string;
packageManager?: string;
workspace?: string;
}

export async function addPythonProjectSetting(edits: EditProjectSettings[]): Promise<void> {
Expand All @@ -306,13 +307,23 @@ export async function addPythonProjectSetting(edits: EditProjectSettings[]): Pro
traceError(`Unable to find workspace for ${e.project.uri.fsPath}`);
});

const isMultiroot = (getWorkspaceFolders() ?? []).length > 1;

const promises: Thenable<void>[] = [];
workspaces.forEach((es, w) => {
const config = workspace.getConfiguration('python-envs', w.uri);
const overrides = config.get<PythonProjectSettings[]>('pythonProjects', []);
es.forEach((e) => {
if (isMultiroot) {
}
const pwPath = path.normalize(e.project.uri.fsPath);
const index = overrides.findIndex((s) => path.resolve(w.uri.fsPath, s.path) === pwPath);
const index = overrides.findIndex((s) => {
if (s.workspace) {
// If the workspace is set, check workspace and path in existing overrides
return s.workspace === w.name && path.resolve(w.uri.fsPath, s.path) === pwPath;
}
return path.resolve(w.uri.fsPath, s.path) === pwPath;
});
if (index >= 0) {
overrides[index].envManager = e.envManager ?? envManager;
overrides[index].packageManager = e.packageManager ?? pkgManager;
Expand All @@ -321,6 +332,7 @@ export async function addPythonProjectSetting(edits: EditProjectSettings[]): Pro
path: path.relative(w.uri.fsPath, pwPath).replace(/\\/g, '/'),
envManager,
packageManager: pkgManager,
workspace: isMultiroot ? w.name : undefined,
});
}
});
Expand Down
1 change: 1 addition & 0 deletions src/internal.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ export interface PythonProjectSettings {
path: string;
envManager: string;
packageManager: string;
workspace?: string;
}

export class PythonEnvironmentImpl implements PythonEnvironment {
Expand Down