|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +err() { printf "Error: %s\n" "$*" >&2; } |
| 6 | +usage() { printf "Usage: %s /path/to/cardano-clusterlib-py\n" "${0}"; } |
| 7 | + |
| 8 | +if [ $# -ne 1 ]; then |
| 9 | + usage |
| 10 | + exit 64 |
| 11 | +fi |
| 12 | +REPO_PATH=$1 |
| 13 | + |
| 14 | +TOP_DIR="$(readlink -m "${0%/*}/..")" |
| 15 | +cd "$TOP_DIR" >/dev/null |
| 16 | + |
| 17 | +# Sanity checks |
| 18 | +if [ -n "${IN_NIX_SHELL:-""}" ]; then |
| 19 | + err "This script is not supposed to run inside nix shell." |
| 20 | + exit 1 |
| 21 | +fi |
| 22 | + |
| 23 | +# Activate poetry virtual environment |
| 24 | +if [ -z "${VIRTUAL_ENV:-}" ]; then |
| 25 | + # shellcheck disable=SC2091 |
| 26 | + $(poetry env activate) |
| 27 | + # Override PYTHONPATH to prefer virtual environment packages over nix packages |
| 28 | + PYTHONPATH="$(echo "$VIRTUAL_ENV"/lib/python3*/site-packages):${PYTHONPATH:-}" |
| 29 | + export PYTHONPATH |
| 30 | +fi |
| 31 | +if [ -z "${VIRTUAL_ENV:-}" ]; then |
| 32 | + err "Failed to activate virtual environment." |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +# Double-check python is actually running inside a venv |
| 37 | +if ! python - <<'PY' |
| 38 | +import sys |
| 39 | +raise SystemExit(0 if sys.prefix != getattr(sys, "base_prefix", sys.prefix) else 1) |
| 40 | +PY |
| 41 | +then |
| 42 | + err "Python indicates it's not running inside a virtual environment." |
| 43 | + exit 1 |
| 44 | +fi |
| 45 | + |
| 46 | +# Check that cardano-clusterlib is installed |
| 47 | +if ! python -m pip show cardano-clusterlib >/dev/null 2>&1; then |
| 48 | + err "Package 'cardano-clusterlib' is not installed in this environment." |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | + |
| 52 | +# Validate repo path |
| 53 | +if [ ! -d "$REPO_PATH" ]; then |
| 54 | + err "Repo path not found: $REPO_PATH" |
| 55 | + exit 1 |
| 56 | +fi |
| 57 | +if [[ ! -f "$REPO_PATH/pyproject.toml" && ! -f "$REPO_PATH/cardano_clusterlib" ]]; then |
| 58 | + err "Given path doesn't look like the cardano-clusterlib-py repo." |
| 59 | + exit 1 |
| 60 | +fi |
| 61 | + |
| 62 | +echo "Uninstalling 'cardano-clusterlib' from current environment..." |
| 63 | +python -m pip uninstall -y cardano-clusterlib |
| 64 | + |
| 65 | +echo "Installing editable from: $REPO_PATH" |
| 66 | +cd "$REPO_PATH" >/dev/null |
| 67 | +python -m pip install -e . --config-settings editable_mode=compat |
| 68 | + |
| 69 | +echo |
| 70 | +echo "Verifying editable install (should point into your repo, not site-packages):" |
| 71 | +cd "$TOP_DIR" >/dev/null |
| 72 | +python -c 'from cardano_clusterlib import clusterlib_klass; print(clusterlib_klass.__file__)' |
0 commit comments