### Setup development environment Source: https://github.com/mkdocstrings/griffe2md/blob/main/CONTRIBUTING.md Initial commands to clone the repository and install dependencies. ```bash cd griffe2md make setup ``` -------------------------------- ### Full Configuration Example Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Provides a comprehensive example of griffe2md configuration using ConfigDict, covering docstring parsing, display options, signature settings, member filtering, and more. All available options are shown with their possible values. ```python from griffe2md import ConfigDict, default_config # Full configuration example with all available options config: ConfigDict = { # Docstring parsing "docstring_style": "google", # "google", "numpy", "sphinx", "auto", or None "docstring_options": {"ignore_init_summary": True}, "docstring_section_style": "list", # "list" or "table" # Display options "heading_level": 2, "line_length": 80, "show_root_heading": True, "show_root_full_path": True, "show_root_members_full_path": True, "show_object_full_path": True, # Signature options "show_signature": True, "show_signature_annotations": False, "separate_signature": True, "signature_crossrefs": False, "annotations_path": "brief", # "brief", "source", or "full" # Member filtering "members": None, # True, False, None, or list of names "members_order": "alphabetical", # "alphabetical" or "source" "inherited_members": True, # True, False, or list of names "filters": ["!^_"], # Patterns; prefix with ! to exclude # Category grouping "group_by_category": False, "show_category_heading": False, # Docstring sections to display "show_docstring_description": True, "show_docstring_parameters": True, "show_docstring_returns": True, "show_docstring_raises": True, "show_docstring_examples": True, "show_docstring_attributes": True, "show_docstring_classes": True, "show_docstring_functions": True, "show_docstring_modules": True, "show_docstring_other_parameters": True, "show_docstring_receives": True, "show_docstring_warns": True, "show_docstring_yields": True, # Class options "show_bases": True, "merge_init_into_class": True, # Module options "show_submodules": True, "show_if_no_docstring": True, # Summaries "summary": True, # True, False, or dict with keys: attributes, functions, classes, modules # Loading options "search_paths": [], "preload_modules": None, "load_external_modules": False, "allow_inspection": True, "force_inspection": False, "extensions": [], # Griffe extensions to load # Output formatting "mdformat_extensions": [], # e.g., ["tables"] } # View all default values for key, value in default_config.items(): print(f"{key}: {value}") ``` -------------------------------- ### Install uv Source: https://github.com/mkdocstrings/griffe2md/blob/main/CONTRIBUTING.md Fallback installation command for the uv package manager. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` -------------------------------- ### Render object documentation Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Examples for rendering specific functions and attributes with custom configurations. ```python my_func = module["utils"]["process_data"] func_docs = render_object_docs( my_func, config={ "show_signature_annotations": True, "separate_signature": True, }, ) # Render an attribute with table formatting attr = griffe.Attribute( name="CONFIG_TIMEOUT", parent=None, value="30", docstring=griffe.Docstring("Default timeout in seconds."), ) attr_docs = render_object_docs( attr, config={"mdformat_extensions": ["tables"]}, format_md=True, ) ``` -------------------------------- ### Install griffe2md Source: https://github.com/mkdocstrings/griffe2md/blob/main/README.md Installation commands for the griffe2md tool using standard pip or the uv package manager. ```bash pip install griffe2md ``` ```bash uv tool install griffe2md ``` -------------------------------- ### Configure griffe2md Source: https://github.com/mkdocstrings/griffe2md/blob/main/README.md Configuration examples for griffe2md using standalone TOML files or the pyproject.toml project file. ```toml docstring_style = "sphinx" ``` ```toml [tool.griffe2md] docstring_style = "sphinx" ``` -------------------------------- ### Generate API Documentation Source: https://github.com/mkdocstrings/griffe2md/blob/main/README.md Basic command-line usage to generate documentation for a package or directory. ```bash griffe2md markdown griffe2md path/to/my/src/package ``` -------------------------------- ### Manual Member Ordering Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Demonstrates how to manually order members using an explicit list, overriding default ordering. ```python manual_order = do_order_members( members, Order.alphabetical, # Ignored when members_list is provided members_list=["Config", "main", "utils", "helpers"], ) print([m.name for m in manual_order]) # Only these members, in this order ``` -------------------------------- ### Write Documentation to File Source: https://github.com/mkdocstrings/griffe2md/blob/main/README.md Use the output option to save generated documentation to a specific file. ```bash griffe2md markdown -o markdown.md ``` -------------------------------- ### Load configuration Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Utility to locate and load project configuration files, merging them with defaults. ```python from griffe2md import load_config, CONFIG_FILE_PATHS, default_config # Show where config is searched print("Config file paths:", CONFIG_FILE_PATHS) # Output: (PosixPath('.config/griffe2md.toml'), PosixPath('config/griffe2md.toml'), PosixPath('pyproject.toml')) # Load configuration (returns None if no config file found) config = load_config() if config is None: print("No config file found, using defaults") config = default_config.copy() else: # Merge with defaults merged_config = {**default_config, **config} print(f"Loaded config with docstring_style: {merged_config.get('docstring_style')}") # View default configuration values print("Default config keys:", list(default_config.keys())) # Output includes: docstring_style, heading_level, line_length, filters, etc. ``` -------------------------------- ### Write package documentation Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Convenience function to render and output package documentation to various destinations. ```python from griffe2md import write_package_docs # Write to stdout write_package_docs("mypackage") # Write to a file write_package_docs("mypackage", output="docs/api.md") # Write with configuration and formatting write_package_docs( "mypackage", config={ "docstring_style": "google", "show_signature_annotations": True, "filters": ["!^_"], }, output="api-reference.md", format_md=True, ) # Write to a file object import sys write_package_docs("mypackage", output=sys.stderr) with open("output.md", "w") as f: write_package_docs("mypackage", output=f) ``` -------------------------------- ### Programmatic Rendering with render_package_docs Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Use `render_package_docs` for programmatic API documentation generation. It accepts a package name or path and an optional configuration dictionary. The `format_md` argument applies `mdformat`. ```python from griffe2md import render_package_docs, ConfigDict # Basic usage - render docs for an installed package markdown = render_package_docs("requests") print(markdown) # Render docs for a local package with custom configuration config: ConfigDict = { "docstring_style": "numpy", "show_signature_annotations": True, "heading_level": 1, "line_length": 100, "filters": ["!^_", "!^test"], # Exclude private and test members "members_order": "source", # Order by source file position "summary": { "attributes": True, "functions": True, "classes": True, "modules": False, }, } markdown = render_package_docs( "mypackage", config=config, format_md=True, # Apply mdformat ) # Write to file with open("api.md", "w") as f: f.write(markdown) ``` -------------------------------- ### Prepare environment and context Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Low-level functions for customizing the Jinja2 rendering environment and preparing the data context. ```python from griffe2md import prepare_env, prepare_context import griffe # Load a module with Griffe loader = griffe.GriffeLoader(docstring_parser=griffe.Parser("google")) module = loader.load("mypackage") # Prepare the Jinja2 environment with custom filters env = prepare_env() # Add a custom filter env.filters["uppercase"] = lambda x: x.upper() # Prepare context for rendering context = prepare_context( module, config={ "heading_level": 1, "show_root_heading": True, "show_signature_annotations": True, }, ) # Render using the template directly template = env.get_template("module.md.jinja") markdown = template.render(**context) # Context contains the object and configuration print(context.keys()) # dict_keys(['config', 'module', 'heading_level', 'root']) ``` -------------------------------- ### Programmatic Rendering with render_object_docs Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Use `render_object_docs` to generate documentation for specific Griffe objects (modules, classes, functions, attributes). This provides fine-grained control over documentation output. It accepts a Griffe object and an optional configuration. ```python import griffe from griffe2md import render_object_docs, ConfigDict # Load a package with Griffe loader = griffe.GriffeLoader( docstring_parser=griffe.Parser("google"), docstring_options={"ignore_init_summary": True}, ) module = loader.load("mypackage") loader.resolve_aliases() # Render the entire module markdown = render_object_docs(module, format_md=True) # Render a specific class my_class = module["MyClass"] class_docs = render_object_docs( my_class, config={ "heading_level": 2, "show_bases": True, "inherited_members": ["__init__", "from_dict"], }, ) ``` -------------------------------- ### griffe2md Configuration (TOML) Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Configure griffe2md's output using TOML files. Settings can be placed in `.config/griffe2md.toml`, `config/griffe2md.toml`, or the `[tool.griffe2md]` section of `pyproject.toml`. ```toml # griffe2md.toml or .config/griffe2md.toml docstring_style = "google" # Options: "google", "numpy", "sphinx", "auto", or null docstring_section_style = "list" # Options: "list" or "table" heading_level = 2 # Initial heading level line_length = 80 # Max line length for signatures members_order = "alphabetical" # Options: "alphabetical" or "source" show_root_heading = true show_signature = true show_signature_annotations = false separate_signature = true # Put signature in code block below heading merge_init_into_class = true # Merge __init__ into class docstring group_by_category = false # Group by attributes/classes/functions/modules show_bases = true # Show base classes show_submodules = true # Render submodules recursively inherited_members = true # Include inherited members filters = ["!^_"] # Exclude private members (starting with _) annotations_path = "brief" # Options: "brief", "source", "full" summary = true # Render summaries of modules/classes/functions mdformat_extensions = ["tables"] # mdformat plugins to enable ``` ```toml # pyproject.toml [tool.griffe2md] docstring_style = "sphinx" show_signature_annotations = true line_length = 100 filters = ["!^_", "!^test_"] # Exclude private and test functions ``` -------------------------------- ### load_config Function Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Loads configuration from the project's configuration files, searching standard paths. ```APIDOC ## load_config() ### Description Loads configuration from the project's configuration files. Automatically searches standard paths for griffe2md configuration. ### Response - **config** (dict/None) - Returns the loaded configuration dictionary or None if no file is found. ``` -------------------------------- ### write_package_docs Function Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Renders package documentation and writes it directly to a file or stdout. ```APIDOC ## write_package_docs(package_name, output=None, config=None, format_md=False) ### Description Convenience function that renders package documentation and writes it directly to a file or stdout. ### Parameters - **package_name** (str) - Required - The name of the package to document. - **output** (str/file-like) - Optional - The destination file path or file object to write the output to. Defaults to stdout. - **config** (dict) - Optional - Configuration dictionary for rendering. - **format_md** (bool) - Optional - Whether to format the output as Markdown. ``` -------------------------------- ### Generate Docs via CLI Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Use the griffe2md CLI to generate Markdown documentation for Python packages. Specify the package path or name, and optionally direct output to a file or enable formatting. ```bash griffe2md markdown ``` ```bash griffe2md path/to/my/src/package ``` ```bash griffe2md markdown -o api-docs.md ``` ```bash griffe2md markdown -f -o api-docs.md ``` ```bash griffe2md markdown --mdformat-extensions tables -o api-docs.md ``` ```bash griffe2md --debug-info ``` ```bash griffe2md --version ``` -------------------------------- ### Create fixup commit Source: https://github.com/mkdocstrings/griffe2md/blob/main/CONTRIBUTING.md Command to create a fixup commit for a specific SHA. ```bash # SHA is the SHA of the commit you want to fix git commit --fixup=SHA ``` -------------------------------- ### render_package_docs Function Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Renders complete API documentation for a Python package programmatically. ```APIDOC ## render_package_docs(package_name, config=None, format_md=False) ### Description Renders complete API documentation for a Python package. This is the main entry point for programmatic usage when you have a package name or path. ### Parameters #### Arguments - **package_name** (str) - Required - The name or path of the package to document. - **config** (ConfigDict) - Optional - A dictionary containing configuration options for the rendering process. - **format_md** (bool) - Optional - Whether to apply mdformat to the output. ### Response - **markdown** (str) - The generated Markdown documentation string. ``` -------------------------------- ### render_object_docs Function Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Renders documentation for a specific Griffe object (module, class, function, or attribute). ```APIDOC ## render_object_docs(obj, config=None, format_md=False) ### Description Renders documentation for a specific Griffe object. Use this when you need fine-grained control over what gets documented. ### Parameters #### Arguments - **obj** (griffe.Object) - Required - The Griffe object (module, class, function, or attribute) to document. - **config** (ConfigDict) - Optional - A dictionary containing configuration options for the rendering process. - **format_md** (bool) - Optional - Whether to apply mdformat to the output. ### Response - **markdown** (str) - The generated Markdown documentation string. ``` -------------------------------- ### Squash commits Source: https://github.com/mkdocstrings/griffe2md/blob/main/CONTRIBUTING.md Interactive rebase command to squash commits before merging. ```bash git rebase -i --autosquash main ``` -------------------------------- ### Order members Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Sort module members alphabetically or by source code position. ```python import griffe from griffe2md import do_order_members, Order # Load a module loader = griffe.GriffeLoader() module = loader.load("mypackage") members = list(module.members.values()) # Order alphabetically alphabetical = do_order_members(members, Order.alphabetical, members_list=None) print([m.name for m in alphabetical]) # Order by source code position by_source = do_order_members(members, Order.source, members_list=None) print([m.name for m in by_source]) ``` -------------------------------- ### do_order_members Function Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Orders a sequence of objects using alphabetical or source code order. ```APIDOC ## do_order_members(members, order, members_list=None) ### Description Orders a sequence of objects using alphabetical or source code order, with optional manual ordering via explicit member lists. ### Parameters - **members** (list) - Required - Sequence of objects to order. - **order** (Order) - Required - The ordering strategy (alphabetical or source). - **members_list** (list) - Optional - Explicit list of member names for manual ordering. ``` -------------------------------- ### Force push changes Source: https://github.com/mkdocstrings/griffe2md/blob/main/CONTRIBUTING.md Command to force push squashed commits to the remote branch. ```bash git push -f ``` -------------------------------- ### Commit message trailer format Source: https://github.com/mkdocstrings/griffe2md/blob/main/CONTRIBUTING.md Required format for adding issue or PR references to the end of a commit body. ```text Body. Issue #10: https://github.com/namespace/project/issues/10 Related to PR namespace/other-project#15: https://github.com/namespace/other-project/pull/15 ``` -------------------------------- ### Commit message format Source: https://github.com/mkdocstrings/griffe2md/blob/main/CONTRIBUTING.md Standard structure for commit messages following the Angular/Karma convention. ```text [(scope)]: Subject [Body] ``` -------------------------------- ### Filter objects Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Filter module members based on regex patterns, explicit lists, or docstring presence. ```python import griffe from griffe2md import do_filter_objects import re # Load a module loader = griffe.GriffeLoader() module = loader.load("mypackage") # Get all members as a dictionary members = module.members # Filter to exclude private members (starting with _) filters = [ (re.compile(r"^_"), True), # Pattern, exclude=True ] public_members = do_filter_objects( members, filters=filters, keep_no_docstrings=False, # Only keep documented members ) # Filter with explicit member list specific_members = do_filter_objects( members, members_list=["MyClass", "my_function", "CONSTANT"], ) # Include inherited members all_members = do_filter_objects( members, inherited_members=True, filters=[(re.compile(r"^_"), True)], ) # Include only specific inherited members selective_inherited = do_filter_objects( members, inherited_members=["__init__", "__repr__", "from_dict"], ) ``` -------------------------------- ### do_filter_objects Function Source: https://context7.com/mkdocstrings/griffe2md/llms.txt Filters a collection of objects based on criteria like regex patterns, member lists, and docstring presence. ```APIDOC ## do_filter_objects(members, filters=None, members_list=None, keep_no_docstrings=True, inherited_members=False) ### Description Filters a collection of objects based on various criteria including regex patterns, explicit member lists, and docstring presence. ### Parameters - **members** (dict) - Required - Collection of objects to filter. - **filters** (list) - Optional - List of tuples containing regex patterns and exclusion booleans. - **members_list** (list) - Optional - Explicit list of member names to include. - **keep_no_docstrings** (bool) - Optional - Whether to keep members without docstrings. - **inherited_members** (bool/list) - Optional - Whether to include inherited members or a list of specific inherited members to include. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.