Skip to content

Allow to deactivate environments activated from pixi shell-hook #3589

@Hofer-Julian

Description

@Hofer-Julian
Contributor

Currently, there's no way to deactivate an environment activated by pixi shell-hook. Let's implement that!

Also see discussion in #3525

Activity

mrswastik-robot

mrswastik-robot commented on Apr 18, 2025

@mrswastik-robot
Contributor

Hi @Hofer-Julian! I would love to contribute to this. Should I start by writing an async function like generate_deactivation_script in shell_hook.rs? I have only solved some good first issues in pixi's codebase till now, so would love to hear more on how a beginner can contribute to this

Hofer-Julian

Hofer-Julian commented on Apr 22, 2025

@Hofer-Julian
ContributorAuthor

Will there be an offical and clean implementation of pixi activate ${path} and pixi deactivate?

Please open a separate issue for that @YuanfengZhang

Hofer-Julian

Hofer-Julian commented on Apr 22, 2025

@Hofer-Julian
ContributorAuthor

I would love to contribute to this. Should I start by writing an async function like generate_deactivation_script in shell_hook.rs? I have only solved some good first issues in pixi's codebase till now, so would love to hear more on how a beginner can contribute to this

@mrswastik-robot sounds good to me. Happy to look at a draft PR as soon as you have something :)

mrswastik-robot

mrswastik-robot commented on Apr 22, 2025

@mrswastik-robot
Contributor

Hi @Hofer-Julian, so I was trying to implement this, but I was having trouble finding the code @wolfv mentioned here in rattler_shell crate. There's definitely code for built-in deactivation() method on the activator object, but it doesn't appear to be a standalone deactivation() method.

For ex. I wrote this function but there isn't any deactivation() method already available:

async fn generate_deactivation_script(
    shell: Option<ShellEnum>,
    environment: &Environment<'_>,
    project: &Workspace,
) -> miette::Result<String> {
 
    let shell = shell.unwrap_or_else(|| {
        ShellEnum::from_parent_process()
            .unwrap_or_else(|| ShellEnum::from_env().unwrap_or_default())
    });

    let activator = get_activator(environment, shell.clone()).into_diagnostic()?;

    let result = activator.deactivation().into_diagnostic()?;

    let script = result.script.contents().into_diagnostic()?;

    Ok(script.to_string())
}
wolfv

wolfv commented on Apr 23, 2025

@wolfv
Member

Hey @mrswastik-robot - you are correct. There is some code missing to make it easy to deactivate environments that we need to add to rattler. However, deactivation in general is already implemented (e.g. finding all the deactivation scripts and removing env vars).

Would you be able to write the deactivation() function in rattler?

mrswastik-robot

mrswastik-robot commented on Apr 23, 2025

@mrswastik-robot
Contributor

Hey @mrswastik-robot - you are correct. There is some code missing to make it easy to deactivate environments that we need to add to rattler. However, deactivation in general is already implemented (e.g. finding all the deactivation scripts and removing env vars).

Would you be able to write the deactivation() function in rattler?

sure @wolfv, I will give this a try and raise a PR in the rattler repo and link to this issue

mrswastik-robot

mrswastik-robot commented on Apr 23, 2025

@mrswastik-robot
Contributor

Hi @wolfv, so I have created the PRs, after making changes in the rattler_shell crate, when I tried to use the local fork of the rattler_shell instead of the installed crate in the pixi project by providing absolute path in the Cargo.toml , I was unable to compile and run tests, mainly due to some dependency version mismatches with the rattler_conda_types crate. So, idk if the solution in the PRs will work for sure, would love to hear from your side and happy to implement further requested changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @wolfv@Hofer-Julian@mrswastik-robot

      Issue actions

        Allow to deactivate environments activated from `pixi shell-hook` · Issue #3589 · prefix-dev/pixi