Open mcg1969 opened 4 years ago
Would something like this fulfill this need? Multiple commands could be tagged as run_after_prepare
and they would execute in the order shown in the YAML file when running anaconda-project prepare
.
Or do you think a more specialized specification of post-prepare commands be more inline with what you want?
name: prepare-with-script
packages:
- python=3.8
env_specs:
default: {}
commands:
my-command:
unix: <some action here>
win: <some action here>
env_spec: default
run_after_prepare: True
Seems like with the proposal above, if someone does "anaconda-project run", my-command would be executed twice, once after prepare and once since it's the default command. But I guess you'd interpret it as "make sure it's run at least once"?
Indeed, the command should only be run once on the cold use of anaconda-project run
.
Does someone have an example of a post-prepare script that can motivate this?
I do not, but I guess the semantics would have to be that if run_after_prepare==True
, that command cannot be the default command.
@AlbertDeFusco An example of a post-prepare script is to install a python kernel for use with Jupyter notebooks. Something like:
python -m ipykernel install --user --name "my-env" --display-name "Python 3 (my-env)"
In particular, I am trying to do this on CoCalc which runs its own customized notebook server that needs kernels to be properly installed.
Interesting. So for CoCalc you need to make sure that the kernel created using anaconda-project arrives in the ~/.local/share/jupyter
directory rather than the project environment directory.
Yes: the "notebook" is not run with the jupyter
from the project environment, but from somwhere else, and so does not know about the project envifornment directory unless one properly installs the kernel.
Thank you for your input, @mforbes ! In fact, we encounter this scenario often: the conda environment used to run Jupyter Notebook or JupyterLab is different than the environment running the kernel. The nb_conda_kernels
package is useful for such situations, and I wonder whether or not CoCalc might consider using something like that, or similar.
Nevertheless I agree that a post-prepare script would handle this scenario well.
It would be good if there is a way to execute a script of some sort upon environment preparation.