# Configuration file for the Sphinx documentation builder.
import os
import sys
import subprocess
from pathlib import Path

sys.path.insert(0, os.path.abspath('..'))

# -- Run format comparison script before building docs --
def run_format_comparison():
    """Run the format comparison script to generate plots and tables."""
    print("Running format comparison benchmark...")
    script_path = os.path.join(os.path.dirname(__file__), 'format_comparison.py')
    output_dir = os.path.join(os.path.dirname(__file__), '_static/benchmark_results')
    
    # Create the output directory if it doesn't exist
    os.makedirs(output_dir, exist_ok=True)
    
    # Run the script with smaller parameters for CI builds
    try:
        subprocess.run(
            [sys.executable, script_path, '--atoms', '500', '--frames', '200', '--output', output_dir],
            check=True
        )
        print("Format comparison completed successfully.")
    except subprocess.CalledProcessError as e:
        print(f"Warning: Format comparison failed: {e}")
        print("Documentation build will continue without benchmark results.")

# Only run this if we're building the docs (not for conf.py import)
if 'READTHEDOCS' in os.environ or 'SPHINX_BUILD' in os.environ or 'sphinx-build' in sys.argv[0]:
    run_format_comparison()

# -- Project information -----------------------------------------------------
project = 'taco_format'
copyright = '2024, TACO Format Developers'
author = 'TACO Format Developers'
release = '0.1.1'

# -- General configuration ---------------------------------------------------
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.napoleon',
    'sphinx.ext.viewcode',
]

# -- Options for HTML output -------------------------------------------------
html_theme = 'sphinx_rtd_theme'

# Logo configuration
html_logo = 'TACO_orig_small.webp'
html_theme_options = {
    'logo_only': True,
    'display_version': True,
}

exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# If taco_format is built with maturin, it will be importable for autodoc.
