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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃憣 IMPROVE: Generalize environment for using different shells #18

Open
GeigerJ2 opened this issue Feb 19, 2024 · 1 comment
Open

Comments

@GeigerJ2
Copy link
Collaborator

I recently stumbled upon an issue while trying out a few different setups. Actually don't fully recall now how I got
there, but what was happening was that after creating new projects with aiida-project create and activating them with
cda, my AIIDA_PATH environment variable was still pointing to the global $HOME/.aiida, and, accordingly, new
project-specific profiles were being added to the global config file $HOME/.aiida/config.json.

After some digging around, I realized that the issue was an incompatibility between my main shell (fish) and the fact
that I was occasionally launching and using bash. To be precise (and as I have recently, painfully learned),
environment variables of the parent shell cannot be set from a Python subprocess. Thus, in aiida-project, this is
instead handled via the cda command, which, apart from changing the directory, also sources the Python activation
file, activate.fish for fish and activate for bash when using venv. Importantly, aiida-project adds the
command to set AIIDA_PATH to this activation file, e.g. for fish in $HOME/.aiida_venvs/<project>/bin/activate.fish:

set -gx AIIDA_PATH $HOME/aiida_projects/<project>
eval (env _VERDI_COMPLETE=fish_source verdi)

with cda defined as follows:

# Defined in $HOME/.config/fish/conf.d/aiida_project.fish @ line 48
function cda
    source "$aiida_venv_dir/$argv[1]/bin/activate.fish"
    cd "$aiida_project_dir/$argv[1]"
end

Long story short, in my case, cda was pointing to activate not activate.fish, while the command to set
AIIDA_PATH was in activate.

Now, this might be somewhat of a niche case, however, I would propose that we move the location of setting AIIDA_PATH
and the eval statement for tab completion to a general, hidden activation file inside the directory of the project.
This change should also be necessary if we want to add conda support, as here the Python environment is not activated
by sourcing an activate file.

Lastly, as it stands right now, the shell is attached to the global configuration of aiida-project, so we could
instead attach it to each project, or, even better, implement a check on the currently running shell, so that seamless
use of aiida-project is guaranteed even when running with different terminal instances and shells (though, not
entirely sure how one would go about implementing that).

@GeigerJ2
Copy link
Collaborator Author

In addition, for me config.json is currently not written in the .aiida folder under $HOME/aiida_projects/<project>. Very strange...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant