Skip to content

Commit e8d1e47

Browse files
authored
Merge pull request #3172 from IntersectMBO/clusterlib_reinstall_editable
feat(dev): add make target for editable clusterlib install
2 parents a32f245 + 8180973 commit e8d1e47

File tree

3 files changed

+89
-12
lines changed

3 files changed

+89
-12
lines changed

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ build_doc:
3535
doc:
3636
./scripts/deploy_doc.sh
3737

38+
39+
# reinstall cardano-clusterlib-py in editable mode from a given git repository
40+
.PHONY: reinstall-editable
41+
reinstall-editable:
42+
@if [ -z "$(repo)" ]; then \
43+
echo "Usage: make reinstall-editable repo=/path/to/cardano-clusterlib-py" >&2; \
44+
exit 1; \
45+
fi
46+
@./scripts/clusterlib_reinstall_editable.sh "$(repo)"
47+
48+
3849
# run tests
3950

4051
TESTS_DIR ?= cardano_node_tests/

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ prepare-cluster-scripts -c -d dev_workdir/conway_fast -t conway_fast
200200
make check_dev_env
201201
```
202202

203+
### 🧰 Reinstall `cardano-clusterlib` in Editable Mode
204+
205+
```sh
206+
make reinstall-editable repo=../cardano-clusterlib-py
207+
```
208+
203209
### 🧪 Run Individual Tests
204210

205211
```sh
@@ -214,18 +220,6 @@ source "$(poetry env info --path)"/bin/activate
214220
make lint
215221
```
216222

217-
### 🧰 Use `cardano-clusterlib` in Dev Mode
218-
219-
```sh
220-
source "$(poetry env info --path)"/bin/activate
221-
make install
222-
pip uninstall cardano-clusterlib
223-
cd ../cardano-clusterlib-py
224-
pip install -e . --config-settings editable_mode=compat
225-
cd -
226-
python -c 'from cardano_clusterlib import clusterlib_klass; print(clusterlib_klass.__file__)'
227-
```
228-
229223
> ⚠️ After each dependencies update, repeat the steps above to retain dev mode.
230224
231225
### 📦 Update Poetry Dependencies
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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

Comments
 (0)