Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom generator class serialization fix #17954

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion conan/internal/model/conan_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ def serialize(self):
result["options_definitions"] = self.options.possible_values

if self.generators is not None:
result["generators"] = list(self.generators)
result["generators"] = list(s.__name__ if isinstance(s, type) else s
for s in self.generators)
if self.license is not None:
result["license"] = list(self.license) if not isinstance(self.license, str) else self.license

Expand Down
28 changes: 28 additions & 0 deletions test/integration/generators/test_generators_from_br.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import textwrap

from conan.test.utils.tools import TestClient
Expand Down Expand Up @@ -89,3 +90,30 @@ def package_info(self):
content = tc.load("conanbuild.sh")
assert "conantest.sh" in content
assert "envars_generator2.sh" in content


def test_json_serialization_error():
c = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile

class MyGenerator:
def __init__(self, conanfile):
self._conanfile = conanfile

def generate(self):
pass

class MyToolReq(ConanFile):
name = "mygenerator-tool"
version = "1.0"

def package_info(self):
self.generator_info = [MyGenerator]
""")

c.save({"tool/conanfile.py": conanfile})
c.run("create tool")
c.run("install --tool-requires=mygenerator-tool/1.0 --format=json")
graph = json.loads(c.stdout)
assert graph["graph"]["nodes"]["0"]["generators"] == ["MyGenerator"]