Skip to content

Commit cb0fa58

Browse files
Merge pull request #1915 from Comfy-Org/feat/implement-batch-tracking-clean
[feat] Implement comprehensive batch tracking and OpenAPI-driven data models
2 parents 7e51286 + a66f86d commit cb0fa58

File tree

15 files changed

+3760
-1841
lines changed

15 files changed

+3760
-1841
lines changed

.github/workflows/ci.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, feat/*, fix/* ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
validate-openapi:
11+
name: Validate OpenAPI Specification
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Check if OpenAPI changed
17+
id: openapi-changed
18+
uses: tj-actions/changed-files@v44
19+
with:
20+
files: openapi.yaml
21+
22+
- name: Setup Node.js
23+
if: steps.openapi-changed.outputs.any_changed == 'true'
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: '18'
27+
28+
- name: Install Redoc CLI
29+
if: steps.openapi-changed.outputs.any_changed == 'true'
30+
run: |
31+
npm install -g @redocly/cli
32+
33+
- name: Validate OpenAPI specification
34+
if: steps.openapi-changed.outputs.any_changed == 'true'
35+
run: |
36+
redocly lint openapi.yaml
37+
38+
code-quality:
39+
name: Code Quality Checks
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v4
43+
with:
44+
fetch-depth: 0 # Fetch all history for proper diff
45+
46+
- name: Get changed Python files
47+
id: changed-py-files
48+
uses: tj-actions/changed-files@v44
49+
with:
50+
files: |
51+
**/*.py
52+
files_ignore: |
53+
comfyui_manager/legacy/**
54+
55+
- name: Setup Python
56+
if: steps.changed-py-files.outputs.any_changed == 'true'
57+
uses: actions/setup-python@v5
58+
with:
59+
python-version: '3.9'
60+
61+
- name: Install dependencies
62+
if: steps.changed-py-files.outputs.any_changed == 'true'
63+
run: |
64+
pip install ruff
65+
66+
- name: Run ruff linting on changed files
67+
if: steps.changed-py-files.outputs.any_changed == 'true'
68+
run: |
69+
echo "Changed files: ${{ steps.changed-py-files.outputs.all_changed_files }}"
70+
echo "${{ steps.changed-py-files.outputs.all_changed_files }}" | xargs -r ruff check

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ pip_overrides.json
1919
check2.sh
2020
/venv/
2121
build
22+
dist
2223
*.egg-info
2324
.env
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Data Models
2+
3+
This directory contains Pydantic models for ComfyUI Manager, providing type safety, validation, and serialization for the API and internal data structures.
4+
5+
## Overview
6+
7+
- `generated_models.py` - All models auto-generated from OpenAPI spec
8+
- `__init__.py` - Package exports for all models
9+
10+
**Note**: All models are now auto-generated from the OpenAPI specification. Manual model files (`task_queue.py`, `state_management.py`) have been deprecated in favor of a single source of truth.
11+
12+
## Generating Types from OpenAPI
13+
14+
The state management models are automatically generated from the OpenAPI specification using `datamodel-codegen`. This ensures type safety and consistency between the API specification and the Python code.
15+
16+
### Prerequisites
17+
18+
Install the code generator:
19+
```bash
20+
pipx install datamodel-code-generator
21+
```
22+
23+
### Generation Command
24+
25+
To regenerate all models after updating the OpenAPI spec:
26+
27+
```bash
28+
datamodel-codegen \
29+
--use-subclass-enum \
30+
--field-constraints \
31+
--strict-types bytes \
32+
--input openapi.yaml \
33+
--output comfyui_manager/data_models/generated_models.py \
34+
--output-model-type pydantic_v2.BaseModel
35+
```
36+
37+
### When to Regenerate
38+
39+
You should regenerate the models when:
40+
41+
1. **Adding new API endpoints** that return new data structures
42+
2. **Modifying existing schemas** in the OpenAPI specification
43+
3. **Adding new state management features** that require new models
44+
45+
### Important Notes
46+
47+
- **Single source of truth**: All models are now generated from `openapi.yaml`
48+
- **No manual models**: All previously manual models have been migrated to the OpenAPI spec
49+
- **OpenAPI requirements**: New schemas must be referenced in API paths to be generated by datamodel-codegen
50+
- **Validation**: Always validate the OpenAPI spec before generation:
51+
```bash
52+
python3 -c "import yaml; yaml.safe_load(open('openapi.yaml'))"
53+
```
54+
55+
### Example: Adding New State Models
56+
57+
1. Add your schema to `openapi.yaml` under `components/schemas/`
58+
2. Reference the schema in an API endpoint response
59+
3. Run the generation command above
60+
4. Update `__init__.py` to export the new models
61+
5. Import and use the models in your code
62+
63+
### Troubleshooting
64+
65+
- **Models not generated**: Ensure schemas are under `components/schemas/` (not `parameters/`)
66+
- **Missing models**: Verify schemas are referenced in at least one API path
67+
- **Import errors**: Check that new models are added to `__init__.py` exports
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
"""
2+
Data models for ComfyUI Manager.
3+
4+
This package contains Pydantic models used throughout the ComfyUI Manager
5+
for data validation, serialization, and type safety.
6+
7+
All models are auto-generated from the OpenAPI specification to ensure
8+
consistency between the API and implementation.
9+
"""
10+
11+
from .generated_models import (
12+
# Core Task Queue Models
13+
QueueTaskItem,
14+
TaskHistoryItem,
15+
TaskStateMessage,
16+
TaskExecutionStatus,
17+
18+
# WebSocket Message Models
19+
MessageTaskDone,
20+
MessageTaskStarted,
21+
MessageTaskFailed,
22+
MessageUpdate,
23+
ManagerMessageName,
24+
25+
# State Management Models
26+
BatchExecutionRecord,
27+
ComfyUISystemState,
28+
BatchOperation,
29+
InstalledNodeInfo,
30+
InstalledModelInfo,
31+
ComfyUIVersionInfo,
32+
33+
# Other models
34+
OperationType,
35+
OperationResult,
36+
ManagerPackInfo,
37+
ManagerPackInstalled,
38+
SelectedVersion,
39+
ManagerChannel,
40+
ManagerDatabaseSource,
41+
ManagerPackState,
42+
ManagerPackInstallType,
43+
ManagerPack,
44+
InstallPackParams,
45+
UpdatePackParams,
46+
UpdateAllPacksParams,
47+
UpdateComfyUIParams,
48+
FixPackParams,
49+
UninstallPackParams,
50+
DisablePackParams,
51+
EnablePackParams,
52+
UpdateAllQueryParams,
53+
UpdateComfyUIQueryParams,
54+
ComfyUISwitchVersionQueryParams,
55+
QueueStatus,
56+
ManagerMappings,
57+
ModelMetadata,
58+
NodePackageMetadata,
59+
SnapshotItem,
60+
Error,
61+
InstalledPacksResponse,
62+
HistoryResponse,
63+
HistoryListResponse,
64+
InstallType,
65+
SecurityLevel,
66+
RiskLevel,
67+
)
68+
69+
__all__ = [
70+
# Core Task Queue Models
71+
"QueueTaskItem",
72+
"TaskHistoryItem",
73+
"TaskStateMessage",
74+
"TaskExecutionStatus",
75+
76+
# WebSocket Message Models
77+
"MessageTaskDone",
78+
"MessageTaskStarted",
79+
"MessageTaskFailed",
80+
"MessageUpdate",
81+
"ManagerMessageName",
82+
83+
# State Management Models
84+
"BatchExecutionRecord",
85+
"ComfyUISystemState",
86+
"BatchOperation",
87+
"InstalledNodeInfo",
88+
"InstalledModelInfo",
89+
"ComfyUIVersionInfo",
90+
91+
# Other models
92+
"OperationType",
93+
"OperationResult",
94+
"ManagerPackInfo",
95+
"ManagerPackInstalled",
96+
"SelectedVersion",
97+
"ManagerChannel",
98+
"ManagerDatabaseSource",
99+
"ManagerPackState",
100+
"ManagerPackInstallType",
101+
"ManagerPack",
102+
"InstallPackParams",
103+
"UpdatePackParams",
104+
"UpdateAllPacksParams",
105+
"UpdateComfyUIParams",
106+
"FixPackParams",
107+
"UninstallPackParams",
108+
"DisablePackParams",
109+
"EnablePackParams",
110+
"UpdateAllQueryParams",
111+
"UpdateComfyUIQueryParams",
112+
"ComfyUISwitchVersionQueryParams",
113+
"QueueStatus",
114+
"ManagerMappings",
115+
"ModelMetadata",
116+
"NodePackageMetadata",
117+
"SnapshotItem",
118+
"Error",
119+
"InstalledPacksResponse",
120+
"HistoryResponse",
121+
"HistoryListResponse",
122+
"InstallType",
123+
"SecurityLevel",
124+
"RiskLevel",
125+
]

0 commit comments

Comments
 (0)