File size: 3,689 Bytes
35f0320
051df5f
35f0320
 
 
 
 
 
 
 
 
 
 
 
 
051df5f
35f0320
 
 
 
051df5f
35f0320
051df5f
35f0320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
051df5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
# source teammate.sh

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'

_log()   { echo -e "${BLUE}[INFO]${NC}  $1"; }
_ok()    { echo -e "${GREEN}[OK]${NC}    $1"; }
_warn()  { echo -e "${YELLOW}[WARN]${NC}  $1"; }
_error() { echo -e "${RED}[ERROR]${NC} $1"; }

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
    _error "This script must be sourced: source teammate.sh"
    exit 1
fi

# configuration
OWNER=""    # <-- replace with your username of the person who ran hackathon_setup.sh before this
PROJECT_NAME="training2614"
TEAM_FOLDER="" # <-- replace with your team_name as done by OWNER
WRITE_TO_BASHRC="yes"

SCRATCH_BASE="/p/scratch/$PROJECT_NAME"
TEAM_DIR="$SCRATCH_BASE/$OWNER/$TEAM_FOLDER"

UV_BASE="$TEAM_DIR/.uv"
HF_CACHE="$TEAM_DIR/.cache"

echo ""
echo "============================================="
echo "   Shared Team Environment Setup"
echo "============================================="
echo ""
echo "  Project     : $PROJECT_NAME"
echo "  Team folder : $TEAM_DIR"
echo ""

_log "Step 1/4 - Checking cluster tools..."

if ! command -v jutil &> /dev/null; then
    _error "jutil not found. Are you on JURECA?"
    return 1
fi
_ok "jutil found."

_log "Step 2/4 - Activating project $PROJECT_NAME..."

jutil env activate -p "$PROJECT_NAME"

if [[ -z "$PROJECT" ]]; then
    _error "\$PROJECT is empty after activation."
    return 1
fi
_ok "Project activated. \$PROJECT = $PROJECT"

_log "Step 3/4 - Exporting shared cache paths..."

export UV_CACHE_DIR="$UV_BASE/cache"
export UV_TOOL_DIR="$UV_BASE/tools"
export UV_PYTHON_INSTALL_DIR="$UV_BASE/python"
export HF_HOME="$HF_CACHE"
export HUGGINGFACE_HUB_CACHE="$HF_CACHE/hub"

_ok "Shared environment variables exported in current shell."

if [[ "$WRITE_TO_BASHRC" == "yes" ]]; then
    if grep -q "TEAM SHARED UV/HF CONFIG: $TEAM_DIR" ~/.bashrc 2>/dev/null; then
        _warn "Shared config already present in ~/.bashrc"
    else
        cat << EOF >> ~/.bashrc

# TEAM SHARED UV/HF CONFIG: $TEAM_DIR
export PATH="\$HOME/.local/bin:\$PATH"
export UV_CACHE_DIR=$UV_BASE/cache
export UV_TOOL_DIR=$UV_BASE/tools
export UV_PYTHON_INSTALL_DIR=$UV_BASE/python
export HF_HOME=$HF_CACHE
export HUGGINGFACE_HUB_CACHE=$HF_CACHE/hub
EOF
        _ok "Shared config written to ~/.bashrc"
    fi
fi

_log "Step 4/4 - Checking access to shared folder and uv..."

if [[ ! -d "$TEAM_DIR" ]]; then
    _error "Shared team folder does not exist: $TEAM_DIR"
    return 1
fi

if [[ ! -r "$TEAM_DIR" || ! -x "$TEAM_DIR" ]]; then
    _error "You do not have proper access to: $TEAM_DIR"
    return 1
fi

_ok "You can access the shared team folder."

if command -v uv &> /dev/null; then
    _ok "uv found: $(uv --version 2>&1)"
else
    _warn "uv is not available in your shell. Installing for this user..."

    curl -LsSf https://astral.sh/uv/install.sh | sh

    if [[ -f "$HOME/.local/bin/env" ]]; then
        source "$HOME/.local/bin/env"
    fi

    export PATH="$HOME/.local/bin:$PATH"

    if command -v uv &> /dev/null; then
        _ok "uv installed: $(uv --version 2>&1)"
    else
        _error "uv installation seems to have failed."
        echo "Run these manually:"
        echo "curl -LsSf https://astral.sh/uv/install.sh | sh"
        echo "source \$HOME/.local/bin/env"
        return 1
    fi
fi

echo ""
echo "============================================="
echo -e "${GREEN}   Teammate shell setup complete!${NC}"
echo "============================================="
echo ""
echo "Use the shared folder with:"
echo "  cd $TEAM_DIR/<dataset-name>"
echo "  source .venv/bin/activate"
echo ""
echo "Or run directly:"
echo "  uv run $TEAM_DIR/<dataset-name>/main.py"
echo ""