Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add /opt/python to environment search directories #6261

Merged
merged 1 commit into from
Feb 10, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@ class NativePythonFinderImpl extends DisposableBase implements NativePythonFinde
const options: ConfigurationOptions = {
workspaceDirectories: getWorkspaceFolderPaths(),
// We do not want to mix this with `search_paths`
environmentDirectories: getCustomVirtualEnvDirs(),
// --- Start Positron ---
environmentDirectories: getEnvironmentDirs(),
// --- End Positron ---
condaExecutable: getPythonSettingAndUntildify<string>(CONDAPATH_SETTING_KEY),
poetryExecutable: getPythonSettingAndUntildify<string>('poetryPath'),
cacheDirectory: this.cacheDirectory?.fsPath,
Expand Down Expand Up @@ -437,6 +439,35 @@ function getCustomVirtualEnvDirs(): string[] {
return Array.from(new Set(venvDirs));
}

// --- Start Positron ---
/**
* Gets the list of directories to search for Python environments.
* @returns List of directories to search for Python environments.
*/
function getEnvironmentDirs(): string[] {
const venvDirs = getCustomVirtualEnvDirs();
const additionalDirs = getAdditionalEnvDirs();
const uniqueEnvDirs = new Set([...venvDirs, ...additionalDirs]);
return Array.from(uniqueEnvDirs);
}

/**
* Gets the list of additional directories to add to environment directories.
* @returns List of directories to add to environment directories.
*/
function getAdditionalEnvDirs(): string[] {
const additionalDirs: string[] = [];
if (!isWindows()) {
// /opt/python is a recommended Python installation location on Posit Workbench.
// see: https://docs.posit.co/ide/server-pro/python/installing_python.html
additionalDirs.push('/opt/python');
}
// TODO: add user-specified additional directories to include in discovery
// see: https://github.com/posit-dev/positron/issues/3574
return additionalDirs;
}
// --- End Positron ---

function getPythonSettingAndUntildify<T>(name: string, scope?: Uri): T | undefined {
const value = getConfiguration('python', scope).get<T>(name);
if (typeof value === 'string') {
Expand Down
Loading