-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·81 lines (66 loc) · 2.74 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·81 lines (66 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# Export repo root so k4bench can locate the C++ plugin
export K4BENCH_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export LD_LIBRARY_PATH="${K4BENCH_REPO}/plugin/install/lib:${K4BENCH_REPO}/plugin/build:${LD_LIBRARY_PATH}"
# Use environment variable if set, otherwise use default version
KEY4HEP_VERSION=${KEY4HEP_VERSION:-"2026-04-08"}
# Setup Key4HEP environment only if not already set
if [ -z "$KEY4HEP_STACK" ]; then
source /cvmfs/sw.hsf.org/key4hep/setup.sh -r "${KEY4HEP_VERSION}"
else
echo "✅ KEY4HEP_STACK is already set. Skipping Key4HEP environment setup."
fi
# Set up python virtual environment only if it doesn't exist
mkdir -p ~/.local/bin
export PATH=~/.local/bin:"${PATH}"
# Download cvmfs-venv script if not already present
if [ ! -f ~/.local/bin/cvmfs-venv ]; then
curl -sL https://raw.githubusercontent.com/jbeirer/cvmfs-venv/main/cvmfs-venv.sh -o ~/.local/bin/cvmfs-venv
chmod +x ~/.local/bin/cvmfs-venv
fi
# Check if the virtual environment already exists
if [ ! -d "py-venv" ]; then
cvmfs-venv py-venv
else
echo "✅ Virtual environment 'py-venv' already exists. Skipping creation."
fi
# Check if the virtual environment is already activated
if [ -z "$VIRTUAL_ENV" ]; then
echo "🔄 Activating virtual environment..."
. py-venv/bin/activate
else
echo "✅ Virtual environment is already active."
fi
# Check if all required Python dependencies are installed
pip install --quiet --no-dependencies -r requirements.txt
# Build the k4Bench timing plugin (idempotent)
bash "${K4BENCH_REPO}/plugin/build.sh"
# Check if pre-commit is already installed
if ! pre-commit --version &>/dev/null; then
echo "🔄 Installing pre-commit hooks..."
pre-commit install
else
echo "✅ Pre-commit hooks are already installed."
fi
# Capture all environment variables for the current session
# This allows us to use jupyter notebooks in the key4hep environment
ENV_FILE=".env"
echo "🔄 Saving all environment variables to .env file..."
# Use printenv to retrieve all environment variables and format them for a .env file.
#
# Exclusions:
# 1) Exclude PKG_CONFIG_PATH to prevent "execvp(3) failed: Argument list too long."
# - There is nothing special about PKG_CONFIG_PATH, but it is long and unnecessary.
# 2) Exclude all SINGULARITY and APPTAINER-related variables.
# - This helps avoid potential conflicts or issues with Singularity/Apptainer.
EXCLUDE_PATTERNS=(
PKG_CONFIG_PATH
".*SINGULARITY.*"
".*APPTAINER.*"
ALRB_CONT_IMAGE
)
# Convert patterns into a grep-compatible regex
EXCLUDE_REGEX="$(printf "|%s" "${EXCLUDE_PATTERNS[@]}" | cut -c2-)"
printenv | grep -vE "^(${EXCLUDE_REGEX})=" \
| awk -F= '{print $1"=\"" $2 "\""}' > "$ENV_FILE"
echo "✅ .env file created successfully."