Skip to content

Commit dbe4474

Browse files
calvinp0alongd
authored andcommitted
Enhance installation scripts with improved cleanup options and argument parsing
1 parent 5a4a184 commit dbe4474

5 files changed

Lines changed: 354 additions & 148 deletions

File tree

devtools/clean.sh

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,91 @@
11
#!/usr/bin/env bash
22
set -eo pipefail
33

4-
echo "🧹 Cleaning ARC, molecule, and RMG-Py build artifacts..."
4+
# -----------------------------------------------------------------------------
5+
# Helper: aggressively clean conda/micromamba caches & remove any known build
6+
# directories in our workspace. Ignores any permission errors.
7+
# -----------------------------------------------------------------------------
58

9+
clean_conda() {
10+
echo ">>> Cleaning conda/micromamba caches…"
11+
echo ">>> Current disk usage:"
12+
df -h . | sed '1!p;d' # show before-clean
613

7-
if [[ -d "RMG-Py" ]]; then
8-
echo "🧹 Running 'make clean' in RMG-Py..."
9-
(cd RMG-Py && make clean)
14+
if command -v micromamba &>/dev/null; then
15+
micromamba clean --all --yes || true
16+
elif command -v mamba &>/dev/null; then
17+
mamba clean --all --yes || true
18+
elif command -v conda &>/dev/null; then
19+
conda clean -afy || true
20+
fi
21+
22+
echo ">>> After cleaning conda/micromamba caches:"
23+
24+
df -h . | sed '1!p;d' # show after-clean
25+
26+
echo ">>> Cleaned conda/micromamba caches."
27+
}
28+
29+
clean_pip() {
30+
echo ">>> Cleaning pip cache…"
31+
32+
rm -rf "$HOME/.cache/pip" || true
33+
34+
echo ">>> Cleaned pip cache."
35+
}
36+
37+
clean_python_builds() {
38+
echo ">>> Cleaning Python build directories, .pyc, .pyd, and .so files…"
39+
40+
# Remove any "build/" or "dist/" dirs left behind in our repo clones
41+
find . -type d \( -name build -o -name dist \) -prune -exec rm -rf {} + 2>/dev/null || true
42+
43+
# Remove any __pycache__
44+
find . -type d -name "__pycache__" -prune -exec rm -rf {} + 2>/dev/null || true
45+
46+
# remove .pyc .pyd and .so files
47+
find . -type f \( -name "*.pyc" -o -name "*.pyd" -o -name "*.so" \) -exec rm -f {} + 2>/dev/null || true
48+
49+
echo ">>> Cleaned."
50+
51+
}
52+
# -----------------------------------------------------------------------------
53+
54+
# Main script execution
55+
# USER Passed Arguments
56+
if [[ "${1:-}" == "--conda" ]]; then
57+
clean_conda
58+
fi
59+
60+
if [[ "${1:-}" == "--pip" ]]; then
61+
clean_pip
1062
fi
1163

12-
# Remove Python cache files
13-
find . -type d -name "__pycache__" -exec rm -rf {} +
64+
if [[ "${1:-}" == "--python-builds" ]]; then
65+
clean_python_builds
66+
fi
1467

15-
# Remove coverage files
16-
rm -f .coverage coverage.xml
68+
if [[ "${1:-}" == "--all" ]]; then
69+
clean_conda
70+
clean_pip
71+
clean_python_builds
72+
fi
1773

18-
echo "✅ Clean completed."
74+
# What if the user didn't pass any arguments?
75+
if [[ -z "${1:-}" ]]; then
76+
echo "No arguments provided. Please specify --conda, --pip, --python-builds, or --all."
77+
echo "Example: ./devtools/clean.sh --all"
78+
exit 1
79+
elif [[ "${1:-}" == "--help" ]]; then
80+
echo "Usage: ./devtools/clean.sh [--conda | --pip | --python-builds | --all]"
81+
echo "Options:"
82+
echo " --conda Clean conda/micromamba caches"
83+
echo " --pip Clean pip cache"
84+
echo " --python-builds Clean Python build directories and files"
85+
echo " --all Clean all caches and build directories"
86+
exit 0
87+
elif [[ "${1:-}" != "--conda" && "${1:-}" != "--pip" && "${1:-}" != "--python-builds" && "${1:-}" != "--all" ]]; then
88+
echo "Invalid argument: $1"
89+
echo "Use --help for usage information."
90+
exit 1
91+
fi

