HenrikBengtsson / conda-stage

conda-stage: Stage a Conda Environment on Local Disk
https://github.com/HenrikBengtsson/conda-stage
ISC License
7 stars 0 forks source link

IDEA: conda-stage --install-auto-stage #16

Closed HenrikBengtsson closed 2 years ago

HenrikBengtsson commented 2 years ago

We could add conda-stage --install-auto-stage, which installs a "hook" script to the original conda environment, e.g.

$ cat ~/.conda/envs/myenv/etc/conda/activate.d/zzz.conda-stage.sh
if [[ ${CONDA_STAGE_ACTION} != "unstage" ]]; then
    command -v conda-stage > /dev/null || module load CBI conda-stage
    conda-stage --read-only
fi
HenrikBengtsson commented 2 years ago

Wow, it works;

$ conda activate myenv
INFO: Staging current conda environment (/home/hb/.conda/envs/myenv) to local disk ...
INFO: Extracting /home/hb/.conda/envs/myenv.tar.gz (397363978 bytes; 2022-04-14 14:51:40.967483116 -0700) to /tmp/hb/conda-stage-LZtb/myenv
INFO: Total extract time: 10 seconds
INFO: Unpacking
INFO: Total 'conda-unpack' time: 0 seconds
INFO: Activating staged conda environment: /tmp/hb/conda-stage-LZtb/myenv
HenrikBengtsson commented 2 years ago

After more tweaks, it's now also possible to unstage back to the original conda environment;

$ conda activate myenv
INFO: Staging current conda environment (/home/hb/.conda/envs/myenv) to local disk ...
INFO: Extracting /home/hb/.conda/envs/myenv.tar.gz (397363978 bytes; 2022-04-14 14:51:40.967483116 -0700) to /tmp/hb/conda-stage-Iwpc/myenv
INFO: Total extract time: 14 seconds
INFO: Unpacking
INFO: Total 'conda-unpack' time: 0 seconds
INFO: Make staged environment read-only
INFO: Activating staged conda environment: /tmp/hb/conda-stage-Iwpc/myenv
20220414-W15-4 (d104) 18:35:04 hb-x1:~/repositories/conda-stage

$ conda-stage --unstage
INFO: Unstaging and reverting to original conda environment  ...
INFO: Original conda environment: /home/hb/.conda/envs/myenv
INFO: Removing all staged files: /tmp/hb/conda-stage-Iwpc/myenv
INFO: Activating original conda environment: /home/hb/.conda/envs/myenv
INFO: Total unstage time: 1 seconds
HenrikBengtsson commented 2 years ago

Added;