feat: funciones Bash — install_nbconvert, notebook_to_pdf, export_analysis_pdfs
Infra: install_nbconvert (instala nbconvert+deps), notebook_to_pdf (convierte .ipynb a PDF). Pipeline: export_analysis_pdfs (exporta todos los notebooks de analysis/ a PDF). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
---
|
||||
name: export_analysis_pdfs
|
||||
kind: pipeline
|
||||
lang: bash
|
||||
domain: pipelines
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "export_analysis_pdfs(nombre: string, [pattern: string]) -> void"
|
||||
description: "Exporta todos los notebooks de un analisis Jupyter a PDF. Instala nbconvert y playwright automaticamente si no estan presentes."
|
||||
tags: [pipeline, jupyter, pdf, export, nbconvert, launcher]
|
||||
uses_functions:
|
||||
- assert_command_exists_bash_shell
|
||||
- install_nbconvert_bash_infra
|
||||
- notebook_to_pdf_bash_infra
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/pipelines/export_analysis_pdfs.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Exportar todos los notebooks de un analisis
|
||||
./export_analysis_pdfs.sh finanzas
|
||||
|
||||
# Con pattern especifico
|
||||
./export_analysis_pdfs.sh ml "notebooks/01_*.ipynb"
|
||||
|
||||
# Via fn run
|
||||
fn run export_analysis_pdfs finanzas
|
||||
fn run export_analysis_pdfs ml "notebooks/01_*.ipynb"
|
||||
```
|
||||
|
||||
## Flujo
|
||||
|
||||
1. `assert_command_exists uv` — verifica que uv esta disponible
|
||||
2. `install_nbconvert` — instala nbconvert y playwright con chromium (idempotente)
|
||||
3. `notebook_to_pdf` — convierte notebooks al patron indicado a PDF en `notebooks/pdf/`
|
||||
|
||||
## Notas
|
||||
|
||||
El analysis debe existir previamente en `analysis/{nombre}/` con un venv inicializado. Los PDFs se generan en `analysis/{nombre}/notebooks/pdf/` por defecto. El pipeline usa `set -euo pipefail` — cualquier fallo detiene la ejecucion.
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
# export_analysis_pdfs
|
||||
# ---------------------
|
||||
# Pipeline que exporta todos los notebooks de un analisis a PDF.
|
||||
# Compone: assert_command_exists + install_nbconvert + notebook_to_pdf
|
||||
#
|
||||
# USO:
|
||||
# ./export_analysis_pdfs.sh <nombre_analysis> [pattern]
|
||||
#
|
||||
# EJEMPLOS:
|
||||
# ./export_analysis_pdfs.sh finanzas
|
||||
# ./export_analysis_pdfs.sh ml "notebooks/01_*.ipynb"
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REGISTRY_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
|
||||
|
||||
# Source funciones atomicas
|
||||
source "$REGISTRY_ROOT/bash/functions/shell/assert_command_exists.sh"
|
||||
source "$REGISTRY_ROOT/bash/functions/infra/install_nbconvert.sh"
|
||||
source "$REGISTRY_ROOT/bash/functions/infra/notebook_to_pdf.sh"
|
||||
|
||||
# ── Argumentos ──────────────────────────────────────────────
|
||||
|
||||
NOMBRE="${1:-}"
|
||||
if [ -z "$NOMBRE" ]; then
|
||||
echo "Uso: $0 <nombre_analysis> [pattern]" >&2
|
||||
echo " Ejemplo: $0 finanzas" >&2
|
||||
echo " Ejemplo: $0 ml 'notebooks/01_*.ipynb'" >&2
|
||||
exit 1
|
||||
fi
|
||||
shift
|
||||
PATTERN="${1:-notebooks/*.ipynb}"
|
||||
|
||||
ANALYSIS_DIR="${REGISTRY_ROOT}/analysis/${NOMBRE}"
|
||||
|
||||
# Verificar que el analysis existe
|
||||
if [ ! -d "$ANALYSIS_DIR" ]; then
|
||||
echo "Error: analysis '${NOMBRE}' no existe en ${ANALYSIS_DIR}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "════════════════════════════════════════════════════════════"
|
||||
echo " EXPORT ANALYSIS PDFs: ${NOMBRE}"
|
||||
echo " Directorio: ${ANALYSIS_DIR}"
|
||||
echo "════════════════════════════════════════════════════════════"
|
||||
echo ""
|
||||
|
||||
# ── 1. Verificar herramientas ───────────────────────────────
|
||||
|
||||
echo "[1/3] Verificando herramientas..."
|
||||
assert_command_exists uv
|
||||
echo " OK"
|
||||
|
||||
# ── 2. Instalar nbconvert + playwright ──────────────────────
|
||||
|
||||
echo "[2/3] Instalando dependencias de exportacion..."
|
||||
install_nbconvert "$ANALYSIS_DIR"
|
||||
echo " OK"
|
||||
|
||||
# ── 3. Convertir notebooks a PDF ────────────────────────────
|
||||
|
||||
echo "[3/3] Convirtiendo notebooks a PDF..."
|
||||
notebook_to_pdf "$ANALYSIS_DIR" "$PATTERN"
|
||||
|
||||
# ── Resumen ─────────────────────────────────────────────────
|
||||
|
||||
echo ""
|
||||
echo "════════════════════════════════════════════════════════════"
|
||||
echo " EXPORT COMPLETADO"
|
||||
echo "════════════════════════════════════════════════════════════"
|
||||
Reference in New Issue
Block a user