summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2019-03-15 14:29:45 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2019-03-15 14:29:45 -0400
commit474686135abd4ee49dd943ae4f7a05c6b84672dd (patch)
tree366f3a7d128c5859166fc8b298362238d5bcfe7d
downloaddo_not_let_the_wrapper_fool_you-474686135abd4ee49dd943ae4f7a05c6b84672dd.tar.gz
Initial commit
-rw-r--r--resources/edu/stsci/include/compat.sh38
-rw-r--r--resources/edu/stsci/include/conda.sh5
-rw-r--r--resources/edu/stsci/init.sh24
-rw-r--r--resources/edu/stsci/lib/conda.sh178
-rw-r--r--resources/edu/stsci/lib/workspace.sh26
-rw-r--r--src/edu/stsci/.keep0
-rw-r--r--vars/.keep0
7 files changed, 271 insertions, 0 deletions
diff --git a/resources/edu/stsci/include/compat.sh b/resources/edu/stsci/include/compat.sh
new file mode 100644
index 0000000..a8b46a0
--- /dev/null
+++ b/resources/edu/stsci/include/compat.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+[[ -n ${_shutil_compat_header} ]] && return || readonly _shutil_compat_header=1
+
+declare -r _shutil_compat_sed_str='s|%s|%s|%s'
+shutil_compat_get_arch() {
+ : # pass
+}
+
+shutil_compat_get_platform() {
+ : # pass
+}
+
+shutil_compat_replace() {
+ local mod tmp
+ mod=''
+ args=()
+
+ while [[ $# != 0 ]]
+ do
+ key="${1}"
+ case "${key}" in
+ --global|-g)
+ mod='g'
+ shift
+ ;;
+ *)
+ args+=("${1}")
+ shift
+ esac
+ done
+
+ [[ ${#args[@]} != 3 ]] && echo "shutil_compat_replace [-g] {pattern1} {pattern2} {file}" && exit 1
+
+ tmp=$(mktemp)
+ sed -e $(printf ${_shutil_compat_sed_str} ${args[1]} ${args[2]} ${mod}) < ${args[0]} > ${tmp}
+ mv ${tmp} ${args[0]}
+}
+
diff --git a/resources/edu/stsci/include/conda.sh b/resources/edu/stsci/include/conda.sh
new file mode 100644
index 0000000..9e55db1
--- /dev/null
+++ b/resources/edu/stsci/include/conda.sh
@@ -0,0 +1,5 @@
+[[ -n ${_shutil_conda_header} ]] && return || readonly _shutil_conda_header=1
+
+declare -r _URL_CONTINUUMIO=https://repo.continuum.io
+declare -r _URL_CONTINUUMIO_MINICONDA=${_URL_CONTINUUMIO}/miniconda
+declare -r _URL_CONTINUUMIO_ANACONDA=${_URL_CONTINUUMIO}/archive
diff --git a/resources/edu/stsci/init.sh b/resources/edu/stsci/init.sh
new file mode 100644
index 0000000..ac95dc0
--- /dev/null
+++ b/resources/edu/stsci/init.sh
@@ -0,0 +1,24 @@
+# source-only
+if [[ -z ${_shutil_init_protect} ]] || [[ ${_shutil_init_protect} == 0 ]]; then
+
+export EDU_STSCI_SHUTIL_ROOT=$(python -c "import os.path; print(os.path.abspath(os.path.dirname('${BASH_SOURCE[0]}')))")
+export EDU_STSCI_SHUTIL_INCLUDE="${EDU_STSCI_SHUTIL_ROOT}/include"
+export EDU_STSCI_SHUTIL_LIB="${EDU_STSCI_SHUTIL_ROOT}/lib"
+
+# Remove this
+export WORKSPACE=$EDU_STSCI_SHUTIL_ROOT
+
+shutil_init() {
+ local lib
+ for lib in "${EDU_STSCI_SHUTIL_LIB}"/*.sh
+ do
+ echo "Loading shutil library: $(basename ${lib})"
+ source "${lib}"
+ done
+}
+
+shutil_init
+export _shutil_init_protect=1
+
+fi # _shutil_init_protect
+
diff --git a/resources/edu/stsci/lib/conda.sh b/resources/edu/stsci/lib/conda.sh
new file mode 100644
index 0000000..e304a57
--- /dev/null
+++ b/resources/edu/stsci/lib/conda.sh
@@ -0,0 +1,178 @@
+#!/bin/bash
+source ${EDU_STSCI_SHUTIL_INCLUDE}/conda.sh
+
+
+shutil_conda_die() {
+ echo "shutil_conda_die: ${1-no_error_specified_by_caller}"
+ exit 1
+}
+
+shutil_conda_exists() {
+ retval=0
+ if ! type -p conda ; then
+ retval=1
+ elif [[ $(type -t conda) != function ]]; then
+ retval=2
+ fi
+ echo ${retval}
+}
+
+shutil_conda_infect() {
+ if [[ $(shutil_conda_exists) != 0 ]]; then
+ shutil_conda_die "cannot dump environment key pairs"
+ fi
+ printenv | sort
+}
+
+shutil_conda_install() {
+ local version prefix
+ #TODO
+
+
+}
+
+shutil_conda_withenv() {
+ if [[ $(shutil_conda_exists) != 0 ]]; then
+ shutil_conda_die "unable to execute: conda must be on \$PATH or activated via 'conda' function"
+ fi
+ local commands environ exe key
+ environ=base
+ commands=()
+
+ while [[ $# != 0 ]]
+ do
+ key="${1}"
+ case ${key} in
+ -n|--name)
+ environ="${2}"
+ shift 2
+ ;;
+ *)
+ commands+=("${1}")
+ shift
+ ;;
+ esac
+ done
+
+ exe='source'
+ if [[ $(type -t conda) == function ]]; then
+ exe='conda'
+ fi
+
+ ${exe} activate "${environ}"
+ "${commands[@]}"
+}
+
+shutil_conda_root() {
+ if [[ $(shutil_conda_exists) != 0 ]]; then
+ shutil_conda_die "cannot get root directory"
+ fi
+ local version
+ version=$(shutil_conda_withenv conda --version)
+
+ # Return version triplet without "conda"
+ echo "${version#conda }"
+}
+
+shutil_conda_version() {
+ if [[ $(shutil_conda_exists) != 0 ]]; then
+ shutil_conda_die "cannot get version"
+ fi
+ local version
+ version=$(shutil_conda_withenv conda --version)
+
+ # Return version triplet without "conda"
+ echo "${version#conda }"
+}
+
+shutil_conda_init_from_prefix() {
+ local prefix profile target
+ prefix="${1}"
+ if [[ ! -d ${prefix}/bin ]]; then
+ shutil_conda_die "expected conda root , but got '${prefix}'"
+ fi
+
+ profile="${prefix}"/etc/profile.d/conda.sh
+
+ if [[ -f ${profile} ]]; then
+ source "${profile}"
+ conda activate
+ else
+ export PATH="${prefix}/bin:${PATH}"
+ source activate base
+ fi
+}
+
+shutil_conda_env_dump() {
+ if [[ $(shutil_conda_exists) != 0 ]]; then
+ shutil_conda_die "unable to execute: conda must be on \$PATH or activated via 'conda' function"
+ fi
+ local commands environ key output use_yaml use_explicit
+ environ=base
+ output=environment
+ commands=()
+
+ while [[ $# != 0 ]]
+ do
+ key="${1}"
+ case ${key} in
+ -n|--name)
+ environ="${2}"
+ shift 2
+ ;;
+ -y|--yaml)
+ use_yaml=1
+ shift
+ ;;
+ -e|--explicit)
+ use_explicit=1
+ shift
+ ;;
+ -o|--output)
+ output="${2}"
+ shift 2
+ ;;
+ *)
+ commands+=("${1}")
+ shift
+ ;;
+ esac
+ done
+
+ local retval
+ if [[ -n ${use_yaml} ]]; then
+ shutil_conda_withenv -n "${environ}" conda env export --name "${environ}" --file "${output}".yml "${commands[@]}"
+ retval=$?
+ if [[ $? == 0 ]]; then
+ sed -e '/^name:/d' -e '/^prefix:/d' <<< $(< ${output}.yml) > "${output}".yml
+ fi
+ elif [[ -n ${use_explicit} ]]; then
+ shutil_conda_withenv -n "${environ}" conda list --name "${environ}" --explicit > "${output}".txt "${commands[@]}"
+ retval=$?
+ else
+ shutil_conda_die "shutil_conda_env_dump: unknown operation: ${commands[@]}"
+ fi
+
+ if [[ ${retval} != 0 ]]; then
+ shutil_conda_die "shutil_conda_env_dump: operation failed: ${@}"
+ fi
+}
+
+set -x
+shutil_conda_init_from_prefix ~/Downloads/miniconda3
+shutil_conda_env_dump --yaml
+shutil_conda_env_dump --explicit
+cat environment.*
+#export PATH=~/Downloads/miniconda3/bin:$PATH
+#source ~/Downloads/miniconda3/etc/profile.d/conda.sh
+#conda activate
+
+#if [[ $(shutil_conda_exists) != 0 ]]; then
+# echo "nope"
+#else
+# echo "exists"
+#fi
+
+#shutil_conda_withenv conda --help
+#shutil_conda_version
+#shutil_conda_infect
diff --git a/resources/edu/stsci/lib/workspace.sh b/resources/edu/stsci/lib/workspace.sh
new file mode 100644
index 0000000..63f87a2
--- /dev/null
+++ b/resources/edu/stsci/lib/workspace.sh
@@ -0,0 +1,26 @@
+shutil_ws_path() {
+ echo "${WORKSPACE}"
+}
+
+shutil_ws_search() {
+ local pattern
+ pattern="${1-*}"
+
+ for f in $(find $(shutil_ws_path) -type f -name "${pattern}" | xargs)
+ do
+ echo "${f}"
+ done
+}
+
+shutil_ws_file_exists() {
+ local filename
+ filename="${1}"
+ if [[ -z ${filename} ]]; then
+ echo "exists_in_ws() missing argument: filename" >&2
+ echo 0
+ return
+ fi
+
+ ([[ -n $(shutil_ws_search "${filename}") ]] && echo 1) || echo 0
+}
+
diff --git a/src/edu/stsci/.keep b/src/edu/stsci/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/edu/stsci/.keep
diff --git a/vars/.keep b/vars/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/vars/.keep