Commit 266ea5e6 authored by Fabien Amarger's avatar Fabien Amarger
Browse files

fix(entities.py): Use jinja instead of f-string

By the way, add the registration_callback function
parent 90480b9feebf
from yams.schema import Schema
from typing import Dict
import jinja2
entities_template = jinja2.Template(
"""
from cubicweb.entities.adapters import EntityRDFAdapter
from rdflib import URIRef, OWL
{% for fragment, uri in entitytype_fragment_to_uri.items() %}
class {{fragment}}RDFAdapter(EntityRDFAdapter):
def triples(self):
yield from super().triples()
yield(URIRef("{{uri}}"), OWL.sameAs, URIRef(self.uri))
{% endfor %}
def registration_callback(vreg):
vreg.register_all(
globals().values(),
__name__,
({% for fragment in entitytype_fragment_to_uri %} {{fragment}}RDFAdapter, {% endfor %})
)
"""
)
def generate_entities(
......@@ -7,18 +31,6 @@
entitytype_fragment_to_uri: Dict[str, str],
relationtype_fragment_to_uri: Dict[str, str],
) -> str:
entities_py_content = """
from cubicweb.entities.adapters import EntityRDFAdapter
from rdflib import URIRef, OWL
"""
for fragment, uri in entitytype_fragment_to_uri.items():
entities_py_content += f"""
class {fragment}RDFAdapter(EntityRDFAdapter):
def triples(self):
yield from super().triples()
yield(URIRef("{uri}"), OWL.sameAs, URIRef(self.uri))
"""
return entities_py_content
return entities_template.render(
entitytype_fragment_to_uri=entitytype_fragment_to_uri
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment