slaclab / anarel-manage

Manage the conda based analysis release environments that include psana at LCLS.
Other
3 stars 3 forks source link

source conda_setup from within script - error with command line arguments #9

Closed davidslac closed 7 years ago

davidslac commented 7 years ago

@koglin ran into an issue using conda_setup from a script.

Users may write scripts like

#!/bin/bash

source conda_setup
# process command line arguments

However, per http://superuser.com/questions/1029431/how-to-prevent-source-in-a-bash-script-from-passing-the-scripts-arguments, conda_setup will see the scripts command line argument, and currently error out when it processes them.

Looks like the best practice is for users to do

source conda_setup ""

to not pass the scripts command line arguments.

I could also look into

http://stackoverflow.com/questions/12818146/python-argparse-ignore-unrecognised-arguments

to not complain about unrecognized arguments, but this doesn't seem as robust. Some of the user script arguments may coincidentally be the same as those of conda_setup, and outside the script, we'd rather throw an error.

davidslac commented 7 years ago

I updated documentation at https://confluence.slac.stanford.edu/display/PSDMInternal/User+Documentation will close.

davidslac commented 7 years ago

Jason reports there is still trouble calling bsub, bsub/script + conda_setup leads to messed up envrionment. Workaround, don't use conda_setup, get into the ana-current environment directly. You can read which environment is ana-current, but you need to set which OS, i.e, rhel7, rhel6, rhel5 yourself (batch jobs should only be run on rhel7), so you could start your script like:

#!/usr/bin/bash

_CONDA_DIR=/reg/g/psdm/sw/conda
PATH=$_CONDA_DIR/inst/miniconda2-prod-rhel7/bin:$PATH
_ANA_CURRENT=`cat $_CONDA_DIR/ana-current/ana-current`
unset PYTHONPATH
unset LD_LIBRARY_PATH
source activate $_ANA_CURRENT
unset _ANA_CURRENT
unset _CONDA_DIR

This mechanism for reading ana-current from the path /reg/g/psdm/sw/conda/ana-current/ana-current is subject to change, we really should have an API for it so we can put the information elsewhere