Implementation:AUTOMATIC1111 Stable diffusion webui Config States
| Knowledge Sources | |
|---|---|
| Domains | Configuration, Version_Control |
| Last Updated | 2025-05-15 00:00 GMT |
Overview
Supports saving and restoring the WebUI and its extensions to a known working set of git commits, enabling reproducible environment snapshots.
Description
The Config States module provides a mechanism to snapshot the current state of the WebUI repository and all installed extensions, storing the git commit hashes, branch names, remote URLs, and commit dates into JSON configuration files. These snapshots can later be listed and used to restore the entire environment to a previous known-good state. The list_config_states function scans the config states directory for saved snapshots and returns them sorted by creation time. get_config captures the current state by reading git information from both the main WebUI repository and each extension. The restoration functions (restore_webui_config and restore_extension_config) perform git fetch --all and git reset --hard to roll back to the saved commits, and update the extension enabled/disabled status accordingly.
Usage
Use this module when you need to create a reproducible snapshot of the entire WebUI environment before making changes, or when you need to restore a previously saved configuration after an update breaks functionality.
Code Reference
Source Location
- Repository: AUTOMATIC1111_Stable_diffusion_webui
- File: modules/config_states.py
- Lines: 1-199
Signature
def list_config_states() -> dict
def get_webui_config() -> dict
def get_extension_config() -> dict
def get_config() -> dict
def restore_webui_config(config: dict) -> None
def restore_extension_config(config: dict) -> None
Import
from modules import config_states
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config | dict | Yes | A previously saved configuration state dictionary containing "webui" and "extensions" keys (used by restore functions) |
Outputs
| Name | Type | Description |
|---|---|---|
| config_states | dict | A dictionary mapping display names (e.g., "Config: 2024-01-15 12:00:00") to their full state dictionaries |
| config | dict | A dictionary containing "created_at", "webui", and "extensions" snapshot data |
Usage Examples
from modules import config_states
# Save the current state
current_config = config_states.get_config()
# List all saved configuration states
all_states = config_states.list_config_states()
for name, state in all_states.items():
print(f"Snapshot: {name}")
# Restore a previously saved state
config_states.restore_webui_config(current_config)
config_states.restore_extension_config(current_config)