tracdap-runtime 0.7.0rc1__py3-none-any.whl → 0.8.0b2__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.
Files changed (52) hide show
  1. tracdap/rt/_exec/actors.py +5 -4
  2. tracdap/rt/_exec/context.py +166 -74
  3. tracdap/rt/_exec/dev_mode.py +147 -71
  4. tracdap/rt/_exec/engine.py +224 -99
  5. tracdap/rt/_exec/functions.py +122 -80
  6. tracdap/rt/_exec/graph.py +23 -35
  7. tracdap/rt/_exec/graph_builder.py +250 -113
  8. tracdap/rt/_exec/runtime.py +24 -10
  9. tracdap/rt/_exec/server.py +4 -3
  10. tracdap/rt/_impl/config_parser.py +3 -2
  11. tracdap/rt/_impl/data.py +89 -16
  12. tracdap/rt/_impl/grpc/tracdap/metadata/file_pb2.py +3 -1
  13. tracdap/rt/_impl/grpc/tracdap/metadata/file_pb2.pyi +8 -0
  14. tracdap/rt/_impl/grpc/tracdap/metadata/job_pb2.py +64 -62
  15. tracdap/rt/_impl/grpc/tracdap/metadata/job_pb2.pyi +16 -2
  16. tracdap/rt/_impl/grpc/tracdap/metadata/model_pb2.py +27 -25
  17. tracdap/rt/_impl/grpc/tracdap/metadata/model_pb2.pyi +14 -4
  18. tracdap/rt/_impl/grpc/tracdap/metadata/object_id_pb2.py +3 -3
  19. tracdap/rt/_impl/grpc/tracdap/metadata/object_id_pb2.pyi +2 -0
  20. tracdap/rt/_impl/grpc/tracdap/metadata/object_pb2.py +4 -4
  21. tracdap/rt/_impl/grpc/tracdap/metadata/object_pb2.pyi +4 -2
  22. tracdap/rt/_impl/logging.py +195 -0
  23. tracdap/rt/_impl/models.py +11 -8
  24. tracdap/rt/_impl/repos.py +5 -3
  25. tracdap/rt/_impl/schemas.py +2 -2
  26. tracdap/rt/_impl/shim.py +3 -2
  27. tracdap/rt/_impl/static_api.py +53 -33
  28. tracdap/rt/_impl/storage.py +4 -3
  29. tracdap/rt/_impl/util.py +1 -111
  30. tracdap/rt/_impl/validation.py +57 -30
  31. tracdap/rt/_version.py +1 -1
  32. tracdap/rt/api/__init__.py +6 -3
  33. tracdap/rt/api/file_types.py +29 -0
  34. tracdap/rt/api/hook.py +15 -7
  35. tracdap/rt/api/model_api.py +16 -0
  36. tracdap/rt/api/static_api.py +211 -125
  37. tracdap/rt/config/__init__.py +6 -6
  38. tracdap/rt/config/common.py +11 -1
  39. tracdap/rt/config/platform.py +4 -6
  40. tracdap/rt/ext/plugins.py +2 -2
  41. tracdap/rt/launch/launch.py +9 -11
  42. tracdap/rt/metadata/__init__.py +11 -9
  43. tracdap/rt/metadata/file.py +8 -0
  44. tracdap/rt/metadata/job.py +16 -0
  45. tracdap/rt/metadata/model.py +12 -2
  46. tracdap/rt/metadata/object.py +2 -0
  47. tracdap/rt/metadata/object_id.py +2 -0
  48. {tracdap_runtime-0.7.0rc1.dist-info → tracdap_runtime-0.8.0b2.dist-info}/METADATA +15 -15
  49. {tracdap_runtime-0.7.0rc1.dist-info → tracdap_runtime-0.8.0b2.dist-info}/RECORD +52 -50
  50. {tracdap_runtime-0.7.0rc1.dist-info → tracdap_runtime-0.8.0b2.dist-info}/WHEEL +1 -1
  51. {tracdap_runtime-0.7.0rc1.dist-info → tracdap_runtime-0.8.0b2.dist-info}/LICENSE +0 -0
  52. {tracdap_runtime-0.7.0rc1.dist-info → tracdap_runtime-0.8.0b2.dist-info}/top_level.txt +0 -0