devtools/install_all.sh

Lines changed: 95 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,65 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
# -------------------------------------------------------------------------
5+
# INSTALLATION OF ARC, RMG, and other external dependencies
6+
# Options:
7+
# --no-clean: Skip the aggressive cleanup of conda/micromamba caches and build directories.
8+
# --no-ext: Skip the installation of external dependencies (autotst, kinbot, etc.)
9+
# --rmg-*: Options for RMG installation
10+
# --arc-*: Options for ARC installation
11+
# -------------------------------------------------------------------------
12+
13+
# ── locate this script and the repo root ──────────────────────────────────
14+
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
15+
DEVTOOLS_DIR="$SCRIPT_DIR" # you are already in devtools
16+
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" # one level up
17+
18+
# helper so every sub-call works no matter where we launched from
19+
run_devtool () { bash "$DEVTOOLS_DIR/$1" "${@:2}"; }
20+
421
###################################################################################
5-
# Flag for cleaning
22+
# Flag for cleaning up disk space and caches, and for installing external dependencies
23+
# and their arguments.
624
#################################################################################
7-
SKIP_CLEAN=false
8-
[[ "${1:-}" == --no-clean ]] && SKIP_CLEAN=true
9-
10-
11-
# -----------------------------------------------------------------------------
12-
# Helper: aggressively clean conda/micromamba caches & remove any known build
13-
# directories in our workspace. Ignores any permission errors.
14-
# -----------------------------------------------------------------------------
15-
cleanup_disk() {
16-
echo ">>> Cleaning package manager caches and temporary build dirs…"
17-
18-
# Clean conda / micromamba
19-
if command -v micromamba &>/dev/null; then
20-
micromamba clean --all --yes || true
21-
elif command -v mamba &>/dev/null; then
22-
mamba clean --all --yes || true
23-
elif command -v conda &>/dev/null; then
24-
conda clean -afy || true
25-
fi
26-
27-
# Remove pip cache
28-
rm -rf "$HOME/.cache/pip" || true
2925

30-
# Remove any "build/" or "dist/" dirs left behind in our repo clones
31-
find . -type d \( -name build -o -name dist \) -prune -exec rm -rf {} + 2>/dev/null || true
26+
SKIP_CLEAN=false
27+
SKIP_EXT=false
28+
SKIP_ARC=false
29+
RMG_ARGS=()
30+
ARC_ARGS=()
31+
EXT_ARGS=()
32+
GENERIC_ARGS=()
33+
34+
while [[ $# -gt 0 ]]; do
35+
case "$1" in
36+
--no-clean) SKIP_CLEAN=true ;;
37+
--no-ext) SKIP_EXT=true ;;
38+
--no-arc) SKIP_ARC=true ;;
39+
--rmg-*) RMG_ARGS+=("${1#--rmg-}") ;;
40+
--arc-*) ARC_ARGS+=("${1#--arc-}") ;;
41+
--ext-*) EXT_ARGS+=("${1#--ext-}") ;;
42+
--help|-h)
43+
cat <<EOF
44+
Usage: $0 [global-flags] [--rmg-xxx] [--arc-yyy] [--ext-zzz]
45+
--no-clean Skip micromamba/conda cache cleanup
46+
--no-ext Skip external tools (AutoTST, KinBot, …)
47+
--rmg-path Forward '--path' to RMG installer
48+
--rmg-pip Forward '--pip' to RMG installer
49+
...
50+
EOF
51+
exit 0 ;;
52+
*) GENERIC_ARGS+=("$1") ;;
53+
esac
54+
shift
55+
done
3256

33-
# Remove any __pycache__
34-
find . -type d -name "__pycache__" -prune -exec rm -rf {} + 2>/dev/null || true
57+
echo ">>> Beginning full ARC external repo installation…"
58+
echo " RMG sub-flags : ${RMG_ARGS[*]:-(none)}"
59+
echo " ARC sub-flags : ${ARC_ARGS[*]:-(none)}"
60+
echo " EXT sub-flags : ${EXT_ARGS[*]:-(none)}"
3561

36-
# Prune any other big caches under home that we own
37-
rm -rf "$HOME/.cache"/git* "$HOME/.cache"/julia* || true
3862

39-
df -h . | sed '1!p;d' # show after-clean free space
40-
}
4163

