Verified Commit 3ca9a047 authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Do not use pre-defined tasks to allow for working on read-only filesystems

parent 25ab4f1e
Loading
Loading
Loading
Loading

src/mantidworkbench

100644 → 100755
+5 −8
Original line number Diff line number Diff line
@@ -4,28 +4,25 @@
. "$(dirname "$(realpath "$0")")/nsd-app-wrap.sh" ||
	. /bin/nsd-app-wrap.sh

# default conda environment if it was not specified
PIXI_ENV="mantid"

# look for a supplied argument
for var in "$@"; do
	case "$var" in
	--env=*)
		PIXI_ENV=$(echo "${var}" | awk -F"=" '{print $2}')
		PIXI_TASK="start_mantid"
		shift 1 # remove this argument
		;;
	--env)
		PIXI_ENV="$2" # look ahead by one
		PIXI_TASK="start_mantid"
                shift 2        # remove the flag and value
		;;
	esac
done
# default conda environment if it was not specified
if [ -z "${PIXI_ENV}" ]; then
	PIXI_ENV="mantid"
	PIXI_TASK="start_gui"
fi
PIXI_TASK="mantidworkbench"

# put together arguments - conda_env, application, argv
args=("${PIXI_ENV}" "${PIXI_TASK}" "$@")
# launch the tool
pixi_launch "${args[@]}"
activate_pixi_and_launch "${args[@]}"
+45 −102
Original line number Diff line number Diff line
#!/bin/bash

CONDA_PREFIX_CENTRAL="/opt/anaconda"
CONDA_ACTIVATE_SCRIPT="${CONDA_PREFIX_CENTRAL}/bin/activate"
# several places have conda installed in /usr/local and link it over
CONDA_PREFIX_ALT="/usr/local/anaconda"
# overwrite this value with environment injection e.g.
# PIXI_PREFIX=/path/to/pixitoml/parent/dir nsd-app-wrap.sh
PIXI_PREFIX="${PIXI_PREFIX:=/usr/local/pixi}"