@@ -22,6 +22,7 @@ import pathlib
22
22
 
23
23
  import tracdap.rt.metadata as meta
24
24
  import tracdap.rt.exceptions as ex
25
+ import tracdap.rt._impl.logging as log
25
26
  import tracdap.rt._impl.util as util
26
27
 
27
28
  # _Named placeholder type from API hook is needed for API type checking
@@ -74,7 +75,7 @@ class _TypeValidator:
74
75
  # Inspecting a function signature can take ~ half a second in Python 3.7
75
76
  __method_cache: tp.Dict[str, tp.Tuple[inspect.Signature, tp.Any]] = dict()
76
77
 
77
- _log: logging.Logger = util.logger_for_namespace(__name__)
78
+ _log: logging.Logger = log.logger_for_namespace(__name__)
78
79
 
79
80
  @classmethod
80
81
  def validate_signature(cls, method: tp.Callable, *args, **kwargs):
@@ -306,6 +307,9 @@ class StaticValidator:
306
307
  __reserved_identifier_pattern = re.compile("\\A(_|trac_)", re.ASCII)
307
308
  __label_length_limit = 4096
308
309
 
310
+ __file_extension_pattern = re.compile('\\A[a-zA-Z0-9]+\\Z')
311
+ __mime_type_pattern = re.compile('\\A\\w+/[-.\\w]+(?:\\+[-.\\w]+)?\\Z')
312
+
309
313
  __PRIMITIVE_TYPES = [
310
314
  meta.BasicType.BOOLEAN,
311
315
  meta.BasicType.INTEGER,
@@ -321,7 +325,7 @@ class StaticValidator:
321
325
  meta.BasicType.INTEGER,
322
326
  meta.BasicType.DATE]
323
327
 
324
- _log: logging.Logger = util.logger_for_namespace(__name__)
328
+ _log: logging.Logger = log.logger_for_namespace(__name__)
325
329
 
326
330
  @classmethod
327
331
  def is_primitive_type(cls, basic_type: meta.BasicType) -> bool:
@@ -418,49 +422,72 @@ class StaticValidator:
418
422
  cls._valid_identifiers(param.paramProps.keys(), "entry in param props")
419
423
 
420
424
  @classmethod
421
- def _check_inputs_or_outputs(cls, inputs_or_outputs):
425
+ def _check_inputs_or_outputs(cls, sockets):
422
426
 
423
- for input_name, input_schema in inputs_or_outputs.items():
427
+ for socket_name, socket in sockets.items():
424
428
 
425
- cls._log.info(f"Checking {input_name}")
429
+ if socket.objectType == meta.ObjectType.DATA:
430
+ cls._check_socket_schema(socket_name, socket)
431
+ elif socket.objectType == meta.ObjectType.FILE:
432
+ cls._check_socket_file_type(socket_name, socket)
433
+ else:
434
+ raise ex.EModelValidation(f"Invalid object type [{socket.objectType.name}] for [{socket_name}]")
426
435
 
427
- if input_schema.dynamic:
428
- if input_schema.schema and input_schema.schema.table:
429
- error = "Dynamic schemas must have schema.table = None"
430
- cls._fail(f"Invalid schema for [{input_name}]: {error}")
431
- else:
432
- continue
436
+ label = socket.label
437
+ cls._check_label(label, socket_name)
438
+
439
+ if isinstance(socket, meta.ModelInputSchema):
440
+ if socket.inputProps is not None:
441
+ cls._valid_identifiers(socket.inputProps.keys(), "entry in input props")
442
+ else:
443
+ if socket.outputProps is not None:
444
+ cls._valid_identifiers(socket.outputProps.keys(), "entry in output props")
433
445
 
434
- fields = input_schema.schema.table.fields
435
- field_names = list(map(lambda f: f.fieldName, fields))
436
- property_type = f"field in [{input_name}]"
446
+ @classmethod
447
+ def _check_socket_schema(cls, socket_name, socket):
437
448
 
438
- if len(fields) == 0:
439
- cls._fail(f"Invalid schema for [{input_name}]: No fields defined")
449
+ if socket.schema is None:
450
+ cls._fail(f"Missing schema requirement for [{socket_name}]")
451
+ return
440
452
 
441
- cls._valid_identifiers(field_names, property_type)
442
- cls._case_insensitive_duplicates(field_names, property_type)
453
+ if socket.dynamic:
454
+ if socket.schema and socket.schema.table:
455
+ error = "Dynamic schemas must have schema.table = None"
456
+ cls._fail(f"Invalid schema for [{socket_name}]: {error}")
457
+ else:
458
+ return
443
459
 
444
- for field in fields:
445
- cls._check_single_field(field, property_type)
460
+ fields = socket.schema.table.fields
461
+ field_names = list(map(lambda f: f.fieldName, fields))
462
+ property_type = f"field in [{socket_name}]"
446
463
 
447
- label = input_schema.label
448
- cls._check_label(label, input_name)
464
+ if len(fields) == 0:
465
+ cls._fail(f"Invalid schema for [{socket_name}]: No fields defined")
449
466
 
450
- if isinstance(input_schema, meta.ModelInputSchema):
451
- if input_schema.inputProps is not None:
452
- cls._valid_identifiers(input_schema.inputProps.keys(), "entry in input props")
453
- else:
454
- if input_schema.outputProps is not None:
455
- cls._valid_identifiers(input_schema.outputProps.keys(), "entry in output props")
467
+ cls._valid_identifiers(field_names, property_type)
468
+ cls._case_insensitive_duplicates(field_names, property_type)
469
+
470
+ for field in fields:
471
+ cls._check_single_field(field, property_type)
472
+
473
+ @classmethod
474
+ def _check_socket_file_type(cls, socket_name, socket):
475
+
476
+ if socket.fileType is None:
477
+ cls._fail(f"Missing file type requirement for [{socket_name}]")
478
+ return
479
+
480
+ if not cls.__file_extension_pattern.match(socket.fileType.extension):
481
+ cls._fail(f"Invalid extension [{socket.fileType.extension}] for [{socket_name}]")
482
+
483
+ if not cls.__mime_type_pattern.match(socket.fileType.mimeType):
484
+ cls._fail(f"Invalid mime type [{socket.fileType.mimeType}] for [{socket_name}]")
456
485
 
457
486
  @classmethod
458
487
  def _check_single_field(cls, field: meta.FieldSchema, property_type):
459
488
 
460
489
  # Valid identifier and not trac reserved checked separately
461
490
 
462
- cls._log.info(field.fieldName)
463
-
464
491
  if field.fieldOrder < 0:
465
492
  cls._fail(f"Invalid {property_type}: [{field.fieldName}] fieldOrder < 0")
466
493
 
tracdap/rt/_version.py CHANGED
@@ -13,4 +13,4 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- __version__ = "0.7.0rc1"
16
+ __version__ = "0.8.0b2"
@@ -17,13 +17,16 @@
17
17
  TRAC model API for Python
18
18
  """
19
19
 
20
- from .model_api import *
21
- from .static_api import *
22
-
23
20
  # Make metadata classes available to client code when importing the API package
24
21
  # Remove this import when generating docs, so metadata classes are only documented once
25
22
  from tracdap.rt.metadata import * # noqa DOCGEN_REMOVE
26
23
 
24
+ # static_api overrides some metadata types for backwards compatibility with pre-0.8 versions
25
+ # Make sure it is last in the list
26
+ from .file_types import *
27
+ from .model_api import *
28
+ from .static_api import *
29
+
27
30
  # Map basic types into the root of the API package
28
31
 
29
32
  BOOLEAN = BasicType.BOOLEAN
@@ -0,0 +1,29 @@
1
+ # Licensed to the Fintech Open Source Foundation (FINOS) under one or
2
+ # more contributor license agreements. See the NOTICE file distributed
3
+ # with this work for additional information regarding copyright ownership.
4
+ # FINOS licenses this file to you under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ from tracdap.rt.metadata import * # DOCGEN_REMOVE
17
+
18
+
19
+ class CommonFileTypes:
20
+
21
+ TXT = FileType("txt", "text/plain")
22
+
23
+ JPG = FileType("jpg", "image/jpeg")
24
+ PNG = FileType("png", "image/png")
25
+ SVG = FileType("svg", "image/svg+xml")
26
+
27
+ WORD = FileType("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
28
+ EXCEL = FileType("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
29
+ POWERPOINT = FileType("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation")
tracdap/rt/api/hook.py CHANGED
@@ -116,7 +116,7 @@ class _StaticApiHook:
116
116
  @_abc.abstractmethod
117
117
  def define_schema(
118
118
  self, *fields: _tp.Union[_meta.FieldSchema, _tp.List[_meta.FieldSchema]],
119
- schema_type: _meta.SchemaType = _meta.SchemaType.TABLE) \
119
+ schema_type: _meta.SchemaType = _meta.SchemaType.TABLE, dynamic: bool = False) \
120
120
  -> _meta.SchemaDefinition:
121
121
 
122
122
  pass
@@ -131,21 +131,29 @@ class _StaticApiHook:
131
131
 
132
132
  @_abc.abstractmethod
133
133
  def infer_schema(self, dataset: _tp.Any) -> _meta.SchemaDefinition:
134
+
134
135
  pass
135
136
 
136
137
  @_abc.abstractmethod
137
- def define_input_table(
138
- self, *fields: _tp.Union[_meta.FieldSchema, _tp.List[_meta.FieldSchema]],
139
- label: _tp.Optional[str] = None, optional: bool = False, dynamic: bool = False,
138
+ def define_file_type(self, extension: str, mime_type: str) -> _meta.FileType:
139
+
140
+ pass
141
+
142
+ @_abc.abstractmethod
143
+ def define_input(
144
+ self, requirement: _tp.Union[_meta.SchemaDefinition, _meta.FileType], *,
145
+ label: _tp.Optional[str] = None,
146
+ optional: bool = False, dynamic: bool = False,
140
147
  input_props: _tp.Optional[_tp.Dict[str, _tp.Any]] = None) \
141
148
  -> _meta.ModelInputSchema:
142
149
 
143
150
  pass
144
151
 
145
152
  @_abc.abstractmethod
146
- def define_output_table(
147
- self, *fields: _tp.Union[_meta.FieldSchema, _tp.List[_meta.FieldSchema]],
148
- label: _tp.Optional[str] = None, optional: bool = False, dynamic: bool = False,
153
+ def define_output(
154
+ self, requirement: _tp.Union[_meta.SchemaDefinition, _meta.FileType], *,
155
+ label: _tp.Optional[str] = None,
156
+ optional: bool = False, dynamic: bool = False,
149
157
  output_props: _tp.Optional[_tp.Dict[str, _tp.Any]] = None) \
150
158
  -> _meta.ModelOutputSchema:
151
159
 
@@ -194,6 +194,14 @@ class TracContext(metaclass=_abc.ABCMeta):
194
194
 
195
195
  pass
196
196
 
197
+ def get_file(self, file_name: str) -> bytes:
198
+
199
+ pass
200
+
201
+ def get_file_stream(self, file_name: str) -> _tp.ContextManager[_tp.BinaryIO]:
202
+
203
+ pass
204
+
197
205
  def put_schema(self, dataset_name: str, schema: SchemaDefinition):
198
206
 
199
207
  """
@@ -283,6 +291,14 @@ class TracContext(metaclass=_abc.ABCMeta):
283
291
 
284
292
  pass
285
293
 
294
+ def put_file(self, file_name: str, file_content: _tp.Union[bytes, bytearray]):
295
+
296
+ pass
297
+
298
+ def put_file_stream(self, file_name: str) -> _tp.ContextManager[_tp.BinaryIO]:
299
+
300
+ pass
301
+
286
302
  def log(self) -> _logging.Logger:
287
303
 
288
304
  """
@@ -162,35 +162,6 @@ def define_parameter(
162
162
  return sa.define_parameter(param_name, param_type, label, default_value, param_props=param_props)
163
163
 
164
164
 
165
- def declare_parameter(
166
- param_name: str,
167
- param_type: _tp.Union[BasicType, TypeDescriptor],
168
- label: str,
169
- default_value: _tp.Optional[_tp.Any] = None) \
170
- -> _Named[ModelParameter]:
171
-
172
- """
173
- .. deprecated:: 0.4.4
174
- Use :py:func:`define_parameter` or :py:func:`P` instead.
175
-
176
- This function is deprecated and will be removed in a future version.
177
- Please use :py:func:`define_parameter() <tracdap.rt.api.define_parameter>` instead.
178
-
179
- :type param_name: str
180
- :type param_type: :py:class:`BasicType <tracdap.rt.metadata.BasicType>` |
181
- :py:class:`TypeDescriptor <tracdap.rt.metadata.TypeDescriptor>`
182
-
183
- :type label: str
184
- :type default_value: Any | None
185
- :rtype: _Named[:py:class:`ModelParameter <tracdap.rt.metadata.ModelParameter>`]
186
-
187
- :display: False
188
- """
189
-
190
- print("TRAC Warning: declare_parameter() is deprecated, please use define_parameter()", file=sys.stderr)
191
-
192
- return define_parameter(param_name, param_type, label, default_value)
193
-
194
165
 
195
166
  def P( # noqa
196
167
  param_name: str,
@@ -241,29 +212,6 @@ def define_parameters(
241
212
  return sa.define_parameters(*parameters)
242
213
 
243
214
 
244
- def declare_parameters(
245
- *params: _tp.Union[_Named[ModelParameter], _tp.List[_Named[ModelParameter]]]) \
246
- -> _tp.Dict[str, ModelParameter]:
247
-
248
- """
249
- .. deprecated:: 0.4.4
250
- Use :py:func:`define_parameters` instead
251
-
252
- This function is deprecated and will be removed in a future version.
253
- Please use :py:func:`define_parameters() <tracdap.rt.api.define_parameters>` instead.
254
-
255
- :type params: _Named[:py:class:`ModelParameter <tracdap.rt.metadata.ModelParameter>`] |
256
- List[_Named[:py:class:`ModelParameter <tracdap.rt.metadata.ModelParameter>`]]
257
- :rtype: Dict[str, :py:class:`ModelParameter <tracdap.rt.metadata.ModelParameter>`]
258
-
259
- :display: False
260
- """
261
-
262
- print("TRAC Warning: declare_parameters() is deprecated, please use define_parameters()", file=sys.stderr)
263
-
264
- return define_parameters(*params)
265
-
266
-
267
215
  def define_field(
268
216
  field_name: str,
269
217
  field_type: BasicType,
@@ -324,45 +272,6 @@ def define_field(
324
272
  format_code, field_order)
325
273
 
326
274
 
327
- def declare_field(
328
- field_name: str,
329
- field_type: BasicType,
330
- label: str,
331
- business_key: bool = False,
332
- categorical: bool = False,
333
- not_null: _tp.Optional[bool] = None,
334
- format_code: _tp.Optional[str] = None,
335
- field_order: _tp.Optional[int] = None) \
336
- -> FieldSchema:
337
-
338
- """
339
- .. deprecated:: 0.4.4
340
- Use :py:func:`define_field` or :py:func:`F` instead.
341
-
342
- This function is deprecated and will be removed in a future version.
343
- Please use :py:func:`define_field() <tracdap.rt.api.define_field>` instead.
344
-
345
- :type field_name: str
346
- :type field_type: :py:class:`BasicType <tracdap.rt.metadata.BasicType>`
347
- :type label: str
348
- :type business_key: bool
349
- :type categorical: bool
350
- :type not_null: bool | None
351
- :type format_code: str | None
352
- :type field_order: int | None
353
- :rtype: :py:class:`FieldSchema <tracdap.rt.metadata.FieldSchema>`
354
-
355
- :display: False
356
- """
357
-
358
- print("TRAC Warning: declare_field() is deprecated, please use define_field()", file=sys.stderr)
359
-
360
- return define_field(
361
- field_name, field_type, label,
362
- business_key, categorical, not_null,
363
- format_code, field_order)
364
-
365
-
366
275
  def F( # noqa
367
276
  field_name: str,
368
277
  field_type: BasicType,
@@ -396,7 +305,7 @@ def F( # noqa
396
305
 
397
306
  def define_schema(
398
307
  *fields: _tp.Union[FieldSchema, _tp.List[FieldSchema]],
399
- schema_type: SchemaType = SchemaType.TABLE) \
308
+ schema_type: SchemaType = SchemaType.TABLE, dynamic: bool = False) \
400
309
  -> SchemaDefinition:
401
310
 
402
311
  """
@@ -416,16 +325,18 @@ def define_schema(
416
325
 
417
326
  :param fields: The list of fields to include in the schema
418
327
  :param schema_type: The type of schema to create (currently only TABLE schemas are supported)
328
+ :param dynamic: Define a dynamic schema (fields list should be empty)
419
329
  :return: A schema definition built from the supplied fields
420
330
 
421
331
  :type fields: :py:class:`FieldSchema <tracdap.rt.metadata.FieldSchema>` |
422
332
  List[:py:class:`FieldSchema <tracdap.rt.metadata.FieldSchema>`]
423
333
  :type schema_type: :py:class:`SchemaType <tracdap.rt.metadata.SchemaType>`
334
+ :type dynamic: bool
424
335
  :rtype: :py:class:`SchemaDefinition <tracdap.rt.metadata.SchemaDefinition>`
425
336
  """
426
337
 
427
338
  sa = _StaticApiHook.get_instance()
428
- return sa.define_schema(*fields, schema_type=schema_type)
339
+ return sa.define_schema(*fields, schema_type=schema_type, dynamic=dynamic)
429
340
 
430
341
 
431
342
  def load_schema(
@@ -471,6 +382,32 @@ def load_schema(
471
382
  return sa.load_schema(package, schema_file, schema_type=schema_type)
472
383
 
473
384
 
385
+ def define_file_type(extension: str, mime_type: str) -> FileType:
386
+
387
+ sa = _StaticApiHook.get_instance()
388
+ return sa.define_file_type(extension, mime_type)
389
+
390
+
391
+ def define_input(
392
+ requirement: _tp.Union[SchemaDefinition, FileType], *,
393
+ label: _tp.Optional[str] = None,
394
+ optional: bool = False, dynamic: bool = False,
395
+ input_props: _tp.Optional[_tp.Dict[str, _tp.Any]] = None):
396
+
397
+ sa = _StaticApiHook.get_instance()
398
+ return sa.define_input(requirement, label=label, optional=optional, dynamic=dynamic, input_props=input_props)
399
+
400
+
401
+ def define_output(
402
+ requirement: _tp.Union[SchemaDefinition, FileType], *,
403
+ label: _tp.Optional[str] = None,
404
+ optional: bool = False, dynamic: bool = False,
405
+ output_props: _tp.Optional[_tp.Dict[str, _tp.Any]] = None):
406
+
407
+ sa = _StaticApiHook.get_instance()
408
+ return sa.define_output(requirement, label=label, optional=optional, dynamic=dynamic, output_props=output_props)
409
+
410
+
474
411
  def define_input_table(
475
412
  *fields: _tp.Union[FieldSchema, _tp.List[FieldSchema]],
476
413
  label: _tp.Optional[str] = None, optional: bool = False, dynamic: bool = False,
@@ -512,34 +449,8 @@ def define_input_table(
512
449
  :rtype: :py:class:`ModelInputSchema <tracdap.rt.metadata.ModelInputSchema>`
513
450
  """
514
451
 
515
- sa = _StaticApiHook.get_instance()
516
-
517
- return sa.define_input_table(
518
- *fields, label=label, optional=optional, dynamic=dynamic,
519
- input_props=input_props)
520
-
521
-
522
- def declare_input_table(
523
- *fields: _tp.Union[FieldSchema, _tp.List[FieldSchema]]) \
524
- -> ModelInputSchema:
525
-
526
- """
527
- .. deprecated:: 0.4.4
528
- Use :py:func:`define_input_table` instead.
529
-
530
- This function is deprecated and will be removed in a future version.
531
- Please use :py:func:`define_input_table() <tracdap.rt.api.define_input_table>` instead.
532
-
533
- :type fields: :py:class:`FieldSchema <tracdap.rt.metadata.FieldSchema>` |
534
- List[:py:class:`FieldSchema <tracdap.rt.metadata.FieldSchema>`]
535
- :rtype: :py:class:`ModelInputSchema <tracdap.rt.metadata.ModelInputSchema>`
536
-
537
- :display: False
538
- """
539
-
540
- print("TRAC Warning: declare_input_table() is deprecated, please use define_input_table()", file=sys.stderr)
541
-
542
- return define_input_table(*fields)
452
+ schema = define_schema(*fields, schema_type=SchemaType.TABLE, dynamic=dynamic)
453
+ return define_input(schema, label=label, optional=optional, dynamic=dynamic, input_props=input_props)
543
454
 
544
455
 
545
456
  def define_output_table(
@@ -581,11 +492,186 @@ def define_output_table(
581
492
  :rtype: :py:class:`ModelOutputSchema <tracdap.rt.metadata.ModelOutputSchema>`
582
493
  """
583
494
 
584
- sa = _StaticApiHook.get_instance()
495
+ schema = define_schema(*fields, schema_type=SchemaType.TABLE, dynamic=dynamic)
496
+ return define_output(schema, label=label, optional=optional, dynamic=dynamic, output_props=output_props)
497
+
498
+
499
+ def define_input_file(
500
+ extension: str, mime_type: str, *,
501
+ label: _tp.Optional[str] = None, optional: bool = False,
502
+ input_props: _tp.Optional[_tp.Dict[str, _tp.Any]] = None) \
503
+ -> ModelInputSchema:
504
+
505
+ file_type = define_file_type(extension, mime_type)
506
+ return define_input(file_type, label=label, optional=optional, input_props=input_props)
507
+
585
508
 
586
- return sa.define_output_table(
587
- *fields, label=label, optional=optional, dynamic=dynamic,
588
- output_props=output_props)
509
+ def define_output_file(
510
+ extension: str, mime_type: str, *,
511
+ label: _tp.Optional[str] = None, optional: bool = False,
512
+ output_props: _tp.Optional[_tp.Dict[str, _tp.Any]] = None) \
513
+ -> ModelOutputSchema:
514
+
515
+ file_type = define_file_type(extension, mime_type)
516
+ return define_output(file_type, label=label, optional=optional, output_props=output_props)
517
+
518
+
519
+ def ModelInputSchema( # noqa
520
+ schema: SchemaDefinition,
521
+ label: _tp.Optional[str] = None,
522
+ optional: bool = False,
523
+ dynamic: bool = False,
524
+ inputProps: _tp.Optional[_tp.Dict[str, Value]] = None): # noqa
525
+
526
+ """
527
+ .. deprecated:: 0.8.0
528
+ Use :py:func:`define_input` instead.
529
+
530
+ This function is provided for compatibility with TRAC versions before 0.8.0.
531
+ Please use :py:func:`define_input() <tracdap.rt.api.define_input>` instead.
532
+
533
+ :display: False
534
+ """
535
+
536
+ input_props = inputProps or dict()
537
+ return define_input(schema, label=label, optional=optional, dynamic=dynamic, input_props=input_props)
538
+
539
+
540
+ def ModelOutputSchema( # noqa
541
+ schema: SchemaDefinition,
542
+ label: _tp.Optional[str] = None,
543
+ optional: bool = False,
544
+ dynamic: bool = False,
545
+ outputProps: _tp.Optional[_tp.Dict[str, Value]] = None): # noqa
546
+
547
+ """
548
+ .. deprecated:: 0.8.0
549
+ Use :py:func:`define_output` instead.
550
+
551
+ This function is provided for compatibility with TRAC versions before 0.8.0.
552
+ Please use :py:func:`define_output() <tracdap.rt.api.define_output>` instead.
553
+
554
+ :display: False
555
+ """
556
+
557
+ output_props = outputProps or dict()
558
+ return define_output(schema, label=label, optional=optional, dynamic=dynamic, output_props=output_props)
559
+
560
+
561
+
562
+ def declare_parameter(
563
+ param_name: str,
564
+ param_type: _tp.Union[BasicType, TypeDescriptor],
565
+ label: str,
566
+ default_value: _tp.Optional[_tp.Any] = None) \
567
+ -> _Named[ModelParameter]:
568
+
569
+ """
570
+ .. deprecated:: 0.4.4
571
+ Use :py:func:`define_parameter` or :py:func:`P` instead.
572
+
573
+ This function is deprecated and will be removed in a future version.
574
+ Please use :py:func:`define_parameter() <tracdap.rt.api.define_parameter>` instead.
575
+
576
+ :type param_name: str
577
+ :type param_type: :py:class:`BasicType <tracdap.rt.metadata.BasicType>` |
578
+ :py:class:`TypeDescriptor <tracdap.rt.metadata.TypeDescriptor>`
579
+
580
+ :type label: str
581
+ :type default_value: Any | None
582
+ :rtype: _Named[:py:class:`ModelParameter <tracdap.rt.metadata.ModelParameter>`]
583
+
584
+ :display: False
585
+ """
586
+
587
+ print("TRAC Warning: declare_parameter() is deprecated, please use define_parameter()", file=sys.stderr)
588
+
589
+ return define_parameter(param_name, param_type, label, default_value)
590
+
591
+
592
+ def declare_parameters(
593
+ *params: _tp.Union[_Named[ModelParameter], _tp.List[_Named[ModelParameter]]]) \
594
+ -> _tp.Dict[str, ModelParameter]:
595
+
596
+ """
597
+ .. deprecated:: 0.4.4
598
+ Use :py:func:`define_parameters` instead
599
+
600
+ This function is deprecated and will be removed in a future version.
601
+ Please use :py:func:`define_parameters() <tracdap.rt.api.define_parameters>` instead.
602
+
603
+ :type params: _Named[:py:class:`ModelParameter <tracdap.rt.metadata.ModelParameter>`] |
604
+ List[_Named[:py:class:`ModelParameter <tracdap.rt.metadata.ModelParameter>`]]
605
+ :rtype: Dict[str, :py:class:`ModelParameter <tracdap.rt.metadata.ModelParameter>`]
606
+
607
+ :display: False
608
+ """
609
+
610
+ print("TRAC Warning: declare_parameters() is deprecated, please use define_parameters()", file=sys.stderr)
611
+
612
+ return define_parameters(*params)
613
+
614
+
615
+ def declare_field(
616
+ field_name: str,
617
+ field_type: BasicType,
618
+ label: str,
619
+ business_key: bool = False,
620
+ categorical: bool = False,
621
+ not_null: _tp.Optional[bool] = None,
622
+ format_code: _tp.Optional[str] = None,
623
+ field_order: _tp.Optional[int] = None) \
624
+ -> FieldSchema:
625
+
626
+ """
627
+ .. deprecated:: 0.4.4
628
+ Use :py:func:`define_field` or :py:func:`F` instead.
629
+
630
+ This function is deprecated and will be removed in a future version.
631
+ Please use :py:func:`define_field() <tracdap.rt.api.define_field>` instead.
632
+
633
+ :type field_name: str
634
+ :type field_type: :py:class:`BasicType <tracdap.rt.metadata.BasicType>`
635
+ :type label: str
636
+ :type business_key: bool
637
+ :type categorical: bool
638
+ :type not_null: bool | None
639
+ :type format_code: str | None
640
+ :type field_order: int | None
641
+ :rtype: :py:class:`FieldSchema <tracdap.rt.metadata.FieldSchema>`
642
+
643
+ :display: False
644
+ """
645
+
646
+ print("TRAC Warning: declare_field() is deprecated, please use define_field()", file=sys.stderr)
647
+
648
+ return define_field(
649
+ field_name, field_type, label,
650
+ business_key, categorical, not_null,
651
+ format_code, field_order)
652
+
653
+
654
+ def declare_input_table(
655
+ *fields: _tp.Union[FieldSchema, _tp.List[FieldSchema]]) \
656
+ -> ModelInputSchema:
657
+
658
+ """
659
+ .. deprecated:: 0.4.4
660
+ Use :py:func:`define_input_table` instead.
661
+
662
+ This function is deprecated and will be removed in a future version.
663
+ Please use :py:func:`define_input_table() <tracdap.rt.api.define_input_table>` instead.
664
+
665
+ :type fields: :py:class:`FieldSchema <tracdap.rt.metadata.FieldSchema>` |
666
+ List[:py:class:`FieldSchema <tracdap.rt.metadata.FieldSchema>`]
667
+ :rtype: :py:class:`ModelInputSchema <tracdap.rt.metadata.ModelInputSchema>`
668
+
669
+ :display: False
670
+ """
671
+
672
+ print("TRAC Warning: declare_input_table() is deprecated, please use define_input_table()", file=sys.stderr)
673
+
674
+ return define_input_table(*fields)
589
675
 
590
676
 
591
677
  def declare_output_table(