|
| 1 | + |
| 2 | +success_message="Script was successful" |
| 3 | + |
| 4 | +echo "Check the return value of this script and/or whether you see \"$success_message\" when it finishes" |
| 5 | + |
| 6 | +if [[ -n $( ls -A ) ]]; then |
| 7 | + |
| 8 | + echo "Error: you need to source his script in an empty directory; returning..." >&2 |
| 9 | + return 1 |
| 10 | +fi |
| 11 | + |
| 12 | +if [[ -d $HOME/.local ]]; then |
| 13 | + |
| 14 | + echo "WARNING: the presence of a $HOME/.local directory may interfere with the execution of this script" >&2 |
| 15 | +fi |
| 16 | + |
| 17 | +. /cvmfs/dunedaq.opensciencegrid.org/spack/externals/ext-v2.2/spack-0.22.0/share/spack/setup-env.sh || return 2 |
| 18 | +spack load [email protected] || return 3 |
| 19 | + |
| 20 | +python -m venv freshenv || return 4 |
| 21 | +. ./freshenv/bin/activate || return 5 |
| 22 | + |
| 23 | +# Upgrade pip and install the poetry dependency-management package as |
| 24 | +# described in https://python-poetry.org/docs/ |
| 25 | + |
| 26 | +pip install --upgrade pip || return 6 |
| 27 | +pip install pipx || return 7 |
| 28 | +pipx install poetry || return 8 |
| 29 | + |
| 30 | +echo "MAY MODIFY \$PATH in $HOME/.bashrc" >&2 |
| 31 | +pipx ensurepath || return 9 |
| 32 | + |
| 33 | +# Assumption is this script is being sourced (not executed) and that |
| 34 | +# pyproject.toml exists in the same directory as the script |
| 35 | + |
| 36 | +scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 37 | + |
| 38 | +cp $scriptdir/pyproject.toml . || return 10 |
| 39 | + |
| 40 | +# Unclear if this is actually "shielding" you from the surrounding environment |
| 41 | +# Create a new subdirectory and cd into it before calling this? |
| 42 | + |
| 43 | +poetry shell || return 11 |
| 44 | +poetry install || return 12 |
| 45 | + |
| 46 | +pip freeze > ./pyvenv_requirements.txt |
| 47 | +test "$?" == "0" || return 12 |
| 48 | + |
| 49 | +echo "Versions frozen into ./pyvenv_requirements.txt" |
| 50 | +echo $success_message |
| 51 | + |
0 commit comments