Created
June 13, 2022 06:03
-
-
Save LeBaronDeCharlus/f91f4c29a5f655920d4c65a62eb275b0 to your computer and use it in GitHub Desktop.
Direnv ultimate python configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # .envrc | |
| # from https://kaderovski.com/posts/ultimate-python-development-environment-configuration/ | |
| layout pyenv 3.10.5 | |
| # POETRY | |
| if [[ ! -f pyproject.toml ]]; then | |
| log_status 'No pyproject.toml found. Will initialize poetry in no-interactive mode' | |
| poetry init -n -q | |
| poetry run pip install -U pip wheel setuptools | |
| fi | |
| poetry run echo >> /dev/null | |
| local VENV=$(dirname $(poetry run which python)) | |
| export VIRTUAL_ENV=$(echo "$VENV" | rev | cut -d'/' -f2- | rev) | |
| export POETRY_ACTIVE=1 | |
| PATH_add "$VENV" | |
| if [ ! -L .venv ]; then | |
| ln -ns $VIRTUAL_ENV .venv | |
| fi | |
| # CHEKING IF TOMB IS OPEN | |
| if ! stat $HOME/.password-store/.gpg-id > /dev/null 2>&1 ; then | |
| # IF NOT OPEN IT | |
| pass open | |
| fi | |
| # THEN PUT SECRET IN ENV | |
| export MY_SECRET=$(pass show kaderovski.com/blog/some_secret) | |
| # CHECKING COMMANDS DEPENDENCIES | |
| DIRENV_CMD_DEPENDENCIES="unzip tar mkdir curl chmod rm" | |
| for mandatory_cmd in ${DIRENV_CMD_DEPENDENCIES}; do | |
| if [ -z "$(which ${mandatory_cmd})" ]; then | |
| echo "===> Mandatory command not found: ${mandatory_cmd}" | |
| exit 1 | |
| fi | |
| done | |
| export DIRENV_TMP_DIR="${PWD}/.direnv" | |
| export DIRENV_BIN_DIR="${DIRENV_TMP_DIR}/bin" | |
| if [ ! -e "${DIRENV_BIN_DIR}" ]; then | |
| mkdir -p "${DIRENV_BIN_DIR}" | |
| fi | |
| export PATH="${DIRENV_BIN_DIR}:${PATH}" | |
| # PACKER INSTALLATION | |
| PACKER_VERSION="1.8.1" | |
| PACKER_ARCH="linux_amd64" | |
| PACKER_PKG_NAME="packer_${PACKER_VERSION}_${PACKER_ARCH}.zip" | |
| PACKER_PKG_URL="https://releases.hashicorp.com/packer/${PACKER_VERSION}/${PACKER_PKG_NAME}" | |
| PACKER_PKG_PATH="${DIRENV_TMP_DIR}/${PACKER_PKG_NAME}" | |
| if [ ! -e "${DIRENV_BIN_DIR}/packer" ]; then | |
| echo "===> Getting packer:${PACKER_VERSION}:${PACKER_ARCH} (can take a while to execute)" | |
| curl -s -L "${PACKER_PKG_URL}" -o "${PACKER_PKG_PATH}" | |
| unzip ${PACKER_PKG_PATH} -d ${DIRENV_BIN_DIR} | |
| chmod 700 ${DIRENV_BIN_DIR}/packer | |
| rm -f ${PACKER_PKG_PATH} | |
| fi | |
| # ADDONS | |
| ENV_ADDONS=".env.packer .env.custom_config" | |
| for addon in ${ENV_ADDONS}; do | |
| if [ -e "${PWD}/${addon}" ]; then | |
| source ${PWD}/${addon} | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment