mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
Drop multiversion support in Python model wrapper
This commit is contained in:
@@ -113,7 +113,7 @@ python_module(TARGET_NAME python-top-internal-module WHEEL revng_internal
|
||||
# Install revng.model (including autogenerated classes)
|
||||
#
|
||||
set(PYTHON_MODEL_FILES revng/model/__init__.py revng/model/metaaddress.py
|
||||
revng/model/v1/__init__.py revng/model/v1/external.py)
|
||||
revng/model/__init__.py revng/model/external.py)
|
||||
python_module(
|
||||
TARGET_NAME
|
||||
python-model
|
||||
|
||||
@@ -12,11 +12,4 @@ with open("/path/to/model.yaml") as f:
|
||||
model = yaml.load(f, Loader=m.YamlLoader)
|
||||
```
|
||||
|
||||
If you need to access a specific version of the model you can import it like so:
|
||||
|
||||
```python
|
||||
import yaml
|
||||
from revng.model import v1
|
||||
|
||||
yaml.load(..., Loader=v1.YamlLoader)
|
||||
```
|
||||
It is not possible to import a model with a schema version other than the latest.
|
||||
|
||||
@@ -1,7 +1,29 @@
|
||||
#
|
||||
# This file is distributed under the MIT License. See LICENSE.md for details.
|
||||
#
|
||||
# flake8: noqa: F405
|
||||
# type: ignore
|
||||
|
||||
from .v1 import * # noqa: F401,F403
|
||||
from revng.tupletree import Reference, enum_value_to_index, init_reference_yaml_classes
|
||||
|
||||
_last_version = "v1"
|
||||
from . import _generated
|
||||
from ._generated import *
|
||||
from .metaaddress import *
|
||||
|
||||
init_metaaddress_yaml_classes(YamlLoader, YamlDumper)
|
||||
init_reference_yaml_classes(YamlLoader, YamlDumper)
|
||||
|
||||
|
||||
class Binary(_generated.Binary):
|
||||
@classmethod
|
||||
def get_reference_str(cls, t):
|
||||
if hasattr(t, "Kind"):
|
||||
typename = t.Kind.value
|
||||
else:
|
||||
typename = type(t).__name__
|
||||
return f"/TypeDefinitions/{t.ID}-{typename}"
|
||||
|
||||
|
||||
# Since we subclassed them we need to re-register their constructors and representers
|
||||
YamlLoader.add_constructor("!Binary", Binary.yaml_constructor)
|
||||
YamlDumper.add_representer(Binary, Binary.yaml_representer)
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
# This file is distributed under the MIT License. See LICENSE.md for details.
|
||||
#
|
||||
|
||||
from ..metaaddress import MetaAddress # noqa: F401
|
||||
from .metaaddress import MetaAddress # noqa: F401
|
||||
@@ -1,29 +0,0 @@
|
||||
#
|
||||
# This file is distributed under the MIT License. See LICENSE.md for details.
|
||||
#
|
||||
# flake8: noqa: F405
|
||||
# type: ignore
|
||||
|
||||
from revng.tupletree import Reference, enum_value_to_index, init_reference_yaml_classes
|
||||
|
||||
from ..metaaddress import *
|
||||
from . import _generated
|
||||
from ._generated import *
|
||||
|
||||
init_metaaddress_yaml_classes(YamlLoader, YamlDumper)
|
||||
init_reference_yaml_classes(YamlLoader, YamlDumper)
|
||||
|
||||
|
||||
class Binary(_generated.Binary):
|
||||
@classmethod
|
||||
def get_reference_str(cls, t):
|
||||
if hasattr(t, "Kind"):
|
||||
typename = t.Kind.value
|
||||
else:
|
||||
typename = type(t).__name__
|
||||
return f"/TypeDefinitions/{t.ID}-{typename}"
|
||||
|
||||
|
||||
# Since we subclassed them we need to re-register their constructors and representers
|
||||
YamlLoader.add_constructor("!Binary", Binary.yaml_constructor)
|
||||
YamlDumper.add_representer(Binary, Binary.yaml_representer)
|
||||
Reference in New Issue
Block a user