#!/usr/bin/env python3

# File: docs/conf.py
# Author: Hadi Cahyadi <cumulus13@gmail.com>
# Date: 2025-12-28
# Description: 
# License: MIT

"""Sphinx configuration file for gntplib documentation."""

import os
import sys
from datetime import datetime
# from ..__version__ import version as gntplib_version

# Add the parent directory to the path so we can import the package
sys.path.insert(0, os.path.abspath('..'))

# Import the package to get version info
import gntplib

# -- Project information -----------------------------------------------------

project = 'gntplib'
copyright = f'{datetime.now().year}, Hadi Cahyadi'
author = 'Hadi Cahyadi'

# The full version, including alpha/beta/rc tags
release = gntplib.__version__
version = '.'.join(release.split('.')[:2])  # Short X.Y version

# -- General configuration ---------------------------------------------------

def debug_setup(app):
    def show_handlers(app):
        import logging
        logger = logging.getLogger('sphinx')
        print("\n" + "="*60)
        print("DEBUG: Sphinx Logger Handlers:")
        for i, h in enumerate(logger.handlers):
            print(f"  [{i}] {h.__class__.__name__}")
            if hasattr(h, 'formatter'):
                print(f"      Formatter: {h.formatter.__class__.__name__}")
        print("="*60 + "\n")
    
    app.connect('builder-inited', show_handlers, priority=999)

# Add any Sphinx extension module names here

extensions = [
    'sphinxcolor',
    'sphinx.ext.autodoc',
    'sphinx.ext.autosummary',
    'sphinx.ext.napoleon',
    'sphinx.ext.intersphinx',
    'sphinx.ext.viewcode',
    'sphinx.ext.todo',
    'sphinx.ext.coverage',
    'sphinx.ext.githubpages',
    'sphinx_copybutton',
    'myst_parser',
]

sphinxcolor_enabled = True


# Add any paths that contain templates here
templates_path = ['_templates']

# List of patterns to exclude
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# The suffix(es) of source filenames
source_suffix = {
    '.rst': 'restructuredtext',
    '.md': 'markdown',
}

# The master toctree document
master_doc = 'index'

# The language for content autogenerated by Sphinx
language = 'en'

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages
html_theme = 'furo'
html_logo = '_static/logo.png'
html_favicon = '_static/favicon.ico'

# Theme options
html_theme_options = {
    "light_css_variables": {
        "color-brand-primary": "#336790",
        "color-brand-content": "#336790",
    },
    "dark_css_variables": {
        "color-brand-primary": "#5B9BD5",
        "color-brand-content": "#5B9BD5",
    },
    "sidebar_hide_name": False,
    "navigation_with_keys": True,
    "top_of_page_button": "edit",
    "source_repository": "https://github.com/cumulus13/gntplib",
    "source_branch": "main",
    "source_directory": "docs/",
}

# Add any paths that contain custom static files
html_static_path = ['_static']

# Custom CSS files - MINIMAL, no signature hacks
html_css_files = [
    'custom.css',  # Basic styling only
]

# NO JavaScript - let Sphinx and Furo handle everything
# html_js_files = []

# The name of the Pygments (syntax highlighting) style to use
pygments_style = 'sphinx'
pygments_dark_style = 'monokai'

# If true, the current module name will be prepended to all description
html_show_sourcelink = True

# Output file base name for HTML help builder
htmlhelp_basename = 'gntplibdoc'

# -- Options for autodoc -----------------------------------------------------

autodoc_default_options = {
    'members': True,
    'member-order': 'bysource',
    'special-members': '__init__',
    'undoc-members': True,
    'exclude-members': '__weakref__',
    'show-inheritance': True,
}

# SOLUTION FOR LONG SIGNATURES: Move type hints to description
# This is the CORRECT way recommended by Sphinx and Furo developers
autodoc_typehints = 'description'  # Put type hints in Parameters section
autodoc_typehints_description_target = 'documented'
autodoc_typehints_format = 'short'  # Use short type names

# Make signatures shorter by removing full module paths
add_module_names = False
python_use_unqualified_type_names = True

# -- Options for autosummary -------------------------------------------------

autosummary_generate = True
autosummary_imported_members = False

# -- Options for Napoleon (Google/NumPy style docstrings) -------------------

napoleon_google_docstring = True
napoleon_numpy_docstring = False
napoleon_include_init_with_doc = True
napoleon_include_private_with_doc = False
napoleon_include_special_with_doc = True
napoleon_use_admonition_for_examples = True
napoleon_use_admonition_for_notes = True
napoleon_use_admonition_for_references = False
napoleon_use_ivar = False
napoleon_use_param = True
napoleon_use_rtype = True
napoleon_type_aliases = None
napoleon_attr_annotations = True

# -- Options for intersphinx -------------------------------------------------

intersphinx_mapping = {
    'python': ('https://docs.python.org/3', None),
    'tornado': ('https://www.tornadoweb.org/en/stable/', None),
}

# -- Options for todo extension ----------------------------------------------

todo_include_todos = True

# -- Options for copybutton --------------------------------------------------

copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
copybutton_prompt_is_regexp = True
copybutton_only_copy_prompt_lines = True
copybutton_remove_prompts = True

# -- Options for MyST --------------------------------------------------------

myst_enable_extensions = [
    "colon_fence",
    "deflist",
    "substitution",
    "tasklist",
]

myst_heading_anchors = 3

# Add at end of file
# def setup(app):
#     debug_setup(app)
