liminal-orm 2.0.1__py3-none-any.whl → 2.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- liminal/validation/__init__.py +56 -46
- {liminal_orm-2.0.1.dist-info → liminal_orm-2.0.2.dist-info}/METADATA +2 -2
- {liminal_orm-2.0.1.dist-info → liminal_orm-2.0.2.dist-info}/RECORD +6 -6
- {liminal_orm-2.0.1.dist-info → liminal_orm-2.0.2.dist-info}/LICENSE.md +0 -0
- {liminal_orm-2.0.1.dist-info → liminal_orm-2.0.2.dist-info}/WHEEL +0 -0
- {liminal_orm-2.0.1.dist-info → liminal_orm-2.0.2.dist-info}/entry_points.txt +0 -0
liminal/validation/__init__.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import inspect
|
2
2
|
from datetime import datetime
|
3
|
-
from functools import wraps
|
4
|
-
from typing import TYPE_CHECKING, Callable
|
3
|
+
from functools import partial, wraps
|
4
|
+
from typing import TYPE_CHECKING, Any, Callable
|
5
5
|
|
6
6
|
from pydantic import BaseModel, ConfigDict
|
7
7
|
|
@@ -67,6 +67,7 @@ class BenchlingValidatorReport(BaseModel):
|
|
67
67
|
entity: type["BenchlingBaseModel"],
|
68
68
|
validator_name: str,
|
69
69
|
message: str | None = None,
|
70
|
+
**kwargs: Any,
|
70
71
|
) -> "BenchlingValidatorReport":
|
71
72
|
"""Creates a BenchlingValidatorReport with the given parameters.
|
72
73
|
|
@@ -96,59 +97,68 @@ class BenchlingValidatorReport(BaseModel):
|
|
96
97
|
creator_email=entity.creator.email if entity.creator else None,
|
97
98
|
updated_date=entity.modified_at,
|
98
99
|
message=message,
|
100
|
+
**kwargs,
|
99
101
|
)
|
100
102
|
|
101
103
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
104
|
+
def _liminal_decorator(
|
105
|
+
func: Callable[[type["BenchlingBaseModel"]], BenchlingValidatorReport | None],
|
106
|
+
validator_level: ValidationSeverity,
|
107
|
+
validator_name: str | None,
|
105
108
|
) -> Callable:
|
106
|
-
"""
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
"""
|
114
|
-
|
115
|
-
def decorator(func: Callable[[type["BenchlingBaseModel"]], None]) -> Callable:
|
116
|
-
"""Decorator that validates a function that takes a Benchling entity as an argument and returns None."""
|
117
|
-
sig = inspect.signature(func)
|
118
|
-
params = list(sig.parameters.values())
|
119
|
-
if not params or params[0].name != "self" or len(params) > 1:
|
120
|
-
raise TypeError(
|
121
|
-
"Validator must defined in a schema class, where the only argument to this validator must be 'self'."
|
122
|
-
)
|
109
|
+
"""Core decorator logic for liminal_validator."""
|
110
|
+
sig = inspect.signature(func)
|
111
|
+
params = list(sig.parameters.values())
|
112
|
+
if not params or params[0].name != "self" or len(params) > 1:
|
113
|
+
raise TypeError(
|
114
|
+
"Validator must be defined in a schema class, where the only argument to this validator must be 'self'."
|
115
|
+
)
|
123
116
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
func(self)
|
136
|
-
except Exception as e:
|
137
|
-
return BenchlingValidatorReport.create_validation_report(
|
138
|
-
valid=False,
|
139
|
-
level=validator_level,
|
140
|
-
entity=self,
|
141
|
-
validator_name=validator_name,
|
142
|
-
message=str(e),
|
143
|
-
)
|
117
|
+
if validator_name is None:
|
118
|
+
validator_name = pascalize(func.__name__)
|
119
|
+
|
120
|
+
@wraps(func)
|
121
|
+
def wrapper(self: type["BenchlingBaseModel"]) -> BenchlingValidatorReport:
|
122
|
+
"""Wrapper that runs the validator function and returns a BenchlingValidatorReport."""
|
123
|
+
try:
|
124
|
+
ret_val = func(self)
|
125
|
+
if type(ret_val) is BenchlingValidatorReport:
|
126
|
+
return ret_val
|
127
|
+
except Exception as e:
|
144
128
|
return BenchlingValidatorReport.create_validation_report(
|
145
|
-
valid=
|
129
|
+
valid=False,
|
146
130
|
level=validator_level,
|
147
131
|
entity=self,
|
148
132
|
validator_name=validator_name,
|
133
|
+
message=str(e),
|
149
134
|
)
|
135
|
+
return BenchlingValidatorReport.create_validation_report(
|
136
|
+
valid=True,
|
137
|
+
level=validator_level,
|
138
|
+
entity=self,
|
139
|
+
validator_name=validator_name,
|
140
|
+
)
|
141
|
+
|
142
|
+
setattr(wrapper, "_is_liminal_validator", True)
|
143
|
+
return wrapper
|
150
144
|
|
151
|
-
setattr(wrapper, "_is_liminal_validator", True)
|
152
|
-
return wrapper
|
153
145
|
|
154
|
-
|
146
|
+
def liminal_validator(
|
147
|
+
validator_level: ValidationSeverity = ValidationSeverity.LOW,
|
148
|
+
validator_name: str | None = None,
|
149
|
+
) -> Callable:
|
150
|
+
"""A decorator for a function that validates a Benchling entity, defined on a schema class.
|
151
|
+
Wraps around any exceptions raised by the validator function, and returns a BenchlingValidatorReport.
|
152
|
+
|
153
|
+
Parameters
|
154
|
+
----------
|
155
|
+
validator_level: ValidationSeverity
|
156
|
+
The severity level of the validation report. Defaults to ValidationSeverity.LOW.
|
157
|
+
validator_name: str | None =
|
158
|
+
The name of the validator. Defaults to the PascalCase version of the function name.
|
159
|
+
"""
|
160
|
+
return partial(
|
161
|
+
_liminal_decorator,
|
162
|
+
validator_level=validator_level,
|
163
|
+
validator_name=validator_name,
|
164
|
+
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: liminal-orm
|
3
|
-
Version: 2.0.
|
3
|
+
Version: 2.0.2
|
4
4
|
Summary: An ORM and toolkit that builds on top of Benchling's platform to keep your schemas and downstream code dependencies in sync.
|
5
5
|
Home-page: https://github.com/dynotx/liminal-orm
|
6
6
|
Author: DynoTx Open Source
|
@@ -88,7 +88,7 @@ With your schemas defined in code, you can now take advantage of the additional
|
|
88
88
|
class Pizza(BaseModel, CustomEntityMixin):
|
89
89
|
...
|
90
90
|
|
91
|
-
@liminal_validator
|
91
|
+
@liminal_validator
|
92
92
|
def cook_time_and_temp_validator(self) -> None:
|
93
93
|
if self.cook_time is not None and self.cook_temp is None:
|
94
94
|
raise ValueError("Cook temp is required if cook time is set")
|
@@ -59,10 +59,10 @@ liminal/tests/from benchling_sdk.py,sha256=CjRUHFB3iaa4rUPLGOqDiBq5EPKldm-Fd8aQQ
|
|
59
59
|
liminal/tests/test_dropdown_compare.py,sha256=yHB0ovQlBLRu8-qYkqIPd8VtYEOmOft_93FQM86g_z8,8198
|
60
60
|
liminal/tests/test_entity_schema_compare.py,sha256=-26Bu5eYIuHRswB5kYjGDo5Wed5LUWjm1e6IRI1Q-lE,18952
|
61
61
|
liminal/utils.py,sha256=radRtRsZmCiNblMvxOX1DH0rcO5TR09kFlp6OONIPBU,2951
|
62
|
-
liminal/validation/__init__.py,sha256=
|
62
|
+
liminal/validation/__init__.py,sha256=aMxO1vcZ_1Ay1Br0BCEEc09xge8-g5TL1sJ0KHbtRM8,5684
|
63
63
|
liminal/validation/validation_severity.py,sha256=ib03PTZCQHcbBDc01v4gJF53YtA-ANY6QSFnhTV-FbU,259
|
64
|
-
liminal_orm-2.0.
|
65
|
-
liminal_orm-2.0.
|
66
|
-
liminal_orm-2.0.
|
67
|
-
liminal_orm-2.0.
|
68
|
-
liminal_orm-2.0.
|
64
|
+
liminal_orm-2.0.2.dist-info/LICENSE.md,sha256=oVA877F_D1AV44dpjsv4f-4k690uNGApX1EtzOo3T8U,11353
|
65
|
+
liminal_orm-2.0.2.dist-info/METADATA,sha256=xOqcfpE7GSkUtmzLq_aNi8xGC74QEmKgK1Ki50przG4,11032
|
66
|
+
liminal_orm-2.0.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
67
|
+
liminal_orm-2.0.2.dist-info/entry_points.txt,sha256=atIrU63rrzH81dWC2sjUbFLlc5FWMmYRdMxXEWexIZA,47
|
68
|
+
liminal_orm-2.0.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|