Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 11,362 Bytes
d15f07c | 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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | #!/bin/bash
set -e
echo "π¦· CommunityOne Open Navigator - Installation Script"
echo "=================================================="
echo ""
# Install system-level dependencies when possible.
#
# Two things need OS packages, not just pip:
# - Tesseract OCR (runtime, for the OCR fallback)
# - libxml2 + libxslt (build-time headers for lxml β pip compiles lxml
# from source on distros without a matching wheel,
# e.g. a fresh Fedora, and the build fails without
# the *-devel/*-dev headers + a C compiler)
#
# run_root: run a privileged command as root directly, via sudo, or warn.
run_root() {
if [ "$(id -u)" -eq 0 ]; then
"$@"
elif command -v sudo &> /dev/null; then
sudo "$@"
else
echo "β Need root to run: $*"
echo " Re-run as root, or run that command manually, then re-run setup."
return 1
fi
}
echo "Checking system dependencies (Tesseract OCR + libxml2/libxslt headers)..."
if command -v apt-get &> /dev/null; then
# Debian/Ubuntu. libxslt1-dev pulls in libxml2-dev; build-essential gives the compiler.
run_root apt-get update || true
run_root apt-get install -y tesseract-ocr libxml2-dev libxslt1-dev build-essential || \
echo "β Could not auto-install system deps via apt-get; install them manually if pip fails on lxml."
elif command -v dnf &> /dev/null; then
# Fedora/RHEL/CentOS Stream.
run_root dnf install -y tesseract libxml2-devel libxslt-devel gcc python3-devel || \
echo "β Could not auto-install system deps via dnf; install them manually if pip fails on lxml."
elif command -v yum &> /dev/null; then
# Older RHEL/CentOS.
run_root yum install -y tesseract libxml2-devel libxslt-devel gcc python3-devel || \
echo "β Could not auto-install system deps via yum; install them manually if pip fails on lxml."
elif command -v pacman &> /dev/null; then
# Arch.
run_root pacman -Sy --noconfirm tesseract libxml2 libxslt gcc || \
echo "β Could not auto-install system deps via pacman; install them manually if pip fails on lxml."
elif command -v zypper &> /dev/null; then
# openSUSE.
run_root zypper install -y tesseract-ocr libxml2-devel libxslt-devel gcc python3-devel || \
echo "β Could not auto-install system deps via zypper; install them manually if pip fails on lxml."
elif command -v brew &> /dev/null; then
# macOS. Homebrew ships lxml wheels via pip normally, but keep the libs handy.
brew install tesseract libxml2 libxslt || true
else
echo "β Unsupported package manager. Install these manually before continuing:"
echo " - tesseract (OCR)"
echo " - libxml2 + libxslt development headers (libxml2-devel/libxslt-devel or libxml2-dev/libxslt1-dev)"
echo " - a C compiler (gcc) + Python development headers"
fi
if command -v tesseract &> /dev/null; then
echo "β Tesseract available: $(tesseract --version | head -n 1)"
else
echo "β Tesseract is still missing. OCR fallback will remain disabled."
fi
# Check Python version
echo "Checking Python version..."
if ! command -v python3 &> /dev/null; then
echo "β Error: Python 3 is not installed"
exit 1
fi
PYTHON_VERSION=$(python3 --version | cut -d' ' -f2 | cut -d'.' -f1,2)
echo "β Found Python $PYTHON_VERSION"
# Python 3.14+ compatibility: some transitive deps (e.g. `whenever`) build a
# Rust extension via PyO3, which currently supports up to Python 3.13. On 3.14+
# that build hard-fails ("configured Python interpreter version is newer than
# PyO3's maximum supported version"). Tell those packages to skip the Rust
# extension and fall back to their (slower) pure-Python implementation so the
# install still succeeds.
PYTHON_MINOR=$(echo "$PYTHON_VERSION" | cut -d'.' -f2)
if [ "${PYTHON_MINOR:-0}" -ge 14 ]; then
echo "β Python $PYTHON_VERSION detected β newer than PyO3's max supported (3.13)."
echo " Forcing pure-Python builds for Rust-backed deps (whenever) to avoid build failures."
export WHENEVER_NO_BUILD_RUST_EXT=1
# Belt-and-suspenders: if a dep still tries to compile against the stable ABI,
# let PyO3 build forward-compatibly instead of erroring out.
export PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1
fi
# Create virtual environment
echo ""
echo "Creating virtual environment..."
if [ -d ".venv" ]; then
echo "β Virtual environment already exists. Removing old one..."
rm -rf .venv
fi
python3 -m venv .venv
echo "β Virtual environment created"
# Activate virtual environment
echo ""
echo "Activating virtual environment..."
source .venv/bin/activate
echo "β Virtual environment activated"
# Upgrade pip
echo ""
echo "Upgrading pip..."
python -m pip install --upgrade pip
echo "β pip upgraded"
# Install dependencies
echo ""
echo "Installing dependencies (this may take a few minutes)..."
# Use CPU-only requirements if available, otherwise use full requirements
if [ -f "requirements-cpu.txt" ]; then
echo "Using CPU-only requirements (no GPU needed)..."
pip install -r requirements-cpu.txt
else
pip install -r requirements.txt
fi
echo "β Dependencies installed"
# Install the local workspace libraries (packages/*) as editable, top-level
# importable modules. requirements.txt only pins third-party deps; the API
# entrypoint imports agents/ingestion/config/llm/etc. which now live under
# packages/* (there is no top-level agents/ tree anymore), so without this step
# `python main.py serve` fails with `ModuleNotFoundError: No module named
# 'agents'`. --no-deps keeps the dependency closure exactly as requirements.txt
# pins it (these packages' own third-party deps are already installed above).
# This is the full runtime set the Dockerfile installs (eager + lazy imports).
echo ""
echo "Installing local workspace packages (editable)..."
pip install --no-deps \
-e packages/core -e packages/core-lib -e packages/datamodels \
-e packages/agents -e packages/scrapers -e packages/ingestion \
-e packages/llm -e packages/accessibility -e packages/hosting
echo "β Workspace packages installed"
# Infrastructure CLIs (Azure CLI + Terraform) for the infra/azure subscriptions
# Terraform. Opt-in β most contributors don't touch it β enable with:
# INSTALL_INFRA_TOOLS=1 ./install.sh
# Prefers the OS package manager; falls back to a rootless install into .venv
# (azure-cli via pip, terraform binary into .venv/bin) when sudo isn't available.
TERRAFORM_VERSION="${TERRAFORM_VERSION:-1.9.8}"
# Symlink a tool installed inside .venv into ~/.local/bin so it's on PATH without
# activating the venv (the rootless fallback otherwise hides az/terraform). venv
# console scripts use an absolute shebang, so the symlink works from any shell.
link_into_local_bin() {
local name="$1" target="$2"
[ -e "$target" ] || return 0
mkdir -p "$HOME/.local/bin"
ln -sf "$(pwd)/$target" "$HOME/.local/bin/$name"
case ":$PATH:" in
*":$HOME/.local/bin:"*) echo "β Linked $name into ~/.local/bin (on PATH)" ;;
*) echo "β Linked $name into ~/.local/bin β add it to PATH: export PATH=\"\$HOME/.local/bin:\$PATH\"" ;;
esac
}
install_azure_cli() {
if command -v az &> /dev/null; then
echo "β Azure CLI already installed: $(az version --query '"azure-cli"' -o tsv 2>/dev/null)"
return 0
fi
echo "Installing Azure CLI..."
if command -v brew &> /dev/null; then
brew install azure-cli || true
elif command -v apt-get &> /dev/null; then
curl -sL https://aka.ms/InstallAzureCLIDeb | run_root bash || true
elif command -v dnf &> /dev/null; then
run_root rpm --import https://packages.microsoft.com/keys/microsoft.asc || true
run_root dnf install -y azure-cli || true
elif command -v zypper &> /dev/null; then
run_root zypper install -y azure-cli || true
fi
if ! command -v az &> /dev/null; then
echo "β No system install path; installing azure-cli into .venv via pip (rootless)..."
if pip install --upgrade azure-cli; then
link_into_local_bin az ".venv/bin/az"
else
echo "β Could not install Azure CLI. Install manually: https://learn.microsoft.com/cli/azure/install-azure-cli"
fi
fi
}
install_terraform() {
if command -v terraform &> /dev/null; then
echo "β Terraform already installed: $(terraform version | head -n 1)"
return 0
fi
echo "Installing Terraform ${TERRAFORM_VERSION}..."
if command -v brew &> /dev/null; then
brew tap hashicorp/tap 2>/dev/null && brew install hashicorp/tap/terraform || true
fi
if ! command -v terraform &> /dev/null; then
# Rootless: drop the official binary into .venv/bin (on PATH once activated).
local os arch url tmp
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m)"
case "$arch" in x86_64) arch=amd64 ;; aarch64 | arm64) arch=arm64 ;; esac
url="https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_${os}_${arch}.zip"
tmp="$(mktemp -d)"
if curl -fsSL "$url" -o "$tmp/terraform.zip"; then
# Use the venv's python (active here) to unzip β no `unzip` dependency.
python - "$tmp/terraform.zip" <<'PY' && echo "β Terraform installed to .venv/bin"
import os, stat, sys, zipfile
zipfile.ZipFile(sys.argv[1]).extractall(".venv/bin")
p = ".venv/bin/terraform"
os.chmod(p, os.stat(p).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
PY
link_into_local_bin terraform ".venv/bin/terraform"
else
echo "β Could not download Terraform. Install manually: https://developer.hashicorp.com/terraform/install"
fi
rm -rf "$tmp"
fi
}
if [ "${INSTALL_INFRA_TOOLS:-0}" = "1" ]; then
echo ""
echo "Installing infrastructure CLIs (Azure CLI + Terraform) [INSTALL_INFRA_TOOLS=1]..."
install_azure_cli
install_terraform
fi
# Create .env file if it doesn't exist
echo ""
if [ ! -f ".env" ]; then
echo "Creating .env file from template..."
cp .env.example .env
echo "β .env file created"
echo ""
echo "β IMPORTANT: Please edit .env and add your API keys:"
echo " - OPENAI_API_KEY"
echo " - DATABRICKS_HOST"
echo " - DATABRICKS_TOKEN"
else
echo "β .env file already exists"
fi
# Create logs directory
echo ""
echo "Creating logs directory..."
mkdir -p logs
echo "β logs directory created"
# Installation complete
echo ""
echo "=================================================="
echo "β
Installation Complete!"
echo "=================================================="
echo ""
echo "To activate the virtual environment, run:"
echo " source .venv/bin/activate"
echo ""
echo "Then you can use the CLI:"
echo " python main.py --help"
echo " python main.py serve"
echo ""
echo "Or run the example workflow:"
echo " python examples/example_workflow.py"
echo ""
echo "Don't forget to configure your .env file with API keys!"
echo ""
if [ "${INSTALL_INFRA_TOOLS:-0}" != "1" ]; then
echo "Working on infra/azure (Azure subscriptions)? Re-run with the infra CLIs:"
echo " INSTALL_INFRA_TOOLS=1 ./install.sh # installs Azure CLI + Terraform"
echo ""
fi
|