sapiopycommons 2025.7.9a582__py3-none-any.whl → 2025.7.9a583__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.
Potentially problematic release.
This version of sapiopycommons might be problematic. Click here for more details.
- sapiopycommons/callbacks/callback_util.py +665 -332
- sapiopycommons/callbacks/field_builder.py +2 -0
- sapiopycommons/chem/IndigoMolecules.py +29 -1
- sapiopycommons/chem/Molecules.py +3 -3
- sapiopycommons/customreport/auto_pagers.py +26 -1
- sapiopycommons/customreport/term_builder.py +1 -1
- sapiopycommons/datatype/pseudo_data_types.py +349 -326
- sapiopycommons/eln/experiment_cache.py +188 -0
- sapiopycommons/eln/experiment_handler.py +408 -767
- sapiopycommons/eln/experiment_report_util.py +11 -6
- sapiopycommons/eln/experiment_step_factory.py +476 -0
- sapiopycommons/eln/plate_designer.py +7 -2
- sapiopycommons/eln/step_creation.py +236 -0
- sapiopycommons/files/file_util.py +7 -5
- sapiopycommons/general/accession_service.py +2 -2
- sapiopycommons/general/aliases.py +3 -1
- sapiopycommons/general/audit_log.py +7 -0
- sapiopycommons/general/custom_report_util.py +12 -0
- sapiopycommons/general/data_structure_util.py +115 -0
- sapiopycommons/processtracking/custom_workflow_handler.py +11 -1
- sapiopycommons/processtracking/endpoints.py +27 -0
- sapiopycommons/recordmodel/record_handler.py +783 -389
- sapiopycommons/rules/eln_rule_handler.py +8 -1
- sapiopycommons/rules/on_save_rule_handler.py +8 -1
- sapiopycommons/webhook/webhook_handlers.py +9 -4
- sapiopycommons/webhook/webservice_handlers.py +2 -2
- {sapiopycommons-2025.7.9a582.dist-info → sapiopycommons-2025.7.9a583.dist-info}/METADATA +2 -2
- sapiopycommons-2025.7.9a583.dist-info/RECORD +68 -0
- sapiopycommons/ai/__init__.py +0 -0
- sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.py +0 -43
- sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.pyi +0 -31
- sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.py +0 -123
- sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.pyi +0 -598
- sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/plan/proto/step_output_pb2.py +0 -45
- sapiopycommons/ai/api/plan/proto/step_output_pb2.pyi +0 -42
- sapiopycommons/ai/api/plan/proto/step_output_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/plan/proto/step_pb2.py +0 -43
- sapiopycommons/ai/api/plan/proto/step_pb2.pyi +0 -43
- sapiopycommons/ai/api/plan/proto/step_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/plan/script/proto/script_pb2.py +0 -55
- sapiopycommons/ai/api/plan/script/proto/script_pb2.pyi +0 -115
- sapiopycommons/ai/api/plan/script/proto/script_pb2_grpc.py +0 -153
- sapiopycommons/ai/api/plan/tool/proto/entry_pb2.py +0 -57
- sapiopycommons/ai/api/plan/tool/proto/entry_pb2.pyi +0 -96
- sapiopycommons/ai/api/plan/tool/proto/entry_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/plan/tool/proto/tool_pb2.py +0 -67
- sapiopycommons/ai/api/plan/tool/proto/tool_pb2.pyi +0 -220
- sapiopycommons/ai/api/plan/tool/proto/tool_pb2_grpc.py +0 -154
- sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.py +0 -39
- sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.pyi +0 -32
- sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2_grpc.py +0 -24
- sapiopycommons/ai/protobuf_utils.py +0 -508
- sapiopycommons/ai/test_client.py +0 -251
- sapiopycommons/ai/tool_service_base.py +0 -798
- sapiopycommons-2025.7.9a582.dist-info/RECORD +0 -92
- {sapiopycommons-2025.7.9a582.dist-info → sapiopycommons-2025.7.9a583.dist-info}/WHEEL +0 -0
- {sapiopycommons-2025.7.9a582.dist-info → sapiopycommons-2025.7.9a583.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from weakref import WeakValueDictionary
|
|
4
|
+
|
|
5
|
+
from sapiopylib.rest.ELNService import ElnManager
|
|
6
|
+
from sapiopylib.rest.User import SapioUser
|
|
7
|
+
from sapiopylib.rest.pojo.datatype.FieldDefinition import AbstractVeloxFieldDefinition
|
|
8
|
+
from sapiopylib.rest.pojo.eln.ElnExperiment import ElnTemplate, TemplateExperimentQuery
|
|
9
|
+
from sapiopylib.rest.pojo.eln.SapioELNEnums import ElnBaseDataType
|
|
10
|
+
from sapiopylib.rest.pojo.eln.field_set import ElnFieldSetInfo
|
|
11
|
+
from sapiopylib.rest.pojo.eln.protocol_template import ProtocolTemplateInfo, ProtocolTemplateQuery
|
|
12
|
+
|
|
13
|
+
from sapiopycommons.general.aliases import UserIdentifier, AliasUtil
|
|
14
|
+
from sapiopycommons.general.exceptions import SapioException
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# FR-47530: Created a class that caches experiment template and predefined field information.
|
|
18
|
+
class ExperimentCacheManager:
|
|
19
|
+
"""
|
|
20
|
+
A class to manage the caching of experiment-related information.
|
|
21
|
+
"""
|
|
22
|
+
user: SapioUser
|
|
23
|
+
eln_man: ElnManager
|
|
24
|
+
|
|
25
|
+
_templates: list[ElnTemplate]
|
|
26
|
+
"""A list of experiment templates. Only cached when first accessed."""
|
|
27
|
+
_protocols: list[ProtocolTemplateInfo]
|
|
28
|
+
"""A list of protocol templates. Only cached when first accessed."""
|
|
29
|
+
_field_sets: dict[str, ElnFieldSetInfo]
|
|
30
|
+
"""A dictionary of field set name to field set. Only cached when first accessed."""
|
|
31
|
+
_field_set_fields: dict[int, list[AbstractVeloxFieldDefinition]]
|
|
32
|
+
"""A dictionary of field set ID to field definitions. Only cached when first accessed."""
|
|
33
|
+
_predefined_fields: dict[str, dict[str, AbstractVeloxFieldDefinition]]
|
|
34
|
+
"""A dictionary of ELN data type name to predefined field definitions. Only cached when first accessed."""
|
|
35
|
+
|
|
36
|
+
__instances: WeakValueDictionary[SapioUser, ExperimentCacheManager] = WeakValueDictionary()
|
|
37
|
+
__initialized: bool
|
|
38
|
+
|
|
39
|
+
def __new__(cls, context: UserIdentifier):
|
|
40
|
+
"""
|
|
41
|
+
:param context: The current webhook context or a user object to send requests from.
|
|
42
|
+
"""
|
|
43
|
+
user = AliasUtil.to_sapio_user(context)
|
|
44
|
+
obj = cls.__instances.get(user)
|
|
45
|
+
if not obj:
|
|
46
|
+
obj = object.__new__(cls)
|
|
47
|
+
obj.__initialized = False
|
|
48
|
+
cls.__instances[user] = obj
|
|
49
|
+
return obj
|
|
50
|
+
|
|
51
|
+
def __init__(self, context: UserIdentifier):
|
|
52
|
+
"""
|
|
53
|
+
:param context: The current webhook context or a user object to send requests from.
|
|
54
|
+
"""
|
|
55
|
+
if self.__initialized:
|
|
56
|
+
return
|
|
57
|
+
self.__initialized = True
|
|
58
|
+
|
|
59
|
+
self.user = AliasUtil.to_sapio_user(context)
|
|
60
|
+
self.eln_man = ElnManager(self.user)
|
|
61
|
+
|
|
62
|
+
self._field_set_fields = {}
|
|
63
|
+
self._predefined_fields = {}
|
|
64
|
+
|
|
65
|
+
def get_experiment_template(self, name: str, active: bool = True, version: int | None = None,
|
|
66
|
+
first_match: bool = False, public: bool | None = True) -> ElnTemplate:
|
|
67
|
+
"""
|
|
68
|
+
Get the experiment template with the given information.
|
|
69
|
+
|
|
70
|
+
:param name: The name of the template.
|
|
71
|
+
:param active: Whether the template is marked as active.
|
|
72
|
+
:param version: The version of the template to get. If None, the latest version will be returned.
|
|
73
|
+
:param first_match: If true, returns the first match found. If false, raises an exception.
|
|
74
|
+
:param public: Whether the template is public. If true, only pubic templates will be queried. If false, only
|
|
75
|
+
private templates will be queried. If None, both public and private templates will be queried. Non-public
|
|
76
|
+
templates do not have a version number, so this will always fail if public is false and a version number is
|
|
77
|
+
provided.
|
|
78
|
+
:return: The experiment template with the given information.
|
|
79
|
+
"""
|
|
80
|
+
if not hasattr(self, "_templates"):
|
|
81
|
+
query = TemplateExperimentQuery()
|
|
82
|
+
query.active_templates_only = False
|
|
83
|
+
query.latest_version_only = False
|
|
84
|
+
self._templates = self.eln_man.get_template_experiment_list(query)
|
|
85
|
+
return self._find_template(self._templates, name, active, version, first_match, public)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def get_protocol_template(self, name: str, active: bool = True, version: int | None = None,
|
|
89
|
+
first_match: bool = False, public: bool | None = True) -> ProtocolTemplateInfo:
|
|
90
|
+
"""
|
|
91
|
+
Get the protocol template with the given information. Will throw an exception if multiple templates match
|
|
92
|
+
the given information.
|
|
93
|
+
|
|
94
|
+
:param name: The name of the template.
|
|
95
|
+
:param active: Whether the template is marked as active.
|
|
96
|
+
:param version: The version of the template to get. If None, the latest version will be returned.
|
|
97
|
+
:param first_match: If true, returns the first match found. If false, raises an exception.
|
|
98
|
+
:param public: Whether the template is public. If true, only pubic templates will be queried. If false, only
|
|
99
|
+
private templates will be queried. If None, both public and private templates will be queried. Non-public
|
|
100
|
+
templates do not have a version number, so this will always fail if public is false and a version number is
|
|
101
|
+
provided.
|
|
102
|
+
:return: The protocol template with the given information.
|
|
103
|
+
"""
|
|
104
|
+
if not hasattr(self, "_protocols"):
|
|
105
|
+
query = ProtocolTemplateQuery()
|
|
106
|
+
query.active_templates_only = False
|
|
107
|
+
query.latest_version_only = False
|
|
108
|
+
self._protocols = self.eln_man.get_protocol_template_info_list(query)
|
|
109
|
+
return self._find_template(self._protocols, name, active, version, first_match, public)
|
|
110
|
+
|
|
111
|
+
@staticmethod
|
|
112
|
+
def _find_template(templates: list[ElnTemplate] | list[ProtocolTemplateInfo], name: str, active: bool,
|
|
113
|
+
version: int, first_match: bool, public: bool | None) -> ElnTemplate | ProtocolTemplateInfo:
|
|
114
|
+
"""
|
|
115
|
+
Find the experiment or protocol template with the given information.
|
|
116
|
+
"""
|
|
117
|
+
matches = []
|
|
118
|
+
for template in templates:
|
|
119
|
+
if template.template_name != name:
|
|
120
|
+
continue
|
|
121
|
+
if template.active != active:
|
|
122
|
+
continue
|
|
123
|
+
if version is not None and template.template_version != version:
|
|
124
|
+
continue
|
|
125
|
+
if public is True and template.template_version is None:
|
|
126
|
+
continue
|
|
127
|
+
if public is False and template.template_version is not None:
|
|
128
|
+
continue
|
|
129
|
+
matches.append(template)
|
|
130
|
+
if not matches:
|
|
131
|
+
raise SapioException(f"No template with the name \"{name}\"" +
|
|
132
|
+
("" if version is None else f" and the version {version}") +
|
|
133
|
+
f" found.")
|
|
134
|
+
# Only filter for the max version number if any of the matches actually have a version number.
|
|
135
|
+
versioned_matches = [x for x in matches if x.template_version is not None]
|
|
136
|
+
if version is None and versioned_matches:
|
|
137
|
+
return max(versioned_matches, key=lambda x: x.template_version)
|
|
138
|
+
if len(matches) > 1 and not first_match:
|
|
139
|
+
raise SapioException(f"Multiple templates with the name \"{name}\" found. Consider setting first_match to "
|
|
140
|
+
f"true, or restrict your search criteria further.")
|
|
141
|
+
return matches[0]
|
|
142
|
+
|
|
143
|
+
def get_predefined_field(self, field_name: str, data_type: ElnBaseDataType) -> AbstractVeloxFieldDefinition:
|
|
144
|
+
"""
|
|
145
|
+
Get the predefined field of the given name for the given ELN data type.
|
|
146
|
+
|
|
147
|
+
:param field_name: The name of the field.
|
|
148
|
+
:param data_type: The ELN data type of the field.
|
|
149
|
+
:return: The predefined field of the given name for the given ELN data type.
|
|
150
|
+
"""
|
|
151
|
+
return self.get_predefined_fields(data_type)[field_name]
|
|
152
|
+
|
|
153
|
+
def get_predefined_fields(self, data_type: ElnBaseDataType) -> dict[str, AbstractVeloxFieldDefinition]:
|
|
154
|
+
"""
|
|
155
|
+
Get the predefined fields for the given ELN data type.
|
|
156
|
+
|
|
157
|
+
:param data_type: The ELN data type to get the predefined fields for.
|
|
158
|
+
:return: A dictionary of field name to field definition for the given ELN data type.
|
|
159
|
+
"""
|
|
160
|
+
if data_type.data_type_name not in self._predefined_fields:
|
|
161
|
+
fields: list[AbstractVeloxFieldDefinition] = self.eln_man.get_predefined_fields(data_type)
|
|
162
|
+
self._predefined_fields[data_type.data_type_name] = {x.data_field_name: x for x in fields}
|
|
163
|
+
return self._predefined_fields[data_type.data_type_name]
|
|
164
|
+
|
|
165
|
+
def get_field_set(self, name: str) -> ElnFieldSetInfo:
|
|
166
|
+
"""
|
|
167
|
+
Get the field set with the given name.
|
|
168
|
+
|
|
169
|
+
:param name: The name of the field set.
|
|
170
|
+
:return: The field set with the given name.
|
|
171
|
+
"""
|
|
172
|
+
if not hasattr(self, "_field_sets"):
|
|
173
|
+
self._field_sets = {x.field_set_name: x for x in self.eln_man.get_field_set_info_list()}
|
|
174
|
+
return self._field_sets[name]
|
|
175
|
+
|
|
176
|
+
def get_field_set_fields(self, field_set: ElnFieldSetInfo | int) -> list[AbstractVeloxFieldDefinition]:
|
|
177
|
+
"""
|
|
178
|
+
Get the fields of the given field set.
|
|
179
|
+
|
|
180
|
+
:param field_set: The field set to get the fields from. Can be either an ElnFieldSetInfo object or an integer
|
|
181
|
+
for the set ID.
|
|
182
|
+
:return: The fields of the given field set.
|
|
183
|
+
"""
|
|
184
|
+
field_set: int = field_set if isinstance(field_set, int) else field_set.field_set_id
|
|
185
|
+
if field_set in self._field_set_fields:
|
|
186
|
+
return self._field_set_fields[field_set]
|
|
187
|
+
self._field_set_fields[field_set] = self.eln_man.get_predefined_fields_from_field_set_id(field_set)
|
|
188
|
+
return self._field_set_fields[field_set]
|