Skip to content

Commit 5daefcf

Browse files
author
Lyuba Zehl
authored
Merge pull request #21 from openMetadataInitiative/simpler-versions
Only produce Python modules for the latest minor version for a given major version.
2 parents cf0d442 + e822538 commit 5daefcf

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

pipeline/src/module_template.py.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class {{ class_name }}({{ base_class }}):
1818
context = {
1919
"@vocab": "https://openminds.ebrains.eu/vocab/"
2020
}
21+
schema_version = "{{ schema_version }}"
2122

2223
properties = [
2324
{% for property in properties -%}

pipeline/translator.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ def __init__(self, schema_file_path: str, root_path: str):
4747
with open(schema_file_path, "r") as schema_f:
4848
self._schema_payload = json.load(schema_f)
4949

50+
@property
51+
def _version_module(self):
52+
# we keep only the major version.
53+
# this code assumes that minor versions are processed from oldest to newest
54+
# so that the Python package will always contain the latest minor version
55+
return self.version.split(".")[0]
56+
5057
def _target_file_without_extension(self) -> str:
51-
return os.path.join(self.version.replace(".", "_"), "/".join(self.relative_path_without_extension))
58+
return os.path.join(self._version_module, "/".join(self.relative_path_without_extension))
5259

5360
def translate(self, embedded=None):
5461
def get_type(property):
@@ -63,13 +70,12 @@ def get_type(property):
6370
"email": "str", # todo: add an Email class for validation?
6471
"ECMA262": "str", # ...
6572
}
66-
version_module = self.version.replace(".", "_")
6773
if "_linkedTypes" in property:
6874
types = []
6975
for item in property["_linkedTypes"]:
7076
openminds_module, class_name = item.split("/")[-2:]
7177
openminds_module = generate_python_name(openminds_module)
72-
types.append(f"openminds.{version_module}.{openminds_module}.{class_name}")
78+
types.append(f"openminds.{self._version_module}.{openminds_module}.{class_name}")
7379
if len(types) == 1:
7480
types = f'"{types[0]}"'
7581
return types
@@ -78,7 +84,7 @@ def get_type(property):
7884
for item in property["_embeddedTypes"]:
7985
openminds_module, class_name = item.split("/")[-2:]
8086
openminds_module = generate_python_name(openminds_module)
81-
types.append(f"openminds.{version_module}.{openminds_module}.{class_name}")
87+
types.append(f"openminds.{self._version_module}.{openminds_module}.{class_name}")
8288
if len(types) == 1:
8389
types = f'"{types[0]}"'
8490
return types
@@ -110,6 +116,7 @@ def get_type(property):
110116
"preamble": "", # todo: e.g. extra imports
111117
"class_name": self._schema_payload["name"],
112118
"openminds_type": self._schema_payload["_type"],
119+
"schema_version": self.version,
113120
"properties": [ # call this "properties"
114121
{
115122
"name": generate_python_name(property["name"]),

0 commit comments

Comments
 (0)