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

fish shell and activation scripts #7993

Open
michaelaye opened this issue Nov 27, 2018 · 9 comments
Open

fish shell and activation scripts #7993

michaelaye opened this issue Nov 27, 2018 · 9 comments
Labels
backlog issue has been triaged but has not been earmarked for any upcoming release cli::fish pertains to the CLI in fish plugins::activate pertains to conda-activate or conda-deactivate severity::3 major; broken functionality with a workaround source::community catch-all for issues filed by community members stale::recovered [bot] recovered after being marked as stale type::bug describes erroneous operation, use severity::* to classify the type

Comments

@michaelaye
Copy link

While the fish shell is supported for standard conda operations, I'm wondering how should one go about activation scripts in $CONDA_PREFIX/etc/conda/activate.d.
They are usually given in /bin/sh format like:

#!/bin/sh
export ISISROOT=$CONDA_PREFIX
export ISIS3DATA=$CONDA_PREFIX/data
export ISIS3TESTDATA=$CONDA_PREFIX/testData
#!/bin/sh
export ISISROOT=$CONDA_PREFIX
export ISIS3DATA=$CONDA_PREFIX/data
export ISIS3TESTDATA=$CONDA_PREFIX/testData
#!/bin/sh
export ISISROOT=$CONDA_PREFIX
export ISIS3DATA=$CONDA_PREFIX/data
export ISIS3TESTDATA=$CONDA_PREFIX/testData

which isn't supported by fish, at least my environment variables are not changed by having this activation script in my conda env.

Several things to check:

  • Is the fish implementation of conda at all looking for activation scripts at $CONDA_PREFIX/etc/conda/activate.d?
  • If yes, would it execute .fish files in there?
  • If not, what should we do now:
    • Write a general env var wrapper that can read sh scripts for setting fish envs?
    • Ask environment creators to provide .fish scripts?

I'm just really looking for guide lines how to advance proper fish use with conda, not asking the anaconda team for doing any of this. If I can provide a PR on the conda-fish script, I will of course consider that, once I know how this should be addressed.

@michaelaye
Copy link
Author

Maybe this could be a way? https://github.com/oh-my-fish/plugin-foreign-env

@michaelaye
Copy link
Author

michaelaye commented Nov 27, 2018

I confirmed that an environment variable set in a .fish file in $CONDA_PREFIX/etc/conda/activate.d is NOT set after activating this environment, so I guess there is currently no standard way of setting fish environment variables using this mechanism?

@michaelaye
Copy link
Author

michaelaye commented Nov 27, 2018

Considering that PROJ4 seems to use this mechanism to set some library paths (there is a proj4-activate.sh script in this folder), I guess this means that PROJ4 is not working using conda-fish?

@zhubonan
Copy link

I confirmed that an environment variable set in a .fish file in $CONDA_PREFIX/etc/conda/activate.d is NOT set after activating this environment, so I guess there is currently no standard way of setting fish environment variables using this mechanism?

I find a workaround - it seems that *.fish files are executed but not properly "sourced". If you add a -g flag to the set statement for setting the environmental variable then it will work. This is different from directly typing source activation_script.fish in the terminal, where the -g flag is unnecessary.

PS: I am on conda 4.5.11

@Phirefly9
Copy link

Phirefly9 commented Jan 31, 2019

as @zhubonan said, here is an example of what it should look like in the build.sh script:

In this example we are taking the openjdk package and fixing it to provide the same variables as the bash activation scripts. The deactivate is not fully robust but this will make the picture for you

cat <<EOF >>$PREFIX/etc/conda/activate.d/openjdk_set_env.fish
set -gx JAVA_HOME_CONDA_BACKUP "$JAVA_HOME"
set -gx JAVA_HOME "$CONDA_PREFIX"
set -gx JAVA_LD_LIBRARY_PATH_BACKUP "$JAVA_LD_LIBRARY_PATH"
set -gx JAVA_LD_LIBRARY_PATH "$JAVA_HOME/lib/server"
EOF

cat <<EOF >>$PREFIX/etc/conda/deactivate.d/openjdk_set_env.fish
set -e JAVA_HOME_CONDA_BACKUP
set -e JAVA_HOME
set -e JAVA_LD_LIBRARY_PATH_BACKUP
set -e JAVA_LD_LIBRARY_PATH
EOF

once that is done simply deactivate and reactivate your environment for the variables to work correctly.

@github-actions
Copy link

Hi there, thank you for your contribution to Conda!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further activity occurs.

If you would like this issue to remain open please:

  1. Verify that you can still reproduce the issue in the latest version of Conda

  2. Comment that the issue is still reproducible and include:

  • What version of Conda you reproduced the issue on
  • What OS and version you reproduced the issue on
  • What steps you followed to reproduce the issue
  1. It would also be helpful to have the output of the following commands available:
  • conda info
  • conda config --show-sources
  • conda list --show-channel-urls

NOTE: If this issue was closed prematurely, please leave a comment and we will gladly reopen the issue.

In case this issue was originally about a project that is covered by the Anaconda issue tracker (e.g. Anaconda, Miniconda, packages built by Anaconda, Inc. like Anaconda Navigator etc), please reopen the issue there again.

Thanks!

@github-actions github-actions bot added the stale [bot] marked as stale due to inactivity label Feb 23, 2022
@github-actions github-actions bot added the stale::closed [bot] closed after being marked as stale label May 14, 2022
@jakirkham
Copy link
Member

Would it be possible to reopen this?

@kenodegard
Copy link
Contributor

@jakirkham sure, it'd probably be good to also focus on a more agnostic solution #6820

@kenodegard kenodegard reopened this Jun 22, 2022
@kenodegard kenodegard added cli::fish pertains to the CLI in fish stale::recovered [bot] recovered after being marked as stale type::bug describes erroneous operation, use severity::* to classify the type source::community catch-all for issues filed by community members plugins::activate pertains to conda-activate or conda-deactivate severity::3 major; broken functionality with a workaround backlog issue has been triaged but has not been earmarked for any upcoming release and removed stale [bot] marked as stale due to inactivity stale::closed [bot] closed after being marked as stale labels Jun 22, 2022
@jurplel
Copy link

jurplel commented May 19, 2023

I successfully made a workaround to run bash activation scripts. I used a separate bash script and fish script, utilizing the bass utility. Posting in case anyone else finds it helpful.

run_activation_scripts.sh:

#!/bin/bash

FILES=$CONDA_PREFIX/etc/conda/activate.d/*.sh;
for f in $FILES; 
do 
	source $f;
	_tc_activation "activate";
	echo "Activated $f"; 
done

activate.fish:

#!/usr/bin/env fish

conda activate DEV
bass source ./run_activation_scripts.sh

To set up the environment (in this case hardcoded to DEV), run source activate.fish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog issue has been triaged but has not been earmarked for any upcoming release cli::fish pertains to the CLI in fish plugins::activate pertains to conda-activate or conda-deactivate severity::3 major; broken functionality with a workaround source::community catch-all for issues filed by community members stale::recovered [bot] recovered after being marked as stale type::bug describes erroneous operation, use severity::* to classify the type
Projects
Status: No status
Development

No branches or pull requests

6 participants