Darkgraylib

2.4.1 · active · verified Thu Apr 16

Darkgraylib provides common supporting code for the Python code formatting tool Darker and the linting utility Graylint. It extracts shared functionality from these two projects, which focus on code reformatting and selective linting, respectively. The current version is 2.4.1. It has a continuous release cadence, often aligning with updates to Darker and Graylint.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `darkgraylib.config.load_config` to parse a configuration file (like `pyproject.toml`) for a specific tool section. This is a core utility used by Darker and Graylint.

from darkgraylib.config import load_config
from pathlib import Path
import os

def demo_config_loading():
    # Create a dummy config file for demonstration
    config_content = """
[tool.my_tool]
setting_key = "setting_value"
    """
    dummy_config_path = Path("./dummy_pyproject.toml")
    dummy_config_path.write_text(config_content)

    print(f"Loading config from {dummy_config_path}")
    # In a real application, you'd pass a tool name like 'darker' or 'graylint'
    # The 'tool_name' argument filters the config to the relevant section.
    # For this example, we'll load directly or provide a mock context.
    # For a simple demo, we can simulate loading a specific section without full CLI parsing.
    try:
        # Directly accessing a specific section from a path
        config = load_config(
            config_path=dummy_config_path,
            tool_name='my_tool',
            verbose=False # Suppress verbose output for quickstart
        )
        print(f"Loaded config: {config}")
        print(f"Setting value: {config['setting_key']}")
    except Exception as e:
        print(f"Error loading config: {e}")
    finally:
        # Clean up the dummy file
        if dummy_config_path.exists():
            dummy_config_path.unlink()

if __name__ == "__main__":
    demo_config_loading()

view raw JSON →