public async getActivationCommandsForInterpreter()

in src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts [57:107]


    public async getActivationCommandsForInterpreter(
        pythonPath: string,
        targetShell: TerminalShellType,
    ): Promise<string[] | undefined> {
        const envInfo = await this.pyenvs.getCondaEnvironment(pythonPath);
        if (!envInfo) {
            return undefined;
        }

        const condaEnv = envInfo.name.length > 0 ? envInfo.name : envInfo.path;

        // Algorithm differs based on version
        // Old version, just call activate directly.
        // New version, call activate from the same path as our python path, then call it again to activate our environment.
        // -- note that the 'default' conda location won't allow activate to work for the environment sometimes.
        const versionInfo = await this.condaService.getCondaVersion();
        if (versionInfo && versionInfo.major >= CondaRequiredMajor) {
            // Conda added support for powershell in 4.6.
            if (
                versionInfo.minor >= CondaRequiredMinorForPowerShell &&
                (targetShell === TerminalShellType.powershell || targetShell === TerminalShellType.powershellCore)
            ) {
                return _getPowershellCommands(condaEnv);
            }
            if (versionInfo.minor >= CondaRequiredMinor) {
                // New version.
                const interpreterPath = await this.condaService.getCondaFileFromInterpreter(pythonPath, envInfo.name);
                if (interpreterPath) {
                    const activatePath = path.join(path.dirname(interpreterPath), 'activate').fileToCommandArgument();
                    const firstActivate = this.platform.isWindows ? activatePath : `source ${activatePath}`;
                    return [firstActivate, `conda activate ${condaEnv.toCommandArgument()}`];
                }
            }
        }

        switch (targetShell) {
            case TerminalShellType.powershell:
            case TerminalShellType.powershellCore:
                return _getPowershellCommands(condaEnv);

            // TODO: Do we really special-case fish on Windows?
            case TerminalShellType.fish:
                return getFishCommands(condaEnv, await this.condaService.getCondaFile());

            default:
                if (this.platform.isWindows) {
                    return this.getWindowsCommands(condaEnv);
                }
                return getUnixCommands(condaEnv, await this.condaService.getCondaFile());
        }
    }