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

Environment Parameters do not activate/deactivate in Powershell #2644

Closed
phreed opened this issue Jun 29, 2023 · 6 comments
Closed

Environment Parameters do not activate/deactivate in Powershell #2644

phreed opened this issue Jun 29, 2023 · 6 comments

Comments

@phreed
Copy link

phreed commented Jun 29, 2023

I look in

std::string CmdExeActivator::shell_extension()
{
return ".bat";
}
std::string CmdExeActivator::shell()
{
return "cmd.exe";
}
and I see bat and sh but no ps1.

In conda the environment variables activate/deactivate in a different manner.
Setting environment variables in cmd.exe and bash are described here.
https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#saving-environment-variables

The installation instructions for minimamba has instructions for powershell, https://mamba.readthedocs.io/en/latest/installation.html#windows
This is inconsistent.

Cause env_var.ps1 files to be supported in activate/deactivate.

@AntoinePrv
Copy link
Member

Hi @phreed, I am not particularly knowledgeable about Windows, would you mind giving an example of that you observe vs what you expect?

You mention you have an issue in Powershell, but point to code for cmd.exe activation. There is a different PowerShellActivator. Which one are you working with?

This is inconsistent.

Could you detail what behavior is inconsistent with what other behavior?

Cause env_var.ps1 files to be supported in activate/deactivate.

Do you mean you write a env_var.ps1 in %CONDA_PREFIX%\etc\conda\activate.d\ that is not red when activating?

@phreed
Copy link
Author

phreed commented Jul 5, 2023

Hi @phreed, I am not particularly knowledgeable about Windows, would you mind giving an example of that you observe vs what you expect?

You mention you have an issue in Powershell, but point to code for cmd.exe activation. There is a different PowerShellActivator. Which one are you working with?

I see that I was wrong (not reading the code correctly).
Previously, I found the PosixActivator and the CmdExeActivator but not a PowershellActivator. I thought it was missing, but now there it is!

This is inconsistent.

Could you detail what behavior is inconsistent with what other behavior?

The inconsistency is in the documentation (not the behavior).
The installation instructions explain how to install minimamba via Powershell, but the environment variable instructions omit Powershell.

Cause env_var.ps1 files to be supported in activate/deactivate.

Do you mean you write a env_var.ps1 in %CONDA_PREFIX%\etc\conda\activate.d\ that is not read when activating?

Yes, that is what I meant.
That turns out to be wrong.
The script is processed but the environment variables to not propagate into the conda environment.

@phreed
Copy link
Author

phreed commented Jul 5, 2023

Now that I have looked at the code I find that the following works.

  1. Create a directory ~/micromamba/envs/<env-name>/etc/conda/env_vars.d/.
  2. Put a json file in that directory. ~/micromamba/envs/<env-name>/etc/conda/env_vars.d/<foo>.json.
  3. Define some variables in that file.
{
  "FOO": "bar"
}

This works on Windows (and I presume the others). However, I do not see this in the documentation.

@phreed
Copy link
Author

phreed commented Jul 5, 2023

Do you mean you write a env_var.ps1 in %CONDA_PREFIX%\etc\conda\activate.d\ that is not read when activating?

I did a test, putting the following in ```$CONDA_PREFIX/etc/conda/activate.d/env-var.ps1.

$Env:PROJECT_DIR = "C:\Users\me\Desktop\cts-3.x"

New-Item "C:\Users\me\foo.txt"
Set-Content "C:\Users\me\foo.txt" 'the env_var.ps1 ran'

When I activate the corresponding conda environment the foo.txt file is created but that environment does not have the $Env:PROJECT_DIR .
So, the activation scripts, apparently, should not be used for setting environment parameters (at least in powershell).

@phreed phreed changed the title Environment Parameters do not activate/deactivate in Poweshell Environment Parameters do not activate/deactivate in Powershell Jul 5, 2023
@AntoinePrv
Copy link
Member

When I activate the corresponding conda environment the foo.txt file is created but that environment does not have the $Env:PROJECT_DIR .
So, the activation scripts, apparently, should not be used for setting environment parameters (at least in powershell).

I don't know enough about powershell to tell whether if this is a bug or not possible (script running in a subshell).

This works on Windows (and I presume the others). However, I do not see this in the documentation.

This should be documented, however, right now we do not have detailed doc on all features and been relying a lot on Conda.
However I don't see it documented there...

@jjerphan
Copy link
Member

jjerphan commented Dec 9, 2024

Duplicates #1717 which has been fixed in 2.0.

@jjerphan jjerphan closed this as not planned Won't fix, can't repro, duplicate, stale Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants