|
1 | | -# Repository Guidelines |
| 1 | +# Repository Guidelines for Agents |
2 | 2 |
|
3 | | -## Project Structure & Module Organization |
| 3 | +## Purpose |
4 | 4 | This repo is a Nix flake that packages ComfyUI plus curated custom nodes. |
| 5 | +Use this file as the single source of truth for build, lint, test, and style |
| 6 | +expectations when working in this repository. |
| 7 | + |
| 8 | +## Project Structure & Module Organization |
5 | 9 | - `nix/`: flake helpers, package definitions, module, checks, and version pins. |
6 | 10 | - `src/custom_nodes/`: bundled custom nodes (Python and frontend assets). |
7 | 11 | - `src/patches/`: patches applied to upstream components. |
8 | 12 | - `docs/`: additional documentation (setup guides, etc.). |
9 | 13 | - `scripts/`: maintenance scripts (template inputs, Cachix, model downloads). |
10 | 14 | - `data/`: local runtime data for container examples and demos. |
11 | 15 |
|
12 | | -## Build, Test, and Development Commands |
13 | | -- `nix run`: run ComfyUI (add `-- --open`, `--port=XXXX`, `--listen 0.0.0.0` as needed). |
14 | | -- `nix run .#cuda`: CUDA build on Linux/NVIDIA; use only when GPU support is required. |
| 16 | +## Development Environment |
| 17 | +- Use `nix develop` to enter the dev shell when running linting or formatting. |
| 18 | +- The dev shell provides `ruff`, `pyright`, `nixfmt`, and `shellcheck`. |
| 19 | +- Python runtime target is 3.12 (see `pyproject.toml`). |
| 20 | + |
| 21 | +## Build, Lint, Format, and Test Commands |
| 22 | +### Core Nix commands |
15 | 23 | - `nix build`: build the default package without running it. |
16 | | -- `nix develop`: enter the dev shell with `ruff`, `pyright`, and `nixfmt`. |
| 24 | +- `nix run`: run ComfyUI (add `-- --open`, `--port=XXXX`, `--listen 0.0.0.0`). |
| 25 | +- `nix run .#cuda`: CUDA build on Linux/NVIDIA only. |
17 | 26 | - `nix flake check`: run all checks (build, ruff, pyright, nixfmt, shellcheck). |
18 | 27 | - `nix fmt`: format Nix files with `nixfmt-rfc-style`. |
19 | 28 | - `nix run .#update`: check for ComfyUI version updates. |
20 | | -- `nix run .#buildDocker` / `nix run .#buildDockerCuda`: build CPU/CUDA images locally. |
| 29 | +- `nix run .#buildDocker`: build CPU Docker image. |
| 30 | +- `nix run .#buildDockerCuda`: build CUDA Docker image. |
| 31 | + |
| 32 | +### Python linting and formatting |
| 33 | +- `ruff check src/`: run linting on all Python sources. |
| 34 | +- `ruff check src/path/to/file.py`: lint a single Python file. |
| 35 | +- `ruff format src/`: format Python sources. |
| 36 | +- `ruff format src/path/to/file.py`: format a single Python file. |
| 37 | + |
| 38 | +### Python type checking |
| 39 | +- `pyright src/`: run type checks for the source tree. |
| 40 | +- `pyright src/path/to/file.py`: run type checks on a single Python file. |
| 41 | + |
| 42 | +### Shell scripting |
| 43 | +- `shellcheck scripts/*.sh`: lint shell scripts. |
| 44 | +- `shellcheck scripts/path/to/script.sh`: lint a single script. |
| 45 | + |
| 46 | +### Tests |
| 47 | +- There are no unit-test suites in this repo today. |
| 48 | +- The primary quality gate is `nix flake check`. |
| 49 | +- If tests are added in the future, prefer `pytest path/to/test.py::test_name` |
| 50 | + for a single test and `pytest path/to/test.py` for a single file. |
| 51 | + |
| 52 | +## Coding Style & Conventions |
| 53 | +### Python formatting |
| 54 | +- Python is formatted with `ruff format`. |
| 55 | +- Use 4-space indentation and a 100-character line length. |
| 56 | +- Use double quotes for strings unless escaping makes it noisy. |
| 57 | +- Prefer trailing commas in multi-line collections. |
| 58 | + |
| 59 | +### Imports |
| 60 | +- Order imports as standard library, third-party, then local. |
| 61 | +- Ruff enforces import ordering (isort). |
| 62 | +- Avoid unused imports except in `__init__.py` where they are allowed. |
| 63 | +- Star imports are allowed only in `src/custom_nodes/**` modules. |
| 64 | + |
| 65 | +### Naming |
| 66 | +- `snake_case` for functions, modules, variables. |
| 67 | +- `PascalCase` for classes. |
| 68 | +- `UPPER_SNAKE_CASE` for constants. |
| 69 | +- Avoid single-letter variable names unless the context is obvious. |
| 70 | + |
| 71 | +### Types |
| 72 | +- Python version is 3.12 (`pyright` configured accordingly). |
| 73 | +- Type checking mode is `basic`; be pragmatic with annotations. |
| 74 | +- Add type hints to new public functions and key data structures. |
| 75 | +- Prefer `typing` (e.g., `Iterable`, `Mapping`, `Sequence`) over concrete |
| 76 | + container types in APIs. |
| 77 | +- Use `typing.cast` only when necessary and document intent. |
| 78 | +- Use `from __future__ import annotations` when it improves readability. |
| 79 | + |
| 80 | +### Docstrings |
| 81 | +- Google-style docstrings are preferred. |
| 82 | +- Document public functions and classes when behavior is non-obvious. |
| 83 | +- Keep docstrings concise and action-oriented. |
| 84 | + |
| 85 | +### Error handling |
| 86 | +- Raise specific exceptions with actionable messages. |
| 87 | +- Preserve context by chaining (`raise ... from err`) when wrapping errors. |
| 88 | +- Avoid bare `except:`; catch explicit exception types. |
| 89 | +- It is acceptable to use `print` for status updates (ComfyUI convention). |
| 90 | + |
| 91 | +### Filesystem usage |
| 92 | +- `os.path` is acceptable (the repo does not mandate `pathlib`). |
| 93 | +- Prefer `pathlib.Path` only when it improves clarity or APIs require it. |
| 94 | +- Avoid writing outside the repo unless required by a script. |
| 95 | + |
| 96 | +### Performance and readability |
| 97 | +- Keep functions small and focused. |
| 98 | +- Avoid deeply nested conditionals; early returns are encouraged. |
| 99 | +- Prefer comprehensions when they remain readable. |
| 100 | +- Do not micro-optimize unless it is on a hot path. |
| 101 | + |
| 102 | +## Repo-Specific Ruff and Pyright Notes |
| 103 | +- Ruff targets Python 3.12 with 100-character lines. |
| 104 | +- Ruff ignores `T20` (print statements) and `G004` (f-strings in logging). |
| 105 | +- Ruff allows unused imports in `__init__.py` and star imports in |
| 106 | + `src/custom_nodes/**`. |
| 107 | +- Ruff complexity guard: `max-complexity = 15` (McCabe). |
| 108 | +- Pyright uses `basic` type checking with lenient missing import handling. |
| 109 | +- Pyright is configured to warn (not fail) on missing imports. |
| 110 | +- Pyright uses `typings/` as the stub path when available. |
| 111 | + |
| 112 | +## Nix Style |
| 113 | +- Format Nix files with `nix fmt`. |
| 114 | +- Keep attrsets aligned and avoid reformatting unrelated sections. |
| 115 | +- Prefer existing patterns in `nix/` for adding new derivations. |
21 | 116 |
|
22 | | -## Coding Style & Naming Conventions |
23 | | -- Python: 4-space indentation, 100-char lines, double quotes (`ruff format`). |
24 | | -- Imports: standard library, third-party, then local; `ruff` enforces ordering. |
25 | | -- Naming: `snake_case` for functions/vars, `PascalCase` for classes. |
26 | | -- Nix: format with `nix fmt` (nixfmt RFC style). |
27 | | -- Shell: scripts in `scripts/` should pass `shellcheck`. |
| 117 | +## Shell Style |
| 118 | +- Shell scripts should pass `shellcheck`. |
| 119 | +- Prefer `set -euo pipefail` for new scripts when appropriate. |
| 120 | +- Avoid bashisms if the script might be invoked by `sh`. |
| 121 | +- Keep scripts small and focused; prefer helpers in `scripts/`. |
28 | 122 |
|
29 | | -## Testing Guidelines |
30 | | -There are no unit-test suites in the repo today. Quality gates are: |
31 | | -- `nix flake check` (ruff + pyright + nixfmt + shellcheck). |
32 | | -- Optional manual runs: `ruff check src/` and `pyright src/` inside `nix develop`. |
| 123 | +## Cursor and Copilot Rules |
| 124 | +- No `.cursorrules` or `.cursor/rules/` found in this repo. |
| 125 | +- No `.github/copilot-instructions.md` found in this repo. |
33 | 126 |
|
34 | 127 | ## Commit & Pull Request Guidelines |
35 | | -- Commit style follows a conventional prefix, e.g. `docs: ...`, `ci: ...`, `refactor: ...`. |
36 | | -- Keep messages short and specific to the change. |
37 | | -- PRs should include a concise description, linked issues if applicable, and the checks run |
38 | | - (e.g. `nix flake check` or relevant `nix run`/`nix build` commands). |
| 128 | +- Commit style follows a conventional prefix, e.g. `docs: ...`, `ci: ...`, |
| 129 | + `refactor: ...`. |
| 130 | +- Keep commit messages short and specific to the change. |
| 131 | +- PRs should include a concise description, linked issues if applicable, and |
| 132 | + the checks run (e.g. `nix flake check`, `nix build`). |
39 | 133 |
|
40 | 134 | ## Agent-Specific Instructions |
41 | 135 | - After any file edits, run `git add` so the flake can see changes correctly. |
|
0 commit comments