Skip to content

Commit

Permalink
Use pixi run to handle running in activated env
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig committed Oct 17, 2024
1 parent d7cd8fa commit 3b1ea6d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/client/interpreter/activation/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { StopWatch } from '../../common/utils/stopWatch';
import { identifyShellFromShellPath } from '../../common/terminal/shellDetectors/baseShellDetector';
import { getSearchPathEnvVarNames } from '../../common/utils/exec';
import { cache } from '../../common/utils/decorators';
import { getRunPixiPythonCommand } from '../../pythonEnvironments/common/environmentManagers/pixi';

const ENVIRONMENT_PREFIX = 'e8b39361-0157-4923-80e1-22d70d46dee6';
const CACHE_DURATION = 10 * 60 * 1000;
Expand Down Expand Up @@ -252,6 +253,11 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
// Using environment prefix isn't needed as the marker script already takes care of it.
command = [...pythonArgv, ...args].map((arg) => arg.toCommandArgumentForPythonExt()).join(' ');
}
} else if (interpreter?.envType === EnvironmentType.Pixi) {
const pythonArgv = await getRunPixiPythonCommand(interpreter.path);
if (pythonArgv) {
command = [...pythonArgv, ...args].map((arg) => arg.toCommandArgumentForPythonExt()).join(' ');
}
}
if (!command) {
const activationCommands = await this.helper.getEnvironmentActivationShellCommands(
Expand Down
24 changes: 24 additions & 0 deletions src/client/pythonEnvironments/common/environmentManagers/pixi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,27 @@ export function registerPixiFeatures(disposables: IDisposableRegistry): void {
}),
);
}

/**
* Returns the `pixi run` command
*/
export async function getRunPixiPythonCommand(pythonPath: string): Promise<string[] | undefined> {
const pixiEnv = await getPixiEnvironmentFromInterpreter(pythonPath);
if (!pixiEnv) {
return undefined;
}

const args = [
pixiEnv.pixi.command.toCommandArgumentForPythonExt(),
'run',
'--manifest-path',
pixiEnv.manifestPath.toCommandArgumentForPythonExt(),
];
if (isNonDefaultPixiEnvironmentName(pixiEnv.envName)) {
args.push('--environment');
args.push(pixiEnv.envName.toCommandArgumentForPythonExt());
}

args.push('python');
return args;
}

0 comments on commit 3b1ea6d

Please sign in to comment.