Skip to content

Commit

Permalink
chore: micromamba in make
Browse files Browse the repository at this point in the history
  • Loading branch information
Gunther Klessinger committed Sep 4, 2023
1 parent 25c49c2 commit 0a6faa5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
28 changes: 16 additions & 12 deletions make
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Modifying Parameters, Adding Functionality:
'

VERSION_MAKE="2"
VERSION_MAKE="3" # micromamaba

me="${BASH_SOURCE[0]:-${(%):-%x}}" # bash and zsh/ksh compliant
builtin cd "$(dirname "$me")"
Expand All @@ -34,6 +34,7 @@ mkdocs_path="${mkdocs_path:-$PROJECT}"
mkdocs_port="${mkdocs_port:-8000}"
d_cover_html="${d_cover_html:-build/coverage/overall}"
fn_changelog="${fn_changelog:-docs/about/changelog.md.lp.py}"
PROJECT="${PROJECT:-$(basename "$here")}"
set +a

skip_func_after_hook="42"
Expand All @@ -47,6 +48,13 @@ helper_funcs () {
if [[ "$?" != "$skip_func_after_hook" ]]; then call "$@"; fi
hook post "$@"
}
function download {
type wget 2>/dev/null 1>/dev/null && {
wget -O "$2" "$1"
return $?
}
curl -L -o "$2" "$1"
}

function hook {
local fn="scripts/$2_$1.sh"
Expand Down Expand Up @@ -78,18 +86,19 @@ helper_funcs () {



function conda_root { echo "${conda_root:-$MAMBA_ROOT_PREFIX}"; }

function activate_venv {
# must be set in environ:
local conda_env="$(conda_root)/envs/${PROJECT}_py${pyver}"
test -e "$conda_env" || { nfo "No $conda_env"; return 1; }
test -z "$CONDA_SHLVL" && conda_src
test -z "$CONDA_SHLVL" && { micromamba activate || return 1; }
test "$CONDA_PREFIX" = "${conda_env:-x}" && return 0
while [ -n "$CONDA_PREFIX" ]; do conda deactivate; done
nfo 'Adding conda root env $PATH'
while [ -n "$CONDA_PREFIX" ]; do micromamba deactivate; done
nfo 'Adding micromamba root env $PATH'
export PATH="$(conda_root)/bin:$PATH"
nfo Activating "$conda_env"
conda activate "$conda_env"
micromamba activate "$conda_env"
}

function set_version {
Expand All @@ -100,13 +109,8 @@ helper_funcs () {
nfo "Say ./make release <version>"
return 1
}
function conda_root { echo "$HOME/${conda_root:-miniconda3}"; }

function conda_src {
source "$(conda_root)/etc/profile.d/conda.sh";
conda config --set always_yes yes # --set changeps1 no
conda config --add channels conda-forge
}
function ci-conda-root-env { ci-conda-base-env "$@"; } # backwards compat

function make {
test -z "$1" && {
Expand Down Expand Up @@ -179,7 +183,7 @@ function self-update {
run_self_update "$@"
}

function ci-conda-root-env { # creates the root conda env if not present yet
function ci-conda-base-env { # creates the root conda env if not present yet
source scripts/conda.sh && make_conda_root_env "$@"
}

Expand Down
37 changes: 19 additions & 18 deletions scripts/conda.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
root_tools="tree fd-find ripgrep poetry"

function make_conda_root_env { # creates the root conda env if not present yet
# main conda bin is in path
local p="$(conda_root)"
test -e "$p" && {
nfo "Already present: $p"
return 0
}
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
chmod +x miniconda.sh
./miniconda.sh -b -p "$p" 1>/dev/null 2>/dev/null && echo 'conda root installed to '$p''
conda_src
eval conda install -y -q $root_tools ${conda_root_tools:-}
ls -a "$p"
type micromamba && return
echo -e "\x1b[1mInstalling micromamba.\x1b[0m"
echo "Please confirm all question unless you know what you are doing."
"${SHELL}" <(curl -L micro.mamba.pm/install.sh)
call . "$HOME/.$(basename $SHELL)rc"
call micromamba activate
call eval micromamba install --yes $root_tools ${conda_root_tools:-}
call micromamba info
nfo "Next, run \x1b[1mmake ci-conda-py-env\x1b[0m"
}

function make_conda_py_env { # creates the venv for the project and poetry installs
# main conda bin is in path
local n="${PROJECT}_py${pyver}"
local p="$(conda_root)/envs/$n"
conda_src
test -e "$p" || eval conda create -q -n "${n}" python="${pyver}" ${conda_project_tools:-} $*
activate_venv || return 1
poetry install
conda info
ls -a "$(conda_root)/envs/"
call micromamba activate
test -e "$p" || {
echo "Installing $p (with tools: $conda_project_tools)"
call eval micromamba create --yes -q -n "${n}" python="${pyver}" ${conda_project_tools:-} $*
}
call activate_venv || return 1
call poetry install
call ls -a "$(conda_root)/envs/"
call micromamba list
}

0 comments on commit 0a6faa5

Please sign in to comment.