4264
# -----------------------------------------------------------------------------
4365
# Main install sequence
@@ -47,57 +69,54 @@ pushd . >/dev/null
4769

4870
# 1) RMG
4971
echo "=== Installing RMG ==="
50-
bash devtools/install_rmg.sh
51-
! $SKIP_CLEAN && cleanup_disk
72+
run_devtool install_rmg.sh "${RMG_ARGS[@]}"
73+
5274

5375
# # 2) PyRDL
5476
# echo "=== Installing PyRDL ==="
5577
# bash devtools/install_pyrdl.sh
5678
# ! $SKIP_CLEAN && cleanup_disk
5779

58-
# # 3) ARC itself (skip env creation in CI)
59-
# if [[ -z "${CI:-}" ]]; then
60-
# echo "=== Installing ARC ==="
61-
# bash devtools/install_arc.sh
62-
# ! $SKIP_CLEAN && cleanup_disk
63-
# else
64-
# echo "ℹ️ CI detected, skipping arc_env creation."
65-
# fi
66-
67-
# 4) GCN (CPU)
68-
echo "=== Installing GCN CPU ==="
69-
bash devtools/install_gcn_cpu.sh
70-
! $SKIP_CLEAN && cleanup_disk
71-
72-
# 5) AutoTST
73-
echo "=== Installing AutoTST ==="
74-
bash devtools/install_autotst.sh
75-
! $SKIP_CLEAN && cleanup_disk
76-
77-
# 6) KinBot
78-
echo "=== Installing KinBot ==="
79-
bash devtools/install_kinbot.sh
80-
! $SKIP_CLEAN && cleanup_disk
81-
82-
# 7) Open Babel
83-
echo "=== Installing OpenBabel ==="
84-
bash devtools/install_ob.sh
85-
! $SKIP_CLEAN && cleanup_disk
86-
87-
# 8) xtb
88-
echo "=== Installing xtb ==="
89-
bash devtools/install_xtb.sh
90-
! $SKIP_CLEAN && cleanup_disk
91-
92-
# 9) Sella
93-
echo "=== Installing Sella ==="
94-
bash devtools/install_sella.sh
95-
! $SKIP_CLEAN && cleanup_disk
96-
97-
# 10) TorchANI
98-
echo "=== Installing TorchANI ==="
99-
bash devtools/install_torchani.sh
100-
! $SKIP_CLEAN && cleanup_disk
80+
# 3) ARC itself (skip env creation in CI or if user requests it)
81+
if [[ -z "${CI:-}" ]] && [[ -z "${SKIP_ARC:-}" ]]; then
82+
echo "=== Installing ARC ==="
83+
run_devtool install_arc.sh "${ARC_ARGS[@]}"
84+
85+
if [[ $SKIP_CLEAN == false ]]; then
86+
echo "=== Cleaning up ARC build artifacts ==="
87+
# Cleanup disk space after ARC installation
88+
run_devtool clean.sh --python-builds --pip
89+
echo "ℹ️ Disk cleanup complete."
90+
else
91+
echo "ℹ️ Skipping ARC cleanup as per --no-clean flag."
92+
fi
93+
else
94+
echo "ℹ️ CI detected or --no-arc flag set. Skipping ARC installation."
95+
fi
96+
97+
if [[ $SKIP_EXT == false ]]; then
98+
# map of friendly names → installer scripts
99+
declare -A EXT_INSTALLERS=(
100+
[GCN\ CPU]=install_gcn_cpu.sh
101+
[AutoTST]=install_autotst.sh
102+
[KinBot]=install_kinbot.sh
103+
[OpenBabel]=install_ob.sh
104+
[xtb]=install_xtb.sh
105+
[Sella]=install_sella.sh
106+
[TorchANI]=install_torchani.sh
107+
)
108+
109+
for name in "${!EXT_INSTALLERS[@]}"; do
110+
echo "=== Installing $name ==="
111+
run_devtool "${EXT_INSTALLERS[$name]}"
112+
113+
done
114+
else
115+
echo "ℹ️ --no-ext flag set. Skipping external-dependency installs."
116+
fi
117+
118+
# 4) Clean up disk space
119+
run_devtool clean.sh --conda
101120

102121
popd >/dev/null
103122

devtools/install_autotst.sh

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/bin/bash -l
22
set -e
33

