CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pydoc-markdown

Create Python API documentation in Markdown format

Pending
Overview
Eval results
Files

main-config.mddocs/

Main Configuration

The main configuration system for pydoc-markdown, providing the core orchestration class and configuration loading capabilities.

Capabilities

PydocMarkdown Class

Main configuration class that orchestrates the entire documentation generation pipeline by managing loaders, processors, and renderers.

class PydocMarkdown:
    """
    Main configuration for Pydoc-Markdown.
    
    Attributes:
        loaders: List of loader implementations that load docspec.Modules (defaults to PythonLoader)
        processors: List of processor implementations that modify docspec.Modules 
                   (defaults to FilterProcessor, SmartProcessor, CrossrefProcessor)
        renderer: Renderer for docspec.Modules (defaults to MarkdownRenderer)
        hooks: Hooks for executing commands at certain points in the pipeline
        unknown_fields: List of unknown configuration fields (filled automatically)
    """
    loaders: List[Loader]
    processors: List[Processor]
    renderer: Renderer
    hooks: Hooks
    unknown_fields: List[str]
    
    def load_config(self, arg: Union[str, dict]) -> None:
        """
        Load configuration from nested data structure or filename.
        
        Args:
            arg: Configuration dictionary or path to config file (JSON, YAML, or TOML)
                For pyproject.toml, reads from [tool.pydoc-markdown] section
        """
    
    def init(self, context: Context) -> None:
        """
        Initialize all plugins with specified context.
        
        Args:
            context: Context containing directory and other initialization data
            
        Raises:
            RuntimeError: If already initialized
        """
    
    def load_modules(self) -> List[docspec.Module]:
        """
        Load modules via the configured loaders.
        
        Returns:
            List of docspec.Module objects containing parsed API information
        """
    
    def process(self, modules: List[docspec.Module]) -> None:
        """
        Process modules via the configured processors.
        
        Args:
            modules: List of modules to process
        """
    
    def render(self, modules: List[docspec.Module], run_hooks: bool = True) -> None:
        """
        Render modules via the configured renderer.
        
        Args:
            modules: List of modules to render
            run_hooks: Whether to run pre/post render hooks
        """
    
    def build(self, site_dir: str) -> None:
        """
        Build final output (only for renderers that support building).
        
        Args:
            site_dir: Directory for build output
            
        Raises:
            NotImplementedError: If renderer doesn't support building
        """
    
    def run_hooks(self, hook_name: str) -> None:
        """
        Execute hooks by name.
        
        Args:
            hook_name: Name of hook to run ("pre-render" or "post-render")
        """

Hooks Configuration

Configuration for pre and post-render hooks that execute shell commands at specific points in the pipeline.

class Hooks:
    """
    Hook configuration for executing commands during rendering.
    
    Attributes:
        pre_render: List of shell commands to execute before rendering
        post_render: List of shell commands to execute after rendering
    """
    pre_render: List[str]
    post_render: List[str]

Usage Examples

Basic Configuration

from pydoc_markdown import PydocMarkdown
from pydoc_markdown.contrib.loaders.python import PythonLoader
from pydoc_markdown.contrib.renderers.markdown import MarkdownRenderer

# Create basic configuration
config = PydocMarkdown(
    loaders=[PythonLoader(modules=['mypackage'])],
    renderer=MarkdownRenderer(filename='docs/api.md')
)

# Generate documentation
modules = config.load_modules()
config.process(modules)
config.render(modules)

Configuration from File

from pydoc_markdown import PydocMarkdown

# Load from YAML file
config = PydocMarkdown()
config.load_config('pydoc-markdown.yml')

# Process documentation
modules = config.load_modules()
config.process(modules)
config.render(modules)

Configuration with Hooks

from pydoc_markdown import PydocMarkdown, Hooks

# Configuration with pre/post render hooks
config = PydocMarkdown(
    hooks=Hooks(
        pre_render=['echo "Starting documentation generation"'],
        post_render=['echo "Documentation complete"', 'cp -r docs/ /var/www/']
    )
)

config.load_config('pydoc-markdown.yml')
modules = config.load_modules()
config.process(modules)
config.render(modules)  # Hooks will run automatically

Manual Initialization

from pydoc_markdown import PydocMarkdown
from pydoc_markdown.interfaces import Context

config = PydocMarkdown()
config.load_config('pydoc-markdown.yml')

# Manual initialization with custom context
context = Context(directory='/path/to/project')
config.init(context)

modules = config.load_modules()
config.process(modules)
config.render(modules)

Configuration File Formats

YAML Configuration

loaders:
  - type: python
    modules: [mypackage]
    search_path: [src/]

processors:
  - type: filter
    documented_only: true
  - type: smart
  - type: crossref

renderer:
  type: mkdocs
  config_file_path: mkdocs.yml
  build_directory: site/

hooks:
  pre-render:
    - echo "Starting build"
  post-render:
    - echo "Build complete"

TOML Configuration (pyproject.toml)

[tool.pydoc-markdown]

[[tool.pydoc-markdown.loaders]]
type = "python"
modules = ["mypackage"]
search_path = ["src/"]

[[tool.pydoc-markdown.processors]]
type = "filter"
documented_only = true

[[tool.pydoc-markdown.processors]]
type = "smart"

[[tool.pydoc-markdown.processors]]
type = "crossref"

[tool.pydoc-markdown.renderer]
type = "mkdocs"
config_file_path = "mkdocs.yml"
build_directory = "site/"

Install with Tessl CLI

npx tessl i tessl/pypi-pydoc-markdown

docs

cli-interface.md

docstring-processing.md

documentation-rendering.md

index.md

main-config.md

plugin-interfaces.md

python-loading.md

utility-functions.md

tile.json