liminal-orm 2.0.1__py3-none-any.whl → 2.0.3a0__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 +47 -43
- {liminal_orm-2.0.1.dist-info → liminal_orm-2.0.3a0.dist-info}/METADATA +2 -2
- {liminal_orm-2.0.1.dist-info → liminal_orm-2.0.3a0.dist-info}/RECORD +6 -6
- {liminal_orm-2.0.1.dist-info → liminal_orm-2.0.3a0.dist-info}/LICENSE.md +0 -0
- {liminal_orm-2.0.1.dist-info → liminal_orm-2.0.3a0.dist-info}/WHEEL +0 -0
- {liminal_orm-2.0.1.dist-info → liminal_orm-2.0.3a0.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,62 @@ 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
104
|
def liminal_validator(
|
105
|
+
func: Callable[[type["BenchlingBaseModel"]], BenchlingValidatorReport | None]
|
106
|
+
| None = None,
|
107
|
+
*,
|
103
108
|
validator_level: ValidationSeverity = ValidationSeverity.LOW,
|
104
109
|
validator_name: str | None = None,
|
105
110
|
) -> Callable:
|
106
|
-
"""A decorator
|
111
|
+
"""A decorator for a function that validates a Benchling entity, defined on a schema class.
|
112
|
+
Can be used with or without parameters. Wraps around any exceptions raised by the validator function,
|
113
|
+
and returns a BenchlingValidatorReport.
|
107
114
|
|
108
|
-
Parameters
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
115
|
+
Parameters
|
116
|
+
----------
|
117
|
+
validator_level: ValidationSeverity
|
118
|
+
The severity level of the validation report. Defaults to ValidationSeverity.LOW.
|
119
|
+
validator_name: str | None
|
120
|
+
The name of the validator. Defaults to the PascalCase version of the function name.
|
113
121
|
"""
|
122
|
+
if func is None:
|
123
|
+
return partial(
|
124
|
+
liminal_validator,
|
125
|
+
validator_level=validator_level,
|
126
|
+
validator_name=validator_name,
|
127
|
+
)
|
128
|
+
elif not isinstance(
|
129
|
+
func, Callable[[type["BenchlingBaseModel"]], BenchlingValidatorReport | None]
|
130
|
+
):
|
131
|
+
raise ValueError(
|
132
|
+
"Parameters passed to liminal_validator must be keyword arguments, not positional arguments."
|
133
|
+
)
|
114
134
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
if sig.return_annotation is not None:
|
125
|
-
raise TypeError("The return type must be None.")
|
126
|
-
|
127
|
-
nonlocal validator_name
|
128
|
-
if validator_name is None:
|
129
|
-
validator_name = pascalize(func.__name__)
|
130
|
-
|
131
|
-
@wraps(func)
|
132
|
-
def wrapper(self: type["BenchlingBaseModel"]) -> BenchlingValidatorReport:
|
133
|
-
"""Wrapper that runs the validator function and returns a BenchlingValidatorReport."""
|
134
|
-
try:
|
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
|
-
)
|
135
|
+
@wraps(func)
|
136
|
+
def wrapper(self: type["BenchlingBaseModel"]) -> BenchlingValidatorReport:
|
137
|
+
"""Wrapper that runs the validator function and returns a BenchlingValidatorReport."""
|
138
|
+
try:
|
139
|
+
ret_val = func(self)
|
140
|
+
if type(ret_val) is BenchlingValidatorReport:
|
141
|
+
return ret_val
|
142
|
+
except Exception as e:
|
144
143
|
return BenchlingValidatorReport.create_validation_report(
|
145
|
-
valid=
|
144
|
+
valid=False,
|
146
145
|
level=validator_level,
|
147
146
|
entity=self,
|
148
|
-
validator_name=validator_name,
|
147
|
+
validator_name=validator_name or pascalize(func.__name__),
|
148
|
+
message=str(e),
|
149
149
|
)
|
150
|
+
return BenchlingValidatorReport.create_validation_report(
|
151
|
+
valid=True,
|
152
|
+
level=validator_level,
|
153
|
+
entity=self,
|
154
|
+
validator_name=validator_name or pascalize(func.__name__),
|
155
|
+
)
|
150
156
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
return decorator
|
157
|
+
setattr(wrapper, "_is_liminal_validator", True)
|
158
|
+
return wrapper
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: liminal-orm
|
3
|
-
Version: 2.0.
|
3
|
+
Version: 2.0.3a0
|
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=p9VoX4rYnDE1DHr2BOnZmRklX6LBNeerlVLPvvr6y0Y,5562
|
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.3a0.dist-info/LICENSE.md,sha256=oVA877F_D1AV44dpjsv4f-4k690uNGApX1EtzOo3T8U,11353
|
65
|
+
liminal_orm-2.0.3a0.dist-info/METADATA,sha256=ANm_kbsM-VMU2lpUnbHutpmlWDyrOYmU1Rg_Zkhsq0c,11034
|
66
|
+
liminal_orm-2.0.3a0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
67
|
+
liminal_orm-2.0.3a0.dist-info/entry_points.txt,sha256=atIrU63rrzH81dWC2sjUbFLlc5FWMmYRdMxXEWexIZA,47
|
68
|
+
liminal_orm-2.0.3a0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|