4+
# ── locate folders relative to this script ────────────────────────────────
5+
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
6+
ARC_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" # …/ARC_Mol
7+
CLONE_ROOT="$(cd "$ARC_ROOT/.." && pwd)" # directory that *contains* ARC_Mol
8+
cd "$CLONE_ROOT"
9+
410
if command -v micromamba &> /dev/null; then
511
echo "✔️ Micromamba is installed."
612
COMMAND_PKG=micromamba
@@ -22,7 +28,6 @@ elif [ "$COMMAND_PKG" = "mamba" ] || [ "$COMMAND_PKG" = "conda" ]; then
2228
source "$BASE/etc/profile.d/conda.sh"
2329
fi
2430

25-
pushd ..
2631
echo ">>> Cloning or updating AutoTST..."
2732
if [ -d AutoTST ]; then
2833
cd AutoTST
@@ -38,20 +43,20 @@ else
3843
cd AutoTST
3944
fi
4045

41-
AUTO_PATH_LINE="export PYTHONPATH=\$PYTHONPATH:$(pwd)"
42-
if ! grep -Fxq "$AUTO_PATH_LINE" ~/.bashrc; then
46+
AUTO_PATH_LINE="export PYTHONPATH=\"\$PYTHONPATH:$(pwd)\""
47+
if ! grep -Fqx "$AUTO_PATH_LINE" ~/.bashrc; then
4348
echo "$AUTO_PATH_LINE" >> ~/.bashrc
4449
echo "✔️ Added AutoTST path to ~/.bashrc"
4550
else
4651
echo "ℹ️ AutoTST path already exists in ~/.bashrc"
4752
fi
4853

49-
if $COMMAND_PKG env list | grep -q '^tst_env\s'; then
54+
if $COMMAND_PKG env list | awk '{print $1}' | sed 's/^\*//' | grep -Fxq 'tst_env'; then
5055
echo ">>> Updating existing environment tst_env..."
5156
if [ "$COMMAND_PKG" != "conda" ]; then
52-
$COMMAND_PKG env update -n tst_env -f environment.yml --prune -y
57+
$COMMAND_PKG env update -n tst_env -f environment.yml -y
5358
else
54-
$COMMAND_PKG env update -n tst_env -f environment.yml --prune
59+
$COMMAND_PKG env update -n tst_env -f environment.yml -y
5560
fi
5661
else
5762
echo ">>> Creating new environment tst_env..."
@@ -62,12 +67,12 @@ else
6267
fi
6368
fi
6469

65-
echo ">>> Installing extra dependencies into tst_env..."
66-
if [ "$COMMAND_PKG" != "conda" ]; then
67-
$COMMAND_PKG install -n tst_env -c conda-forge pyyaml -y
70+
echo ">>> Checking for pyyaml. Will be installing extra dependencies into tst_env if not there..."
71+
if $COMMAND_PKG list -n tst_env pyyaml | grep -Eq '^\*?\s*pyyaml\s'; then
72+
echo "ℹ️ PyYAML already in tst_env – skipping install."
6873
else
69-
$COMMAND_PKG install -n tst_env -c conda-forge pyyaml
74+
echo "➜ Installing PyYAML into tst_env…"
75+
$COMMAND_PKG install -n tst_env -c conda-forge pyyaml -y
7076
fi
7177

72-
popd > /dev/null
7378
echo "✅ Done installing AutoTST."

devtools/install_gcn.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/bin/bash -l
22
set -e
33

4+
# ── locate folders relative to this script ────────────────────────────────
5+
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
6+
ARC_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" # …/ARC_Mol
7+
CLONE_ROOT="$(cd "$ARC_ROOT/.." && pwd)" # directory that *contains* ARC_Mol
8+
cd "$CLONE_ROOT"
9+
410
if command -v micromamba &> /dev/null; then
511
echo "✔️ Micromamba is installed."
612
COMMAND_PKG=micromamba
@@ -23,7 +29,6 @@ else
2329
. "$BASE/etc/profile.d/conda.sh"
2430
fi
2531

26-
pushd ..
2732

2833
echo ">>> Cloning or updating TS-GCN..."
2934
if [ -d TS-GCN ]; then
@@ -61,5 +66,4 @@ else
6166
exit 1
6267
fi
6368

64-
popd > /dev/null
6569
echo "✅ Done installing GCN."

0 commit comments

Comments
 (0)