Skip to content

Commit f75c545

Browse files
authored
fix: support PEP 639 SPDX license identifiers in pyproject.toml (#383)
1 parent 291b264 commit f75c545

2 files changed

Lines changed: 11 additions & 28 deletions

File tree

comfy_cli/registry/config_parser.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def create_comfynode_config():
2727
project["description"] = ""
2828
project["version"] = "1.0.0"
2929
project["dependencies"] = tomlkit.aot()
30-
project["license"] = "LICENSE"
30+
project["license"] = "MIT"
3131

3232
urls = tomlkit.table()
3333
urls["Repository"] = ""
@@ -207,18 +207,16 @@ def initialize_project_config():
207207
project["description"] = ""
208208
project["version"] = "1.0.0"
209209

210-
# Update the license field to comply with pyproject.toml spec
211-
license_table = tomlkit.inline_table()
212-
license_table["file"] = "LICENSE"
213-
project["license"] = license_table
210+
# Use PEP 639 SPDX license identifier
211+
project["license"] = "MIT"
214212

215213
# [project].classifiers Classifiers uncommentable hint for OS/GPU support
216214
# Attach classifiers comments to the project, below of "license" field.
217215
# will generate a comment like this:
218216
#
219217
# [project]
220218
# ...
221-
# license = {file = "LICENSE"}
219+
# license = "MIT"
222220
# # classifiers = [
223221
# # # For OS-independent nodes (works on all operating systems)
224222
# ...
@@ -304,9 +302,6 @@ def extract_node_configuration(
304302
license_data = project_data.get("license", {})
305303
if isinstance(license_data, str):
306304
license = License(text=license_data)
307-
typer.echo(
308-
'Warning: License should be in one of these two formats: license = {file = "LICENSE"} OR license = {text = "MIT License"}. Please check the documentation: https://docs.comfy.org/registry/specifications.'
309-
)
310305
elif isinstance(license_data, dict):
311306
if "file" in license_data or "text" in license_data:
312307
license = License(file=license_data.get("file", ""), text=license_data.get("text", ""))

tests/comfy_cli/registry/test_config_parser.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ def test_extract_node_configuration_success(mock_toml_data):
8787
assert result.tool_comfy.models[0] == Model(location="model1.bin", model_url="https://example.com/model1")
8888

8989

90-
def test_extract_node_configuration_license_text():
90+
@pytest.mark.parametrize(
91+
"license_str",
92+
["MIT", "Apache-2.0", "GPL-3.0-or-later", "MIT License"],
93+
)
94+
def test_extract_node_configuration_license_spdx_string(license_str):
9195
mock_data = {
9296
"project": {
93-
"license": "MIT License",
97+
"license": license_str,
9498
},
9599
}
96100
with (
@@ -101,7 +105,7 @@ def test_extract_node_configuration_license_text():
101105
result = extract_node_configuration("fake_path.toml")
102106
assert result is not None, "Expected PyProjectConfig, got None"
103107
assert isinstance(result, PyProjectConfig)
104-
assert result.project.license == License(text="MIT License")
108+
assert result.project.license == License(text=license_str)
105109

106110

107111
def test_extract_node_configuration_license_text_dict():
@@ -124,22 +128,6 @@ def test_extract_node_configuration_license_text_dict():
124128
)
125129

126130

127-
def test_extract_license_incorrect_format():
128-
mock_data = {
129-
"project": {"license": "MIT"},
130-
}
131-
with (
132-
patch("os.path.isfile", return_value=True),
133-
patch("builtins.open", mock_open()),
134-
patch("tomlkit.load", return_value=mock_data),
135-
):
136-
result = extract_node_configuration("fake_path.toml")
137-
138-
assert result is not None, "Expected PyProjectConfig, got None"
139-
assert isinstance(result, PyProjectConfig)
140-
assert result.project.license == License(text="MIT")
141-
142-
143131
def test_extract_node_configuration_with_os_classifiers():
144132
mock_data = {
145133
"project": {

0 commit comments

Comments
 (0)