Implementation:AUTOMATIC1111 Stable diffusion webui Extension Manager
| Knowledge Sources | |
|---|---|
| Domains | Extension_System, Plugin_Architecture |
| Last Updated | 2025-05-15 00:00 GMT |
Overview
Manages the discovery, loading, metadata parsing, version tracking, and update lifecycle of WebUI extensions from both builtin and user-installed directories.
Description
The Extension Manager module is the core of the WebUI's plugin architecture. It defines the Extension class representing a single extension with properties for name, path, enabled status, git remote, commit hash, branch, and version. The ExtensionMetadata class parses metadata.ini files from extension directories to extract canonical names, dependency requirements, and callback ordering instructions. The module maintains global registries (extensions, extension_paths, loaded_extensions) and provides the list_extensions function to scan both the builtin and user extensions directories, instantiate Extension objects, resolve dependencies, and check for duplicate canonical names. Extensions support git-based operations including reading repository info (with caching), checking for updates via fetch --dry-run, and performing fetch_and_reset_hard for updates. The active() function returns the list of currently enabled extensions, respecting command-line flags and settings to disable all or extra extensions. The find_extension utility resolves a filename path back to its owning extension.
Usage
Use this module to discover, load, manage, update, and query the status of WebUI extensions. It is invoked during application startup to populate the extensions list and is used by the Extensions tab in the UI for checking updates and managing enabled/disabled states.
Code Reference
Source Location
- Repository: AUTOMATIC1111_Stable_diffusion_webui
- File: modules/extensions.py
- Lines: 1-299
Signature
def active() -> list[Extension]
def list_extensions() -> None
def find_extension(filename: str) -> Extension | None
class ExtensionMetadata:
def __init__(self, path: str, canonical_name: str) -> None
def get_script_requirements(self, field: str, section: str, extra_section=None) -> list
def parse_list(self, text: str) -> list
def list_callback_order_instructions(self) -> Generator[CallbackOrderInfo]
class Extension:
def __init__(self, name: str, path: str, enabled=True, is_builtin=False, metadata=None) -> None
def to_dict(self) -> dict
def from_dict(self, d: dict) -> None
def read_info_from_repo(self) -> None
def do_read_info_from_repo(self) -> None
def list_files(self, subdir: str, extension: str) -> list
def check_updates(self) -> None
def fetch_and_reset_hard(self, commit=None) -> None
Import
from modules import extensions
from modules.extensions import Extension
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| name | str | Yes | The directory name of the extension |
| path | str | Yes | Filesystem path to the extension directory |
| enabled | bool | No | Whether the extension is active (default True) |
| is_builtin | bool | No | Whether the extension resides in the builtin directory |
| filename | str | Yes | Absolute path to a file, used by find_extension to locate its parent extension |
Outputs
| Name | Type | Description |
|---|---|---|
| extensions | list[Extension] | Global list of all discovered Extension objects |
| active_extensions | list[Extension] | Filtered list of currently enabled extensions |
| extension | Extension or None | The extension that owns a given file path, or None |
Usage Examples
from modules import extensions
# List and load all extensions
extensions.list_extensions()
# Get only active extensions
for ext in extensions.active():
print(f"{ext.name} (v{ext.version}) - {ext.status}")
# Check for updates on a specific extension
ext = extensions.extensions[0]
ext.read_info_from_repo()
ext.check_updates()
if ext.can_update:
ext.fetch_and_reset_hard()
# Find which extension owns a script file
owning_ext = extensions.find_extension("/path/to/extensions/my_ext/scripts/main.py")