Skip to content

Instantly share code, notes, and snippets.

@pbsds
Created November 2, 2020 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbsds/fe243e518717531b10b2782add519256 to your computer and use it in GitHub Desktop.
Save pbsds/fe243e518717531b10b2782add519256 to your computer and use it in GitHub Desktop.
A .remoteenv file to use with remote-cli when using poetry on a remote host you don't have sudo access to.
#!/usr/bin/env bash
MINICONDA_PY38_URL="https://repo.continuum.io/miniconda/Miniconda3-py38_4.8.2-Linux-x86_64.sh"
MINICONDA_PY38_HASH="879457af6a0bf5b34b48c12de31d4df0ee2f06a8e68768e5758c3293b2daf688"
# Assumes repo is put in a "remotes/NAME-HASH" folder
ENVIRON_NAME="py38_$(basename $(pwd))"
REMOTES_DIR="$(dirname $(pwd))"
export POETRY_VIRTUALENVS_IN_PROJECT=true
# Install conda
export PATH="$REMOTES_DIR/miniconda/bin:$PATH"
if ! type -P conda >/dev/null; then
(set -xe
if type -P curl >/dev/null; then
curl -sLo "$REMOTES_DIR/miniconda.sh" "$MINICONDA_PY38_URL"
elif type -P wget >/dev/null; then
wget -O "$REMOTES_DIR/miniconda.sh" "$MINICONDA_PY38_URL"
else
echo "ERROR: unable to download miniconda!"
exit 1
fi
test "$(sha256sum "$REMOTES_DIR/miniconda.sh")" = "$MINICONDA_PY38_HASH"
chmod +x "$REMOTES_DIR/miniconda.sh"
"$REMOTES_DIR/miniconda.sh" -b -p "$REMOTES_DIR/miniconda"
rm "$REMOTES_DIR/miniconda.sh"
) || exit $?
fi
# Enter conda environment
eval "$(conda shell.bash hook)" # basically `conda init`, without modifying .bashrc
if ! conda env list | grep "^$ENVIRON_NAME" -q ; then # Make it first
(set -xe # TODO the conda shell functions become VERY verbose with this setting
conda create --name $ENVIRON_NAME -y \
python==3.8.5 poetry=1.0.10
conda activate "$ENVIRON_NAME" # neccesary?
conda clean -ya
poetry install # first-time-setup of poetry
) || exit $?
fi
conda activate "$ENVIRON_NAME" || exit $?
# Enter the poetry venv
#source "$(poetry env info -p)/bin/activate"
# ^ Currently not needed, poetry currently populates the conda venv instead
# See: https://github.com/python-poetry/poetry/issues/1724
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment