deriva-ml 1.17.10__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.
- deriva_ml/.DS_Store +0 -0
- deriva_ml/__init__.py +79 -0
- deriva_ml/bump_version.py +142 -0
- deriva_ml/core/__init__.py +39 -0
- deriva_ml/core/base.py +1527 -0
- deriva_ml/core/config.py +69 -0
- deriva_ml/core/constants.py +36 -0
- deriva_ml/core/definitions.py +74 -0
- deriva_ml/core/enums.py +222 -0
- deriva_ml/core/ermrest.py +288 -0
- deriva_ml/core/exceptions.py +28 -0
- deriva_ml/core/filespec.py +116 -0
- deriva_ml/dataset/__init__.py +12 -0
- deriva_ml/dataset/aux_classes.py +225 -0
- deriva_ml/dataset/dataset.py +1519 -0
- deriva_ml/dataset/dataset_bag.py +450 -0
- deriva_ml/dataset/history.py +109 -0
- deriva_ml/dataset/upload.py +439 -0
- deriva_ml/demo_catalog.py +495 -0
- deriva_ml/execution/__init__.py +26 -0
- deriva_ml/execution/environment.py +290 -0
- deriva_ml/execution/execution.py +1180 -0
- deriva_ml/execution/execution_configuration.py +147 -0
- deriva_ml/execution/workflow.py +413 -0
- deriva_ml/feature.py +228 -0
- deriva_ml/install_kernel.py +71 -0
- deriva_ml/model/__init__.py +0 -0
- deriva_ml/model/catalog.py +485 -0
- deriva_ml/model/database.py +719 -0
- deriva_ml/protocols/dataset.py +19 -0
- deriva_ml/run_notebook.py +228 -0
- deriva_ml/schema/__init__.py +3 -0
- deriva_ml/schema/annotations.py +473 -0
- deriva_ml/schema/check_schema.py +104 -0
- deriva_ml/schema/create_schema.py +393 -0
- deriva_ml/schema/deriva-ml-reference.json +8525 -0
- deriva_ml/schema/policy.json +81 -0
- deriva_ml/schema/table_comments_utils.py +57 -0
- deriva_ml/test.py +94 -0
- deriva_ml-1.17.10.dist-info/METADATA +38 -0
- deriva_ml-1.17.10.dist-info/RECORD +45 -0
- deriva_ml-1.17.10.dist-info/WHEEL +5 -0
- deriva_ml-1.17.10.dist-info/entry_points.txt +9 -0
- deriva_ml-1.17.10.dist-info/licenses/LICENSE +201 -0
- deriva_ml-1.17.10.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"""Environment information collection for DerivaML executions.
|
|
2
|
+
|
|
3
|
+
This module captures detailed information about the execution environment for DerivaML
|
|
4
|
+
processes. It collects:
|
|
5
|
+
|
|
6
|
+
- Python environment: Installed packages, sys.path, site configuration
|
|
7
|
+
- Operating system: Platform details, user info, environment variables
|
|
8
|
+
- System settings: Locale, encoding, file system details
|
|
9
|
+
- Runtime state: Command line arguments, Python interpreter info
|
|
10
|
+
|
|
11
|
+
This information is stored as execution metadata to ensure reproducibility and
|
|
12
|
+
debugging capabilities.
|
|
13
|
+
|
|
14
|
+
Typical usage example:
|
|
15
|
+
>>> env = get_execution_environment()
|
|
16
|
+
>>> print(f"Python version: {env['platform']['python_version']}")
|
|
17
|
+
>>> print(f"Operating system: {env['os']['name']}")
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import importlib.metadata
|
|
21
|
+
import locale
|
|
22
|
+
import os
|
|
23
|
+
import platform
|
|
24
|
+
import site
|
|
25
|
+
import sys
|
|
26
|
+
from typing import Any, Dict
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_execution_environment() -> Dict[str, Any]:
|
|
30
|
+
"""Collects comprehensive information about the execution environment.
|
|
31
|
+
|
|
32
|
+
Gathers information about the Python environment, operating system, and runtime
|
|
33
|
+
configuration. This provides a complete snapshot of the execution context.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
Dict[str, Any]: Environment information including:
|
|
37
|
+
- imports: Installed Python packages and versions
|
|
38
|
+
- os: Operating system details and user info
|
|
39
|
+
- sys: Python interpreter configuration
|
|
40
|
+
- sys_path: Module search paths
|
|
41
|
+
- site: Python site configuration
|
|
42
|
+
- platform: Detailed platform information
|
|
43
|
+
|
|
44
|
+
Example:
|
|
45
|
+
>>> env = get_execution_environment()
|
|
46
|
+
>>> print(f"Python: {env['platform']['python_version']}")
|
|
47
|
+
>>> print(f"OS: {env['platform']['system']}")
|
|
48
|
+
"""
|
|
49
|
+
return dict(
|
|
50
|
+
imports=get_loaded_modules(),
|
|
51
|
+
os=get_os_info(),
|
|
52
|
+
sys=get_sys_info(),
|
|
53
|
+
sys_path=sys.path,
|
|
54
|
+
site=get_site_info(),
|
|
55
|
+
platform=get_platform_info(),
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def get_loaded_modules() -> Dict[str, str]:
|
|
60
|
+
"""Gets information about installed Python packages.
|
|
61
|
+
|
|
62
|
+
Returns a mapping of package names to their installed versions using
|
|
63
|
+
Python's importlib.metadata.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
Dict[str, str]: Mapping of package names to version strings.
|
|
67
|
+
|
|
68
|
+
Example:
|
|
69
|
+
>>> modules = get_loaded_modules()
|
|
70
|
+
>>> print(f"NumPy version: {modules.get('numpy')}")
|
|
71
|
+
"""
|
|
72
|
+
return {dist.metadata["Name"]: dist.version for dist in importlib.metadata.distributions()}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def get_site_info() -> Dict[str, Any]:
|
|
76
|
+
"""Gets Python site configuration information.
|
|
77
|
+
|
|
78
|
+
Returns information about Python's site configuration, including paths
|
|
79
|
+
for user-specific packages and site-packages directories.
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
Dict[str, Any]: Site configuration including:
|
|
83
|
+
- PREFIXES: Installation prefixes
|
|
84
|
+
- ENABLE_USER_SITE: Whether user site-packages is enabled
|
|
85
|
+
- USER_SITE: Path to user site-packages
|
|
86
|
+
- USER_BASE: Base directory for user site-packages
|
|
87
|
+
|
|
88
|
+
Example:
|
|
89
|
+
>>> info = get_site_info()
|
|
90
|
+
>>> print(f"User site-packages: {info['USER_SITE']}")
|
|
91
|
+
"""
|
|
92
|
+
return {attr: getattr(site, attr) for attr in ["PREFIXES", "ENABLE_USER_SITE", "USER_SITE", "USER_BASE"]}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def get_platform_info() -> Dict[str, Any]:
|
|
96
|
+
"""Gets detailed platform information.
|
|
97
|
+
|
|
98
|
+
Collects all available platform information using Python's platform module.
|
|
99
|
+
This includes details about the operating system, Python version, and
|
|
100
|
+
hardware architecture.
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
Dict[str, Any]: Platform information including:
|
|
104
|
+
- system: Operating system name
|
|
105
|
+
- release: OS release version
|
|
106
|
+
- version: OS version details
|
|
107
|
+
- machine: Hardware architecture
|
|
108
|
+
- processor: Processor type
|
|
109
|
+
- python_version: Python version
|
|
110
|
+
Additional fields vary by platform.
|
|
111
|
+
|
|
112
|
+
Example:
|
|
113
|
+
>>> info = get_platform_info()
|
|
114
|
+
>>> print(f"OS: {info['system']} {info['release']}")
|
|
115
|
+
>>> print(f"Architecture: {info['machine']}")
|
|
116
|
+
"""
|
|
117
|
+
attributes: list[str] = [
|
|
118
|
+
attr for attr in dir(platform) if (not attr.startswith("_")) and callable(getattr(platform, attr))
|
|
119
|
+
]
|
|
120
|
+
platform_info: Dict[str, Any] = {}
|
|
121
|
+
for attr in attributes:
|
|
122
|
+
try:
|
|
123
|
+
platform_info[attr] = getattr(platform, attr)()
|
|
124
|
+
except Exception:
|
|
125
|
+
# Not all attributes are available on all platforms.
|
|
126
|
+
continue
|
|
127
|
+
return platform_info
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def get_os_info() -> Dict[str, Any]:
|
|
131
|
+
"""Gets operating system information.
|
|
132
|
+
|
|
133
|
+
Collects information about the operating system environment, including
|
|
134
|
+
user details, process information, and environment variables.
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
Dict[str, Any]: OS information including:
|
|
138
|
+
- cwd: Current working directory
|
|
139
|
+
- egid: Effective group ID
|
|
140
|
+
- euid: Effective user ID
|
|
141
|
+
- gid: Real group ID
|
|
142
|
+
- groups: Supplemental group IDs
|
|
143
|
+
- login: User's login name
|
|
144
|
+
- pgrp: Process group ID
|
|
145
|
+
- uid: Real user ID
|
|
146
|
+
- umask: File creation mask
|
|
147
|
+
- name: Operating system name
|
|
148
|
+
- environ: Environment variables
|
|
149
|
+
|
|
150
|
+
Example:
|
|
151
|
+
>>> info = get_os_info()
|
|
152
|
+
>>> print(f"User: {info.get('login')}")
|
|
153
|
+
>>> print(f"Working directory: {info['cwd']}")
|
|
154
|
+
"""
|
|
155
|
+
values: Dict[str, Any] = {}
|
|
156
|
+
for func in [
|
|
157
|
+
"cwd",
|
|
158
|
+
"egid",
|
|
159
|
+
"euid",
|
|
160
|
+
"gid",
|
|
161
|
+
"groups",
|
|
162
|
+
"login",
|
|
163
|
+
"pgrp",
|
|
164
|
+
"uid",
|
|
165
|
+
]:
|
|
166
|
+
try:
|
|
167
|
+
values[func] = getattr(os, "get" + func)()
|
|
168
|
+
except (OSError, AttributeError):
|
|
169
|
+
pass
|
|
170
|
+
values["umask"] = oct(get_umask())
|
|
171
|
+
values["name"] = os.name
|
|
172
|
+
values["environ"] = {e: v for e, v in os.environ.items()}
|
|
173
|
+
return values
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def get_umask() -> int:
|
|
177
|
+
"""Gets the current file creation mask.
|
|
178
|
+
|
|
179
|
+
Returns the current umask value in a thread-safe manner by temporarily
|
|
180
|
+
setting it to 0 and then restoring it.
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
int: Current umask value.
|
|
184
|
+
|
|
185
|
+
Note:
|
|
186
|
+
This implementation is based on the thread-safe approach described at:
|
|
187
|
+
https://stackoverflow.com/questions/53227072/reading-umask-thread-safe
|
|
188
|
+
"""
|
|
189
|
+
current_value: int = os.umask(0)
|
|
190
|
+
os.umask(current_value)
|
|
191
|
+
return current_value
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def get_sys_info() -> Dict[str, Any]:
|
|
195
|
+
"""Gets Python interpreter information.
|
|
196
|
+
|
|
197
|
+
Collects information about the Python interpreter configuration and
|
|
198
|
+
runtime environment.
|
|
199
|
+
|
|
200
|
+
Returns:
|
|
201
|
+
Dict[str, Any]: System information including:
|
|
202
|
+
- argv: Command line arguments
|
|
203
|
+
- byteorder: Native byte order
|
|
204
|
+
- exec_prefix: Platform-specific Python files location
|
|
205
|
+
- executable: Python interpreter path
|
|
206
|
+
- flags: Python compiler flags
|
|
207
|
+
- float_info: Floating point number info
|
|
208
|
+
- maxsize: Maximum integer size
|
|
209
|
+
- maxunicode: Maximum Unicode code point
|
|
210
|
+
- encoding settings and recursion limits
|
|
211
|
+
|
|
212
|
+
Example:
|
|
213
|
+
>>> info = get_sys_info()
|
|
214
|
+
>>> print(f"Python path: {info['executable']}")
|
|
215
|
+
>>> print(f"Arguments: {info['argv']}")
|
|
216
|
+
"""
|
|
217
|
+
values: Dict[str, Any] = {}
|
|
218
|
+
for attr in [
|
|
219
|
+
"argv",
|
|
220
|
+
"byteorder",
|
|
221
|
+
"exec_prefix",
|
|
222
|
+
"executable",
|
|
223
|
+
"flags",
|
|
224
|
+
"float_info",
|
|
225
|
+
"maxsize",
|
|
226
|
+
"maxunicode",
|
|
227
|
+
]:
|
|
228
|
+
values[attr] = getattr(sys, attr)
|
|
229
|
+
for func in [
|
|
230
|
+
"getdefaultencoding",
|
|
231
|
+
"getfilesystemencoding",
|
|
232
|
+
"getrecursionlimit",
|
|
233
|
+
]:
|
|
234
|
+
try:
|
|
235
|
+
values[func] = getattr(sys, func)()
|
|
236
|
+
except (OSError, AttributeError) as exc:
|
|
237
|
+
values[func] = exc
|
|
238
|
+
return values
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def localeconv() -> list[str]:
|
|
242
|
+
"""Gets locale convention information.
|
|
243
|
+
|
|
244
|
+
Returns formatted strings containing locale-specific formatting information
|
|
245
|
+
for numbers, currency, and other locale-dependent values.
|
|
246
|
+
|
|
247
|
+
Returns:
|
|
248
|
+
List[str]: Formatted strings with locale convention information.
|
|
249
|
+
|
|
250
|
+
Example:
|
|
251
|
+
>>> info = localeconv()
|
|
252
|
+
>>> for item in info:
|
|
253
|
+
... print(item) # e.g., "decimal_point: ."
|
|
254
|
+
"""
|
|
255
|
+
values: list[str] = []
|
|
256
|
+
for key, value in sorted(locale.localeconv().items()):
|
|
257
|
+
if isinstance(value, bytes):
|
|
258
|
+
value = value.decode("ascii", errors="replace")
|
|
259
|
+
if key == "currency_symbol":
|
|
260
|
+
value = repr(value)
|
|
261
|
+
values.append("%s: %s" % (key, value))
|
|
262
|
+
return values
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def locale_module() -> list[str]:
|
|
266
|
+
"""Gets locale settings information.
|
|
267
|
+
|
|
268
|
+
Returns formatted strings containing information about the current locale
|
|
269
|
+
settings for various categories (e.g., numeric formatting, time, etc.).
|
|
270
|
+
|
|
271
|
+
Returns:
|
|
272
|
+
List[str]: Formatted strings with locale settings.
|
|
273
|
+
|
|
274
|
+
Example:
|
|
275
|
+
>>> info = locale_module()
|
|
276
|
+
>>> for item in info:
|
|
277
|
+
... print(item) # e.g., "LC_NUMERIC: en_US.UTF-8"
|
|
278
|
+
"""
|
|
279
|
+
values: list[str] = []
|
|
280
|
+
values.append("getdefaultlocale(): {}".format(locale.getdefaultlocale()))
|
|
281
|
+
for category in [
|
|
282
|
+
"LC_CTYPE",
|
|
283
|
+
"LC_COLLATE",
|
|
284
|
+
"LC_TIME",
|
|
285
|
+
"LC_MONETARY",
|
|
286
|
+
"LC_MESSAGES",
|
|
287
|
+
"LC_NUMERIC",
|
|
288
|
+
]:
|
|
289
|
+
values.append("getlocale(locale.{}): {}".format(category, locale.getlocale(getattr(locale, category))))
|
|
290
|
+
return values
|