Skip to content

Commit 53c5eb5

Browse files
author
Ryan Calvin Barron
committed
lynx startup helper
1 parent 7e14b03 commit 53c5eb5

3 files changed

Lines changed: 193 additions & 0 deletions

File tree

examples/Lynx/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@
1616
```ssh USER@HOST -L 8501:localhost:8501```
1717
6. Have fun!
1818

19+
20+
21+
## OPTIONAL STARTUP
22+
23+
zsh ./start_lynx.sh -p ../Full\ TELF\ Pipeline/single_block_examples/example_results/semantic_HNMFk_collection_slurm_option/07_SemanticHNMFk

examples/Lynx/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"VIEW_TYPE":"Document Analysis",
3+
"DOCUMENT_FILE_START_WITH":"best_50_docs_in_",
4+
"ROOT_NAME":"Root",
5+
"TEXT_COLUMN":"clean_title_abstract",
6+
"ATTRIBUTE_COLUMN":"slic_authors",
7+
"ATTRIBUTE_COLUMN_SPLIT_BY":";"
8+
}

examples/Lynx/start_lynx.sh

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
#!/usr/bin/env sh
2+
# -------------------------------------------------------------
3+
# T-ELF / TELF launcher (zsh/bash/sh compatible)
4+
# - CDs to a directory that CONTAINS "TELF/" so:
5+
# streamlit run TELF/applications/Lynx/frontend/main.py
6+
# works and the app finds TELF/projects correctly.
7+
# - Copies each -p project into TELF/projects/
8+
# - ALSO copies a settings.json that sits NEXT TO THIS SCRIPT
9+
# into each destination project (backs up existing one).
10+
#
11+
# Usage:
12+
# ./start_lynx.sh
13+
# ./start_lynx.sh -p "../Full TELF Pipeline/.../07_SemanticHNMFk"
14+
# ./start_lynx.sh -p /abs/path/ProjA -p "../rel path/ProjB"
15+
# ./start_lynx.sh --ssh user@host --port 8501
16+
# ./start_lynx.sh --no-copy
17+
# -------------------------------------------------------------
18+
19+
set -eu
20+
21+
PORT=8501
22+
SSH_TARGET=""
23+
COPY_PROJECTS=1
24+
PROJECTS=""
25+
26+
# --- parse args (POSIX)
27+
while [ $# -gt 0 ]; do
28+
case "$1" in
29+
-p|--project)
30+
[ $# -ge 2 ] || { echo "Missing value for $1" >&2; exit 1; }
31+
PROJECTS="${PROJECTS}${PROJECTS:+
32+
}$2"
33+
shift 2
34+
;;
35+
--ssh)
36+
[ $# -ge 2 ] || { echo "Missing value for $1" >&2; exit 1; }
37+
SSH_TARGET="$2"
38+
shift 2
39+
;;
40+
--port)
41+
[ $# -ge 2 ] || { echo "Missing value for $1" >&2; exit 1; }
42+
PORT="$2"
43+
shift 2
44+
;;
45+
--no-copy)
46+
COPY_PROJECTS=0
47+
shift
48+
;;
49+
-h|--help)
50+
echo "Usage: $0 [-p PATH]... [--ssh USER@HOST] [--port N] [--no-copy]"
51+
exit 0
52+
;;
53+
*)
54+
echo "Unknown arg: $1" >&2
55+
exit 1
56+
;;
57+
esac
58+
done
59+
60+
# ---- resolve script dir robustly (works in zsh/bash/sh)
61+
case "$0" in
62+
/*) SCRIPT_PATH="$0" ;;
63+
*) SCRIPT_PATH="$(pwd)/$0" ;;
64+
esac
65+
SCRIPT_DIR=$(cd "$(dirname -- "$SCRIPT_PATH")" 2>/dev/null && pwd -P)
66+
SETTINGS_SRC="$SCRIPT_DIR/settings.json"
67+
68+
# ---- find a repo root that CONTAINS a TELF/ directory
69+
# Try common layouts:
70+
# <prefix>/TELF/...
71+
# <prefix>/T-ELF/TELF/...
72+
find_repo_root() {
73+
CUR="$SCRIPT_DIR"
74+
i=0
75+
while [ $i -le 6 ]; do
76+
if [ -d "$CUR/TELF" ]; then
77+
echo "$CUR"; return 0
78+
fi
79+
if [ -d "$CUR/T-ELF/TELF" ]; then
80+
echo "$CUR/T-ELF"; return 0
81+
fi
82+
if [ -d "$CUR/../TELF" ]; then
83+
echo "$(cd "$CUR/.." && pwd -P)"; return 0
84+
fi
85+
CUR=$(cd "$CUR/.." 2>/dev/null && pwd -P)
86+
i=$((i+1))
87+
done
88+
echo ""
89+
}
90+
91+
REPO_ROOT="$(find_repo_root)"
92+
if [ -z "$REPO_ROOT" ]; then
93+
echo "Error: couldn't locate a directory that contains 'TELF/' starting from: $SCRIPT_DIR" >&2
94+
exit 1
95+
fi
96+
97+
TELF_DIR="$REPO_ROOT"
98+
APP_REL="TELF/applications/Lynx/frontend/main.py"
99+
APP_ABS="$REPO_ROOT/$APP_REL"
100+
PROJECTS_DIR="$TELF_DIR/projects"
101+
102+
if [ ! -f "$APP_ABS" ]; then
103+
echo "Error: Streamlit app not found at: $APP_ABS" >&2
104+
exit 1
105+
fi
106+
107+
# Ensure projects dir
108+
mkdir -p "$PROJECTS_DIR"
109+
110+
# Resolve a user-supplied directory (relative to current working dir; handles spaces)
111+
resolve_dir() {
112+
_p="$1"
113+
case "$_p" in
114+
/*) ABS="$_p" ;;
115+
*) ABS="$(pwd)/$_p" ;;
116+
esac
117+
if cd "$ABS" 2>/dev/null; then
118+
pwd -P
119+
cd - >/dev/null 2>&1 || true
120+
return 0
121+
fi
122+
return 1
123+
}
124+
125+
copy_settings_into() {
126+
_dest="$1"
127+
if [ -f "$SETTINGS_SRC" ]; then
128+
if [ -f "$_dest/settings.json" ]; then
129+
mv -f "$_dest/settings.json" "$_dest/settings.json.bak"
130+
fi
131+
cp -f "$SETTINGS_SRC" "$_dest/settings.json"
132+
echo " -> settings.json copied into '$(basename -- "$_dest")' (backup: settings.json.bak if existed)"
133+
else
134+
echo " -> Warning: settings.json not found next to the script at: $SETTINGS_SRC (skipping settings copy)" >&2
135+
fi
136+
}
137+
138+
# Copy projects (if any)
139+
if [ "$COPY_PROJECTS" -eq 1 ] && [ -n "$PROJECTS" ]; then
140+
echo "$PROJECTS" | while IFS= read -r src_raw; do
141+
[ -n "$src_raw" ] || continue
142+
if ! src_abs="$(resolve_dir "$src_raw")"; then
143+
echo "Warning: project path not found: $src_raw (skipping)" >&2
144+
continue
145+
fi
146+
base_name=$(basename -- "$src_abs")
147+
dest="$PROJECTS_DIR/$base_name"
148+
echo "Copying '$src_raw' -> '$dest' ..."
149+
rm -rf -- "$dest"
150+
if command -v rsync >/dev/null 2>&1; then
151+
rsync -a --delete "$src_abs"/ "$dest"/
152+
else
153+
mkdir -p "$dest"
154+
cp -R -- "$src_abs"/. "$dest"/
155+
fi
156+
# Always drop the local settings.json into the copied project
157+
copy_settings_into "$dest"
158+
done
159+
fi
160+
161+
# Optional SSH port forward
162+
if [ -n "$SSH_TARGET" ]; then
163+
echo "Starting SSH tunnel: localhost:$PORT -> $SSH_TARGET:localhost:$PORT"
164+
if ! ssh -N -f -L "$PORT:localhost:$PORT" "$SSH_TARGET"; then
165+
echo "Warning: SSH port forward failed; continuing without it." >&2
166+
fi
167+
fi
168+
169+
# Check streamlit
170+
if ! command -v streamlit >/dev/null 2>&1; then
171+
echo "Error: 'streamlit' not found on PATH. Activate your env or 'pip install streamlit'." >&2
172+
exit 1
173+
fi
174+
175+
# CD to the repo root so the *relative* Streamlit path works
176+
cd "$REPO_ROOT"
177+
echo "Working directory: $(pwd -P)"
178+
echo "Ensured: $(pwd -P)/TELF/projects"
179+
echo "Launching: streamlit run $APP_REL --server.port $PORT"
180+
exec streamlit run "$APP_REL" --server.port "$PORT"

0 commit comments

Comments
 (0)