Skip to content

Arquitectura RAM-first y migración a Poetry#2

Open
runesc wants to merge 3 commits intoEdybrown:mainfrom
runesc:main
Open

Arquitectura RAM-first y migración a Poetry#2
runesc wants to merge 3 commits intoEdybrown:mainfrom
runesc:main

Conversation

@runesc
Copy link

@runesc runesc commented Dec 21, 2025

Este es un refactor arquitectónico que introduce generación de HTML/CSS en memoria,
permitiendo integración seamless con aplicaciones downstream (PPG, frameworks
web) sin requerir I/O en disco por defecto.

Cambios Principales

1. Sistema de Construcción

  • Migración setuptools → Poetry para mejor gestión de dependencias
  • Configuración moderna con poetry-core como build backend
  • Soporte explícito para Python >=3.8

2. Arquitectura de Memoria

create_document() ahora soporta 3 modos de salida:

  • "raw": Retorna dict con HTML y CSS en memoria
  • "file": Escribe archivos en disco (comportamiento original)
  • "both": Retorna contenido + escribe en disco

bundle_document() (NUEVO)

  • Genera HTML autocontenido con CSS embebido en <style> tag
  • Disponible en memoria o disco usando (pasando "raw" o "file" en el parametro "output")

3. Mejoras de Código

helpers/fs.py (NUEVO)

  • _write_file() centraliza operaciones de escritura
  • Manejo uniforme de errores con mensajes descriptivos
  • Principio DRY: evita repetición de try/except
  • Reutilizable en múltiples módulos

style_manager.py

  • CSSProcessor (NUEVO): Lógica pura de transformación CSS

    • Sin acceso a filesystem
    • Fácil de testear
    • Reutilizable en bundlers, exportadores, previews
  • StyleManager: Adaptador de filesystem

    • Responsabilidad única: read → process → write
    • Delega lógica a CSSProcessor
    • Documentación exhaustiva

html_doc.py

  • Refactor completo del método create_document()

    • Separación clara: generación en RAM vs I/O en disco
    • Type hints con Literal para parámetros
    • Docstrings detallados explicando cada modo
  • Nuevo método bundle_document()

    • Inyecta CSS en <style> tag
    • Utiliza lxml para manipulación DOM segura
    • Retorna HTML autocontenido

4. Dependencias

  • Agregada: lxml>=6.0.2,<7.0.0
    • Manipulación segura de DOM
    • Parser HTML robusto
    • Salida formateada

Major refactor introducing in-memory HTML/CSS generation for seamless
integration with downstream applications (PPG, web frameworks) without
requiring disk I/O by default.

Architecture Changes:
- Migrate build system: setuptools → poetry (modern dependency management)
- create_document() now supports output modes: "file", "raw", "both"
- bundle_document() generates self-contained HTML with embedded CSS
- CSSProcessor extracted for pure CSS transformation (testable, reusable)
- _write_file() helper centralizes file operations (DRY principle)

Features:
- Generate HTML/CSS for in-memory use without disk I/O
- Return content ready for integration with frameworks (PPG, Flask, FastAPI, etc)
- Optional disk export ("file" mode) when needed
- Optional memory + disk export ("both" mode)
- Self-contained bundled HTML generation (embedded CSS)

Code Quality:
- Better separation of concerns (Single Responsibility Principle)
- Pure functions enable easier unit testing
- Centralized file error handling via _write_file()
- Improved documentation (comprehensive docstrings)
- Explicit type hints with Literal types for output modes

Dependencies:
- Add lxml>=6.0.2,<7.0.0 for DOM manipulation
- Requires Python >=3.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant