Skip to content

Commit 7b9843a

Browse files
committed
[Lint] Set 99 char line length and bulk reformat
Set up ruff to enforce a 99 char line limit, mirroring other OpenAssetIO projects. Configure yml with 2-space tabs, mirroring other OpenAssetIO projects (and the ComfyUI cookiecutter project's defaults). Bulk reformat using PyCharm configured to use ruff - i.e. Python files are reformatted using ruff, whilst other files are reformatted according to .editorconfig and/or PyCharm defaults. Signed-off-by: David Feltell <[email protected]>
1 parent 1f51166 commit 7b9843a

File tree

7 files changed

+97
-61
lines changed

7 files changed

+97
-61
lines changed

.editorconfig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trim_trailing_whitespace = true
1313
insert_final_newline = true
1414
charset = utf-8
1515
end_of_line = lf
16-
max_line_length = 140
16+
max_line_length = 99
1717
# For docstrings and comments.
1818
ij_visual_guides = 72
1919

@@ -26,3 +26,6 @@ insert_final_newline = false
2626

2727
[Makefile]
2828
indent_style = tab
29+
30+
[{*.yml,*.yaml}]
31+
indent_size = 2

.github/workflows/build-pipeline.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jobs:
1616
PYTHONIOENCODING: "utf8"
1717
strategy:
1818
matrix:
19-
os: [ubuntu-latest]
20-
python-version: ["3.12"]
19+
os: [ ubuntu-latest ]
20+
python-version: [ "3.12" ]
2121

2222
steps:
2323
- uses: actions/checkout@v4

README.md

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
OpenAssetIO ingress and egress
44

55
> [!NOTE]
6-
> This projected was created with a [cookiecutter](https://github.com/Comfy-Org/cookiecutter-comfy-extension) template. It helps you start writing custom nodes without worrying about the Python setup.
6+
> This projected was created with
7+
> a [cookiecutter](https://github.com/Comfy-Org/cookiecutter-comfy-extension) template. It helps you
8+
> start
9+
> writing custom nodes without worrying about the Python setup.
710
811
## Quickstart
912

1013
1. Install [ComfyUI](https://docs.comfy.org/get_started).
1114
1. Install [ComfyUI-Manager](https://github.com/ltdrdata/ComfyUI-Manager)
12-
1. Look up this extension in ComfyUI-Manager. If you are installing manually, clone this repository under `ComfyUI/custom_nodes`.
15+
1. Look up this extension in ComfyUI-Manager. If you are installing manually, clone this repository
16+
under `ComfyUI/custom_nodes`.
1317
1. Restart ComfyUI.
1418

1519
# Features
@@ -26,14 +30,19 @@ pip install -e .[dev]
2630
pre-commit install
2731
```
2832

29-
The `-e` flag above will result in a "live" install, in the sense that any changes you make to your node extension will automatically be picked up the next time you run ComfyUI.
33+
The `-e` flag above will result in a "live" install, in the sense that any changes you make to your
34+
node extension will automatically be
35+
picked up the next time you run ComfyUI.
3036

3137
## Publish to Github
3238

33-
Install Github Desktop or follow these [instructions](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent) for ssh.
39+
Install Github Desktop or follow
40+
these [instructions](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent)
41+
for ssh.
3442

3543
1. Create a Github repository that matches the directory name.
3644
2. Push the files to Git
45+
3746
```
3847
git add .
3948
git commit -m "project scaffolding"
@@ -42,26 +51,38 @@ git push
4251

4352
## Writing custom nodes
4453

45-
An example custom node is located in [node.py](src/openassetio-comfyui/nodes.py). To learn more, read the [docs](https://docs.comfy.org/essentials/custom_node_overview).
46-
54+
An example custom node is located in [node.py](src/openassetio-comfyui/nodes.py). To learn more,
55+
read
56+
the [docs](https://docs.comfy.org/essentials/custom_node_overview).
4757

4858
## Tests
4959

50-
This repo contains unit tests written in Pytest in the `tests/` directory. It is recommended to unit test your custom node.
60+
This repo contains unit tests written in Pytest in the `tests/` directory. It is recommended to
61+
unit test your custom node.
5162

52-
- [build-pipeline.yml](.github/workflows/build-pipeline.yml) will run pytest and linter on any open PRs
53-
- [validate.yml](.github/workflows/validate.yml) will run [node-diff](https://github.com/Comfy-Org/node-diff) to check for breaking changes
63+
- [build-pipeline.yml](.github/workflows/build-pipeline.yml) will run pytest and linter on any open
64+
PRs
65+
- [validate.yml](.github/workflows/validate.yml) will
66+
run [node-diff](https://github.com/Comfy-Org/node-diff) to check for breaking changes
5467

5568
## Publishing to Registry
5669

57-
If you wish to share this custom node with others in the community, you can publish it to the registry. We've already auto-populated some fields in `pyproject.toml` under `tool.comfy`, but please double-check that they are correct.
70+
If you wish to share this custom node with others in the community, you can publish it to the
71+
registry. We've already auto-populated some
72+
fields in `pyproject.toml` under `tool.comfy`, but please double-check that they are correct.
5873

5974
You need to make an account on https://registry.comfy.org and create an API key token.
6075

61-
- [ ] Go to the [registry](https://registry.comfy.org). Login and create a publisher id (everything after the `@` sign on your registry profile).
76+
- [ ] Go to the [registry](https://registry.comfy.org). Login and create a publisher id (everything
77+
after the `@` sign on your registry
78+
profile).
6279
- [ ] Add the publisher id into the pyproject.toml file.
63-
- [ ] Create an api key on the Registry for publishing from Github. [Instructions](https://docs.comfy.org/registry/publishing#create-an-api-key-for-publishing).
80+
- [ ] Create an api key on the Registry for publishing from
81+
Github. [Instructions](https://docs.comfy.org/registry/publishing#create-an-api-key-for-publishing).
6482
- [ ] Add it to your Github Repository Secrets as `REGISTRY_ACCESS_TOKEN`.
6583

66-
A Github action will run on every git push. You can also run the Github action manually. Full instructions [here](https://docs.comfy.org/registry/publishing). Join our [discord](https://discord.com/invite/comfyorg) if you have any questions!
84+
A Github action will run on every git push. You can also run the Github action manually. Full
85+
instructions [here](https://docs.comfy.org/registry/publishing). Join
86+
our [discord](https://discord.com/invite/comfyorg) if you have any
87+
questions!
6788

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ disable_error_code = "attr-defined"
7070

7171
[tool.ruff]
7272
# extend-exclude = ["static", "ci/templates"]
73-
line-length = 140
73+
line-length = 99
7474
src = ["src", "tests"]
7575
target-version = "py311"
7676

src/openassetio_comfyui/nodes.py

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
from inspect import cleandoc
6+
7+
68
class Example:
79
"""
810
A example node
@@ -32,57 +34,68 @@ class Example:
3234
The entry point method. The name of this method must be the same as the value of property `FUNCTION`.
3335
For example, if `FUNCTION = "execute"` then this method's name must be `execute`, if `FUNCTION = "foo"` then it must be `foo`.
3436
"""
37+
3538
def __init__(self):
3639
pass
3740

3841
@classmethod
3942
def INPUT_TYPES(s):
4043
"""
41-
Return a dictionary which contains config for all input fields.
42-
Some types (string): "MODEL", "VAE", "CLIP", "CONDITIONING", "LATENT", "IMAGE", "INT", "STRING", "FLOAT".
43-
Input types "INT", "STRING" or "FLOAT" are special values for fields on the node.
44-
The type can be a list for selection.
45-
46-
Returns: `dict`:
47-
- Key input_fields_group (`string`): Can be either required, hidden or optional. A node class must have property `required`
48-
- Value input_fields (`dict`): Contains input fields config:
49-
* Key field_name (`string`): Name of a entry-point method's argument
50-
* Value field_config (`tuple`):
51-
+ First value is a string indicate the type of field or a list for selection.
52-
+ Secound value is a config for type "INT", "STRING" or "FLOAT".
44+
Return a dictionary which contains config for all input fields.
45+
Some types (string): "MODEL", "VAE", "CLIP", "CONDITIONING", "LATENT", "IMAGE", "INT", "STRING", "FLOAT".
46+
Input types "INT", "STRING" or "FLOAT" are special values for fields on the node.
47+
The type can be a list for selection.
48+
49+
Returns: `dict`:
50+
- Key input_fields_group (`string`): Can be either required, hidden or optional. A node class must have property `required`
51+
- Value input_fields (`dict`): Contains input fields config:
52+
* Key field_name (`string`): Name of a entry-point method's argument
53+
* Value field_config (`tuple`):
54+
+ First value is a string indicate the type of field or a list for selection.
55+
+ Secound value is a config for type "INT", "STRING" or "FLOAT".
5356
"""
5457
return {
5558
"required": {
56-
"image": ("Image", { "tooltip": "This is an image"}),
57-
"int_field": ("INT", {
58-
"default": 0,
59-
"min": 0, #Minimum value
60-
"max": 4096, #Maximum value
61-
"step": 64, #Slider's step
62-
"display": "number" # Cosmetic only: display as "number" or "slider"
63-
}),
64-
"float_field": ("FLOAT", {
65-
"default": 1.0,
66-
"min": 0.0,
67-
"max": 10.0,
68-
"step": 0.01,
69-
"round": 0.001, #The value represeting the precision to round to, will be set to the step value by default. Can be set to False to disable rounding.
70-
"display": "number"}),
59+
"image": ("Image", {"tooltip": "This is an image"}),
60+
"int_field": (
61+
"INT",
62+
{
63+
"default": 0,
64+
"min": 0, # Minimum value
65+
"max": 4096, # Maximum value
66+
"step": 64, # Slider's step
67+
"display": "number", # Cosmetic only: display as "number" or "slider"
68+
},
69+
),
70+
"float_field": (
71+
"FLOAT",
72+
{
73+
"default": 1.0,
74+
"min": 0.0,
75+
"max": 10.0,
76+
"step": 0.01,
77+
"round": 0.001, # The value represeting the precision to round to, will be set to the step value by default. Can be set to False to disable rounding.
78+
"display": "number",
79+
},
80+
),
7181
"print_to_screen": (["enable", "disable"],),
72-
"string_field": ("STRING", {
73-
"multiline": False, #True if you want the field to look like the one on the ClipTextEncode node
74-
"default": "Hello World!"
75-
}),
82+
"string_field": (
83+
"STRING",
84+
{
85+
"multiline": False, # True if you want the field to look like the one on the ClipTextEncode node
86+
"default": "Hello World!",
87+
},
88+
),
7689
},
7790
}
7891

7992
RETURN_TYPES = ("IMAGE",)
80-
#RETURN_NAMES = ("image_output_name",)
93+
# RETURN_NAMES = ("image_output_name",)
8194
DESCRIPTION = cleandoc(__doc__)
8295
FUNCTION = "test"
8396

84-
#OUTPUT_NODE = False
85-
#OUTPUT_TOOLTIPS = ("",) # Tooltips for the output node
97+
# OUTPUT_NODE = False
98+
# OUTPUT_TOOLTIPS = ("",) # Tooltips for the output node
8699

87100
CATEGORY = "Example"
88101

@@ -93,7 +106,7 @@ def test(self, image, string_field, int_field, float_field, print_to_screen):
93106
int_field: {int_field}
94107
float_field: {float_field}
95108
""")
96-
#do some processing on the image, in this example I just invert it
109+
# do some processing on the image, in this example I just invert it
97110
image = 1.0 - image
98111
return (image,)
99112

@@ -105,18 +118,14 @@ def test(self, image, string_field, int_field, float_field, print_to_screen):
105118
This method is used in the core repo for the LoadImage node where they return the image hash as a string, if the image hash
106119
changes between executions the LoadImage node is executed again.
107120
"""
108-
#@classmethod
109-
#def IS_CHANGED(s, image, string_field, int_field, float_field, print_to_screen):
121+
# @classmethod
122+
# def IS_CHANGED(s, image, string_field, int_field, float_field, print_to_screen):
110123
# return ""
111124

112125

113126
# A dictionary that contains all nodes you want to export with their names
114127
# NOTE: names should be globally unique
115-
NODE_CLASS_MAPPINGS = {
116-
"Example": Example
117-
}
128+
NODE_CLASS_MAPPINGS = {"Example": Example}
118129

119130
# A dictionary that contains the friendly/humanly readable titles for the nodes
120-
NODE_DISPLAY_NAME_MAPPINGS = {
121-
"Example": "Example Node"
122-
}
131+
NODE_DISPLAY_NAME_MAPPINGS = {"Example": "Example Node"}

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
# Add the project root directory to Python path
99
# This allows the tests to import the project
10-
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
10+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

tests/test_openassetio_comfyui.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@
88
import pytest
99
from src.openassetio_comfyui.nodes import Example
1010

11+
1112
@pytest.fixture
1213
def example_node():
1314
"""Fixture to create an Example node instance."""
1415
return Example()
1516

17+
1618
def test_example_node_initialization(example_node):
1719
"""Test that the node can be instantiated."""
1820
assert isinstance(example_node, Example)
1921

22+
2023
def test_return_types():
2124
"""Test the node's metadata."""
2225
assert Example.RETURN_TYPES == ("IMAGE",)

0 commit comments

Comments
 (0)