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 support for detection and selection of conda environments lacking a python interpreter #18427

Merged
merged 46 commits into from
Mar 21, 2022

Conversation

karrtikr
Copy link

@karrtikr karrtikr commented Feb 3, 2022

Closes #18357

Key changes:

  • ConfigService.pythonPath can now also carry the path to the environment folder. So we remove uses of .pythonPath in favor of using InterpreterService.getActiveInterpreter to get interpreter path instead.
  • Given interpreter paths are no longer unique, the API has been updated to handle "environments" instead of interpreters.

@karrtikr karrtikr changed the title Detect conda environments lacking a python interpreter Add support for detection and selection of conda environments lacking a python interpreter Feb 3, 2022
@karrtikr karrtikr force-pushed the condawithoutpython branch 2 times, most recently from b1e8a5a to 39d7ecd Compare February 4, 2022 12:57
@karrtikr karrtikr force-pushed the condawithoutpython branch 2 times, most recently from 40fbc61 to 20a90f1 Compare February 10, 2022 16:55
@@ -64,7 +64,8 @@ export abstract class ModuleInstaller implements IModuleInstaller {
const interpreter = isResource(resource)
? await interpreterService.getActiveInterpreter(resource)
: resource;
const pythonPath = isResource(resource) ? settings.pythonPath : resource.path;
Copy link
Author

Choose a reason for hiding this comment

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

.pythonPath can also be path to environment, so use interpreter.path.

@@ -75,7 +75,7 @@ export class CondaInstaller extends ModuleInstaller {

const pythonPath = isResource(resource)
? this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(resource).pythonPath
: resource.path;
Copy link
Author

Choose a reason for hiding this comment

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

.path is no longer unique.

@@ -75,7 +75,7 @@ export class CondaInstaller extends ModuleInstaller {

const pythonPath = isResource(resource)
? this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(resource).pythonPath
: resource.path;
Copy link
Author

Choose a reason for hiding this comment

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

.path is no longer unique.

@@ -36,24 +40,18 @@ export abstract class ModuleInstaller implements IModuleInstaller {
resource?: InterpreterUri,
cancel?: CancellationToken,
flags?: ModuleInstallFlags,
options?: InstallOptions,
Copy link
Author

Choose a reason for hiding this comment

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

Add support for installing modules as a process. Earlier we just sent the command in terminal.

@karrtikr karrtikr marked this pull request as ready for review March 17, 2022 11:32
Comment on lines +32 to +34
// For conda environments not containing a python interpreter, do not use pip installer due to bugs in `conda run`:
// https://github.com/microsoft/vscode-python/issues/18479#issuecomment-1044427511
// https://github.com/conda/conda/issues/11211
Copy link
Author

Choose a reason for hiding this comment

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

That is, conda run -n <envname> python -m pip install <module> doesn't work.

return true;
}

public async install(
Copy link
Author

Choose a reason for hiding this comment

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

Runs conda install -n <envname> python for environments lacking an interpreter, so they become normal conda environments.

@@ -162,7 +161,14 @@ export async function createCondaEnv(
(file, args, opts) => procs.exec(file, args, opts),
(command, opts) => procs.shellExec(command, opts),
);
return new PythonEnvironment(pythonPath, deps);
Copy link
Author

Choose a reason for hiding this comment

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

pythonPath can also be path to env folder, whereas the first parameter should refer to interpreter path.

@@ -185,19 +187,19 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand {
itemsWithFullName,
this.workspaceService.getWorkspaceFolder(resource)?.uri,
);
if (recommended && arePathsSame(items[0].interpreter.path, recommended.interpreter.path)) {
Copy link
Author

Choose a reason for hiding this comment

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

.path is no longer unique so use .id.

@@ -28,6 +28,16 @@ export enum PythonEnvKind {
OtherVirtual = 'virt-other',
}

export interface EnvPathType {
Copy link
Author

Choose a reason for hiding this comment

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

Uniquely identifies an environment.

@@ -150,3 +153,17 @@ function getResolvedEnv(interpreterInfo: InterpreterInformation, environment: Py
setEnvDisplayString(resolvedEnv);
return resolvedEnv;
}

async function getExecutablePathAndEnvPath(path: string) {
Copy link
Author

Choose a reason for hiding this comment

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

path can either be a python executable or env path.

Copy link

@kimadeline kimadeline left a comment

Choose a reason for hiding this comment

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

I understand the broad context of these changes (and renaming many __interpreter__ functions to __environment__ to reflect the new support), but the intricacies of this PR flew above my head 😅

You already got Karthik's approval so I assume this PR is good to go, are there any specific changes I should focus on?

@karrtikr
Copy link
Author

@kimadeline I see 😅 I think it's better to validate all the intricacies anyways. So I would like to merge this now so it can be tested properly for testing week.

@karrtikr karrtikr merged commit f1d0509 into microsoft:main Mar 21, 2022
@karrtikr karrtikr deleted the condawithoutpython branch March 21, 2022 12:22
wesm pushed a commit to posit-dev/positron that referenced this pull request Mar 28, 2024
… a python interpreter (microsoft/vscode-python#18427)

* Support conda environments without a python executable

* Fix interpreter display

* Fix areSameEnv

* Add support to select env folders as interpreterPaths

* Allow selecting such environments

* Handle resolving environment path

* Document resolver works for both env path and executable

* Fxi bug

* Simplify conda.ts

* Define identifiers for an environment

* Fix getCondaEnvironment

* Introduce an id property to environments

* Update proposed discovery API to handle environments

* Fix bug with interpreter display

* Normalize path passed in resolveEnv

* Update environment details API

* Dont use pythonPath for getting active interpreter for activation commands

* Support conda activation

* Support ${command:python.interpreterPath} with this envs

* Fix getActiveItem

* Add comment justifying using `.pythonPath` for middleware

* Fix shebang codelens

* Fix startup telemetry

* Do not support pip installer for such environments

* Trigger discovery once installation is finished for such environments

* Automatically install python into environment once it is selected

* Add telemetry for new interpreters discovered

* Add telemtry if such an env is selected

* Fix bugs and cache installer

* Fix compile errors, tests, and add tests

* Fix some tests

* Ignore id when comparing envs

* Phew, fixed terrible tests in module installer

* Fix more tests

* MOre

* Skip resolver tests on linux

* Fix tests

* If environment doesn't contain python do not support pip installer

* Skip module install tests for python as it is not a module

* News entry

* Remove unnecssary commnet

* Fix bug introduced by merges

* Code reviews
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support discovering multiple conda envs with same interpreter path
3 participants