File size: 4,117 Bytes
439e630
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# Setup script for ChartPipeline on a fresh machine.
# Run from the project root (the directory this script is in).
#
# Prereqs you have to handle BEFORE running this script:
#   1. Python 3.10+ installed (conda or system).
#   2. Node.js 18+ installed (`node -v`).
#   3. Google Chrome or Chromium installed at /usr/bin/google-chrome
#      (or set PUPPETEER_EXECUTABLE_PATH to its real path).
#   4. librsvg2-bin installed (provides rsvg-convert).  On Ubuntu:
#        sudo apt install librsvg2-bin tmux
#      If you have no sudo, install via conda:
#        conda install -c conda-forge librsvg tmux
#   5. Input data pools available at the paths config.py points to,
#      e.g. /data/liduan/resources/claude_data_v2 and claude_new.
#      Edit config.data_resource_dirs to match this machine if needed.

set -u
cd "$(dirname "$0")"
ROOT="$(pwd)"
echo "[setup] cwd=$ROOT"

# ---- 1. Python deps ----
echo
echo "============================================================"
echo "[setup] installing python deps from requirements.txt"
echo "============================================================"
pip install -r requirements.txt
# Things requirements.txt was missing on the source machine; install
# defensively so chart_engine + selenium-based screenshot both work.
pip install pyecharts snapshot_selenium selenium

# ---- 2. Node deps ----
echo
echo "============================================================"
echo "[setup] installing node deps (puppeteer / echarts ...)"
echo "============================================================"
if [[ -f package.json ]]; then
  # IMPORTANT: ChartPipeline's puppeteer was patched to *re-use* an existing
  # Chrome via PUPPETEER_EXECUTABLE_PATH; skip the bundled chromium download
  # to save ~300 MB and avoid network friction.
  PUPPETEER_SKIP_DOWNLOAD=1 npm install
else
  echo "[setup] package.json missing, skipping npm install"
fi

# ---- 3. System binaries sanity check ----
echo
echo "============================================================"
echo "[setup] checking system binaries"
echo "============================================================"
for bin in google-chrome rsvg-convert tmux node npm python; do
  loc="$(command -v "$bin" 2>/dev/null || true)"
  if [[ -n "$loc" ]]; then
    printf '  %-14s  OK   %s\n' "$bin" "$loc"
  else
    printf '  %-14s  MISSING  -- you need to install this before running pipeline.py\n' "$bin"
  fi
done

# ---- 4. PUPPETEER_EXECUTABLE_PATH ----
echo
echo "============================================================"
echo "[setup] puppeteer chrome path"
echo "============================================================"
CHROME_BIN="${PUPPETEER_EXECUTABLE_PATH:-$(command -v google-chrome || command -v chromium || true)}"
if [[ -n "$CHROME_BIN" ]]; then
  echo "  PUPPETEER_EXECUTABLE_PATH = $CHROME_BIN  (export this before running pipeline.py)"
else
  echo "  WARNING: no chrome/chromium found; puppeteer will fail at runtime"
fi

# ---- 5. Quick import test ----
echo
echo "============================================================"
echo "[setup] verifying config + key imports"
echo "============================================================"
python - <<'PY'
import importlib
import config
print(f"  config.resource_path        = {config.resource_path}")
print(f"  config.data_resource_dirs[0]= {config.data_resource_dirs[0]}")
for mod in (
    "modules.chart_engine.template.template_registry",
    "modules.infographics_generator.template_utils",
    "modules.infographics_generator.infographics_generator",
):
    importlib.import_module(mod)
    print(f"  import {mod} OK")
PY

echo
echo "[setup] DONE."
echo "Next steps:"
echo "  1. Edit config.py 's data_resource_dirs if data pools live elsewhere on this host."
echo "  2. (optional) Edit allowed_chart_types.json to restrict which chart_type are eligible."
echo "  3. Launch a chart-only run, e.g.:"
echo "       export PUPPETEER_EXECUTABLE_PATH=$CHROME_BIN"
echo "       tmux new-session -d -s chart_10h \\"
echo "         \"PRIOR_SESSION=__none__ THREADS=48 DEADLINE_SEC=36000 bash scripts/run_10h_loop.sh\""