########## Utility functions
_remove_font_cache() {
@@ -14,114 +13,58 @@ _remove_font_cache() {
  fi
}

########## Connect to central conda command
_activate_conda_cmd() {
  if [ -f "${CONDA_ACTIVATE_SCRIPT}" ]; then
    # shellcheck disable=SC1090,SC1091,SC2039
    . "${CONDA_ACTIVATE_SCRIPT}" ""  # don't let command line arguments in
  else
    echo "\"${CONDA_ACTIVATE_SCRIPT}\" not found"
    exit 255
  fi
}

_activate_central_anaconda() {
  if [ "$(command -v conda)" ]; then
    if [ "${CONDA_ACTIVATE_SCRIPT}" != "$(which conda)" ]; then
      echo "Switching to central anaconda install in \"${CONDA_PREFIX_CENTRAL}\""
      _activate_conda_cmd
    fi
  else
    echo "Activating central anaconda install in \"${CONDA_PREFIX_CENTRAL}\""
    _activate_conda_cmd
  fi

  # make sure that conda is found in the correct place
  if [ "${CONDA_PREFIX}" != "${CONDA_PREFIX_CENTRAL}" ] && [ "${CONDA_PREFIX}" != "${CONDA_PREFIX_ALT}" ]; then
    echo "Found conda at \"${CONDA_PREFIX}\" rather than \"${CONDA_PREFIX_CENTRAL}\""
    exit 255
  fi
}
########## Generate the path to the manifest directory
# if the
_get_pixi_manifest_path() {
  # pixi environment
  PIXI_ENV="${1}"

# this should be included in scripts after activate_conda_environment
# but before the actual command to be activated using a trap
#
# trap deactivate_conda_environment EXIT
#
# this will preserve the exit code from the main command
_deactivate_conda_environment() {
    echo "Deactivate conda environment"
    conda deactivate
  echo "${PIXI_PREFIX%/}/${PIXI_ENV}"
}

########## Activate the environment in the central conda install
activate_conda_environment () {
  CONDA_EXP_ENV="${1}"

  # verify that central conda install is the one being used
  _activate_central_anaconda

  # activate the environment
  conda activate "${CONDA_EXP_ENV}"
########## Activate the environment in the central pixi install
# this assumes that "pixi" is in the user's path
activate_pixi_environment () {
  # pixi environment
  PIXI_ENV="${1}"

  # verify that the correct one was activated
  if [ ! "$CONDA_DEFAULT_ENV" == "$CONDA_EXP_ENV" ]; then
    echo "Failed to activate \"${CONDA_EXP_ENV}\" conda environment"
    exit 255
  else
    echo "Activated \"$CONDA_EXP_ENV\" conda environment"
  _path_to_manifest=$(_get_pixi_manifest_path "${PIXI_ENV}")
  # check the directory exists
  if [ ! -d "${_path_to_manifest}" ]; then
    echo "Manfest path does not exist: ${_path_to_manifest}"
    exit 1 # error ends the script
  fi

  # unload the environment on exit
  trap _deactivate_conda_environment EXIT
  # activate the environment
  pixi shell --frozen --manifest-path "${_path_to_manifest}"
}

########## Activate the environment and start the application
# The arguments are (conda_env, command, argv) and can be put
# The arguments are (pixi_env, command, argv) and can be put
# together and supplied like
#
# args=("mantid-dev" "mantidworkbench" "$@")
# activate_and_launch "${args[@]}"
activate_and_launch() {
    # first argument is conda environment
    CONDA_EXP_ENV="${1}"
# activate_pixi_and_launch "${args[@]}"
#
# This assumes that "pixi" is in the user's path
activate_pixi_and_launch() {
  # first argument is pixi environment
  PIXI_ENV="${1}"
  shift
  # second argument is startup command
  COMMAND="${1}"
  shift
  # the rest is passed to the command being started

    _remove_font_cache
    activate_conda_environment "${CONDA_EXP_ENV}"

    echo "Execute: ${COMMAND} $*"
    "${COMMAND}" "$@"
}

pixi_launch() {
        PIXI_PREFIX="/usr/local/pixi"
        PIXI_ENV="${1}"
        shift
      	# This grabs everything past the first argument
        PIXI_TASK="${*}"

        path_to_manifest="${PIXI_PREFIX%/}/${PIXI_ENV}"

        # Verify path_to_manifest directory exists
      	if [ ! -d "${path_to_manifest}" ]; then
	          echo "No pixi environment found at ${path_to_manifest}"
	          exit 1
  _path_to_manifest=$(_get_pixi_manifest_path "${PIXI_ENV}")
  # check the directory exists
  if [ ! -d "${_path_to_manifest}" ]; then
    echo "Manfest path does not exist: ${_path_to_manifest}"
    exit 1 # error ends the script
  fi

        #echo "P: $PIXI_PREFIX, E: $PIXI_ENV, T: $PIXI_TASK - ptm: $path_to_manifest."

  _remove_font_cache

        pixi_run="pixi run --frozen --manifest-path $path_to_manifest $PIXI_TASK"

        #echo "pixi command: $pixi_run"

        $pixi_run

  # activate the environment and run the command
  echo "run \"${COMMAND} $*\" in the \"${PIXI_ENV}\" pixi environment"
  pixi run --frozen --manifest-path "${_path_to_manifest}" "${COMMAND}" "$@"
}
+3 −4
Original line number Diff line number Diff line
@@ -33,8 +33,7 @@ fi
. "$(dirname "$(realpath "$0")")/nsd-app-wrap.sh" ||
    . /bin/nsd-app-wrap.sh

# launch pixi
# put together arguments - conda_env, application, argv
args=("${PIXI_ENVIRON}" "$STARTUP" "$@")
# launch the tool
pixi_launch "${args[@]}"
# launch pixi
activate_pixi_and_launch "${args[@]}"

src/paraview

100644 → 100755
+1 −1
Original line number Diff line number Diff line
@@ -11,4 +11,4 @@ PIXI_ENVIRON=paraview
args=("${PIXI_ENVIRON}" "paraview" "$@")

# start the application
pixi_launch "${args[@]}"
activate_pixi_and_launch "${args[@]}"