//
··
1#!/usr/bin/env bash
2# Extract the Canonical Intermediate Representation (CIR) from the
3# build artifacts produced by scripts/build.sh.
4#
5# Uses the rrxiv CLI from random-walks/rrxiv-python (`pip install rrxiv`
6# or `uv tool install rrxiv` once published; for now: clone alongside
7# this repo and `uv run rrxiv parse` from there).
8#
9# Output: build/main.cir.json
10set -euo pipefail
11
12SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
14TEX="$ROOT/paper/main.tex"
15AUX="$ROOT/build/main.rrxiv.aux"
16META="$ROOT/rrxiv-meta.json"
17OUT="$ROOT/build/main.cir.json"
18
19if [[ ! -f "$AUX" ]]; then
20 echo "ERROR: $AUX missing — run scripts/build.sh first." >&2
21 exit 1
22fi
23
24# Resolve the rrxiv CLI. Order:
25# 1. $RRXIV_PYTHON_REPO env var (CI sets this; respects any in-repo
26# override).
27# 2. `rrxiv` on PATH (once published to PyPI, or a global uv install).
28# 3. Sibling checkout — the local-dev convention where paper repos sit
29# next to rrxiv-python under one workspace dir.
30# `rrxiv.cli.app` eagerly imports every sub-command at module load
31# (annotation_post, seed, server-side projection helpers, ...), which
32# pulls in cryptography + http-message-signatures + fastapi. We pass
33# --all-extras so the CLI imports cleanly even though `rrxiv parse`
34# doesn't actually need most of that machinery. uv caches the install.
35RRXIV_CMD=""
36if [[ -n "${RRXIV_PYTHON_REPO:-}" && -f "$RRXIV_PYTHON_REPO/pyproject.toml" ]]; then
37 RRXIV_CMD="uv run --project $RRXIV_PYTHON_REPO --all-extras rrxiv"
38elif command -v rrxiv >/dev/null 2>&1; then
39 RRXIV_CMD="rrxiv"
40elif command -v uv >/dev/null 2>&1; then
41 for sibling in \
42 "$ROOT/../rrxiv-python" \
43 "$ROOT/../../rrxiv-python" \
44 "$ROOT/../../repos/rrxiv-python" \
45 "$ROOT/deps/rrxiv-python"; do
46 if [[ -f "$sibling/pyproject.toml" ]]; then
47 RRXIV_CMD="uv run --project $sibling --all-extras rrxiv"
48 break
49 fi
50 done
51fi
52
53if [[ -z "$RRXIV_CMD" ]]; then
54 echo "ERROR: rrxiv CLI not found." >&2
55 echo "Options:" >&2
56 echo " 1. Install: pip install rrxiv (once published)" >&2
57 echo " 2. Clone https://github.com/random-walks/rrxiv-python alongside this repo." >&2
58 exit 127
59fi
60
61# `rrxiv parse` reads the .tex + the sidecar .rrxiv.aux and emits a
62# CIR JSON document. The standalone rrxiv-meta.json is human-facing
63# metadata (slug, license, topics) — the v0.x parser pulls all of it
64# out of the .tex via the rrxiv.cls macros + the sidecar, so $META is
65# not currently passed to the CLI. Keep $META resolved above so future
66# tooling can wire it back in.
67$RRXIV_CMD parse "$TEX" \
68 --sidecar "$AUX" \
69 --output "$OUT"
70
71echo "OK $OUT"
72
