weaver.processes.convert
Conversion functions between corresponding data structures.
Module Contents
- weaver.processes.convert.WPS_FIELD_FORMAT = ['formats', 'supported_formats', 'supported_values', 'default'][source]
- weaver.processes.convert.convert_unit(unit: str) pint.Unit [source]
Convert units considering any known registry names and OGC URN.
Since OGC defines units using URN, they cannot be registered as aliases in
UNIT_REGISTRY
. This is a limitation from the naming format that requires valid Python identifier names, which is not possible due to the:
characters in URN references.
- weaver.processes.convert.convert_value_units(value: pint._typing.Scalar, uom: str, to: str) pint._typing.Scalar [source]
Converts the provided value from one UoM to another.
- weaver.processes.convert.complex2json(data: owslib.wps.ComplexData | Any) weaver.typedefs.JSON | Any [source]
Obtains the JSON representation of a
ComplexData
or simply return the unmatched type.
- weaver.processes.convert.metadata2json(meta: ANY_Metadata_Type | Any, force: bool = False) weaver.typedefs.JSON | Any [source]
Retrieve metadata information and generate its JSON representation.
Obtains the JSON representation of a
OWS_Metadata
orpywps.app.Common.Metadata
. Otherwise, simply return the unmatched type. If requested, can enforce parsing a dictionary for the corresponding keys.
- weaver.processes.convert.uom2json(uom: str | pywps.inout.basic.UOM | JSON_UoM, ref: str | None = None) JSON_UoM [source]
Convert an UoM definition into corresponding JSON representation.
- weaver.processes.convert.ows2json_output_data(output: OWS_Output_Type, process_description: owslib.wps.Process, container: weaver.typedefs.AnySettingsContainer | None = None) weaver.typedefs.JSON [source]
Utility method to convert an
owslib.wps
process execution output data (result) to JSON.In the case that a
reference
output of JSON content-type is specified and that it refers to a file that contains an array list of URL references to simulate a multiple-output, this specific output gets expanded to contain both the original URLreference
field and the loaded URL list underdata
field for easier access from the response body.Referenced file(s) are fetched in order to store them locally if executed on a remote process, such that they can become accessible as local job result for following reporting or use by other processes in a workflow chain.
If the
dataType
details is missing from the data output (depending on servers that might omit it), theprocess_description
is employed to retrieve the original description with expected result details.- Parameters:
output – Output with data value or reference according to expected result for the corresponding process.
process_description – Definition of the process producing the specified output following execution.
container – Container to retrieve application settings (for request options during file retrieval as needed).
- Returns:
Converted JSON result data and additional metadata as applicable based on data-type and content-type.
- weaver.processes.convert.any2json_literal_data(data: weaver.typedefs.AnyValueType, data_type: weaver.processes.constants.WPS_LiteralData_Type) weaver.typedefs.AnyValueType [source]
Converts
owslib
WPS literal data using strings into the specific JSON compatible type.
- weaver.processes.convert.ows2json_bbox_data(bbox: owslib.ows.BoundingBox) weaver.typedefs.JSON [source]
Converts
owslib
WPS Bounding Box data into a JSON representation.
- weaver.processes.convert._get_multi_json_references(output: OWS_Output_Type, container: weaver.typedefs.AnySettingsContainer | None) List[weaver.typedefs.JSON] | None [source]
Obtains the JSON contents of a single output corresponding to multi-file references.
Since WPS standard does not allow to return multiple values for a single output, a lot of process actually return a JSON array containing references to these outputs.
Because the multi-output references are contained within this JSON file, it is not very convenient to retrieve the list of URLs as one always needs to open and read the file to get them. This function goal is to detect this particular format and expand the references to make them quickly available in the job output response.
- Returns:
Array of HTTP(S) references if the specified output a JSON with URL references,
None
otherwise.
- weaver.processes.convert.get_io_type_category(io_info: ANY_IO_Type) weaver.processes.constants.WPS_CategoryType [source]
Guesses the applicable I/O type with provided information from any known I/O structure.
- weaver.processes.convert._get_cwl_fmt_details(wps_fmt: ANY_Format_Type) Tuple[Tuple[str, str], str, str] | Tuple[None, None, None] [source]
- weaver.processes.convert._convert_any2cwl_io_complex(cwl_io: weaver.typedefs.CWL_IO_Type, cwl_ns: Dict[str, str], wps_io: JSON_IO_Type | WPS_IO_Type | OWS_IO_Type, io_select: weaver.processes.constants.IO_Select_Type) None [source]
Converts the WPS-like I/O definition and defines them inplace into the CWL containers.
See also
See
weaver.processes.wps_process_base.WpsProcessInterface.stage_results()
which closely interacts with the producedoutputBinding.glob
patterns generated here. Methodology should align between them.- Parameters:
- Returns:
Nothing. Changed inplace.
- weaver.processes.convert._get_cwl_js_value_from(cwl_io_symbols: List[weaver.typedefs.AnyValueType], allow_unique: bool, allow_array: bool) str [source]
Obtain the JavaScript
valueFrom
definition for a CWL input of non-string
allowed values.
- weaver.processes.convert._convert_cwl_io_enum(cwl_io_type: str | Type[weaver.utils.null], cwl_io_symbols: List[weaver.typedefs.AnyValueType], io_select: weaver.processes.constants.IO_Select_Type, allow_unique: bool, allow_array: bool) weaver.typedefs.CWL_IO_Type [source]
Converts the I/O definition to a CWL I/O that allows
Enum
-like functionality.In the event of an explicit
string
as base type, CWL directly supportstype: enum
. Other basic types are not directly supported, and must instead perform manual validation against the set of allowed values.See also
Warning
Because
valueFrom
can only be used withinputBinding
, any output providing a set of allowed values that are notstring
-based will be ignored when converted to CWL I/O.- Parameters:
cwl_io_type – Basic type for which allowed values should apply.
cwl_io_symbols – Allowed values to restrict the I/O definition.
- Returns:
Converted definition as CWL Enum or with relevant value validation as applicable for the type.
- weaver.processes.convert.any2cwl_io(wps_io: JSON_IO_Type | WPS_IO_Type | OWS_IO_Type, io_select: weaver.processes.constants.IO_Select_Type) Tuple[weaver.typedefs.CWL_IO_Type, Dict[str, str]] [source]
Converts a WPS-like I/O from various WPS library representations to CWL I/O.
Conversion can be accomplished for
pywps
andowslib
objects, as well as their JSON equivalent. Because CWL I/O of typeFile
withformat
field are namespaced, this is also returned if needed.- Returns:
converted I/O and namespace dictionary with corresponding format references as required.
- weaver.processes.convert._patch_cwl_enum_js_requirement(cwl_package: weaver.typedefs.CWL) None [source]
Applies the JavaScript requirement to validate a pseudo-
Enum
applied to a CWL input definition.
- weaver.processes.convert.wps2cwl_requirement(wps_service_url: str | urllib.parse.ParseResult, wps_process_id: str) weaver.typedefs.JSON [source]
Obtains the CWL requirements definition needed for parsing by a remote WPS provider as an Application Package.
- weaver.processes.convert.ows2json(wps_process: owslib.wps.Process, wps_service_name: str, wps_service_url: str | urllib.parse.ParseResult, wps_provider_name: str | None = None) Tuple[weaver.typedefs.CWL, weaver.typedefs.JSON] [source]
Generates the CWL package and process definitions from a
owslib.wps.Process
hosted under WPS location.
- weaver.processes.convert.xml_wps2cwl(wps_process_response: requests.models.Response, settings: weaver.typedefs.AnySettingsContainer) Tuple[weaver.typedefs.CWL, weaver.typedefs.JSON] [source]
Obtains the CWL definition that corresponds to an XML WPS process.
Converts a WPS-1 ProcessDescription XML tree structure to an equivalent WPS-3 Process JSON, and builds the associated CWL package in conformance to
weaver.processes.wps_package.CWL_REQUIREMENT_APP_WPS1
.- Parameters:
wps_process_response – Valid response (XML, 200) from a WPS-1 ProcessDescription.
settings – Application settings to retrieve additional request options.
- weaver.processes.convert.ogcapi2cwl_process(payload: weaver.typedefs.JSON, reference: str) Tuple[weaver.typedefs.CWL, weaver.typedefs.JSON] [source]
Generate a CWL for a remote OGC API - Processes description to dispatch Process execution.
- weaver.processes.convert.is_cwl_complex_type(io_info: weaver.typedefs.CWL_IO_Type, complex_types: Iterable[weaver.typedefs.CWL_IO_ComplexType] = PACKAGE_COMPLEX_TYPES) bool [source]
Identifies if the provided CWL input/output corresponds to one, many or a potential Complex type(s).
When multiple distinct atomic types are allowed for a given I/O (e.g.:
type: [string, File]
) and that one of them is one of the considered Complex type, the result will beTrue
even if other types are not Complex. Similarly, optional Complex types combined with"null"
will also returnTrue
.
- weaver.processes.convert.parse_cwl_array_type(io_info: weaver.typedefs.CWL_IO_Type, strict: bool = True) CWLIODefinition [source]
Parses the specified I/O for one of the various potential CWL array definitions.
- Parameters:
- Returns:
Updated CWL I/O definition with applicable properties.
- Raises:
PackageTypeError – if the array element doesn’t have the required values and valid format.
- weaver.processes.convert.parse_cwl_enum_type(io_info: weaver.typedefs.CWL_IO_Type) CWLIODefinition [source]
Parses the specified I/O for potential CWL enum definition.
- Returns:
Updated CWL I/O definition with applicable properties.
- Raises:
PackageTypeError – if the enum doesn’t have the required parameters and valid format.
- weaver.processes.convert.get_cwl_io_type_name(io_type: Any) Any [source]
Obtain the simple type-name representation of a CWL I/O.
Depending on
cwltool
version, types are represented with or without an extended prefix, and using an explicit quoted class representation rather than plain strings.
- weaver.processes.convert.resolve_cwl_io_type_schema(io_info: weaver.typedefs.CWL_IO_Type, cwl_schema_names: weaver.typedefs.CWL_SchemaNames | None = None) weaver.typedefs.CWL_IO_Type [source]
Reverse CWL schema references by name back to their full CWL I/O definition.
- class weaver.processes.convert.CWLIODefinition[source]
Utility CWL I/O definition to contain metadata from parsing results.
- type: CWL_IO_LiteralType | CWL_IO_ComplexType | CWL_IO_DataType[source]
Type of the CWL I/O.
If
enum
isTrue
, represents the enum base type. Ifarray
isTrue
, represents the item type.Note
Before resolution with
parse_cwl_array_type()
, this attribute can temporarily hold any CWL type structure (list, dict, nested types, etc.). After parsing, it will be resolved to the basic string type.
- null: bool = False[source]
Indicates if the I/O is nullable.
This is obtained from a type composed of
"null"
and something else, or using the shorthand{type}?
notation.
- min_occurs: int = 1[source]
Minimum number of occurrences allowed.
When
null
isTrue
, it is equal to0
. Otherwise, it is greater or equal to1
. If greater than1
,array
should beTrue
.
- max_occurs: int = 1[source]
Maximum number of occurrences allowed.
Applies only when
array
isTrue
. Otherwise, always equal to1
. Can take the valuePACKAGE_ARRAY_MAX_SIZE
to represent"unbounded"
occurrences.
- symbols: CWL_IO_EnumSymbols | AnyValue | Type[AnyValue][source]
Specifies the allowed values when the definition is marked as
enum
.When not overriden by literal values, it uses the default
AnyValue
.
- mode: pywps.validator.mode.MODE[source]
Validation mode to be applied if I/O requires it.
Defaults to
MODE.NONE
. Indicates how strict the validation must be. Usually applies when an enum must only allow a specific set of symbols. Can also be used with Media-Types in more advanced validation use case withpywps
.
- weaver.processes.convert.get_cwl_io_type(io_info: weaver.typedefs.CWL_IO_Type, strict: bool = True, cwl_schema_names: weaver.typedefs.CWL_SchemaNames | None = None) CWLIODefinition [source]
Obtains the basic type of the CWL input and identity if it is optional.
CWL allows multiple shorthand representation or combined types definition. The base type must be extracted in order to identify the expected data format and supported values.
Obtains real type if
"default"
or shorthand"<type>?"
was in CWL, which can also be defined as type["null", <type>]
.CWL allows multiple distinct types (e.g.:
string
andint
simultaneously), but not WPS inputs. WPS allows only different amount of same type throughminOccurs
andmaxOccurs
. Considering WPS conversion, we can also have the following definition["null", <type>, <array-type>]
will all basic types matching exactly. Whether single or array-like type, the base type can be extracted.- Parameters:
- Returns:
tuple of guessed base type and flag indicating if it can be null (optional input).
- weaver.processes.convert.cwl2wps_io(io_info: weaver.typedefs.CWL_IO_Type, io_select: weaver.processes.constants.IO_Select_Type) WPS_IO_Type [source]
Converts input/output parameters from CWL types to WPS types.
- Parameters:
io_info – parsed IO of a CWL file
io_select –
IO_INPUT
orIO_OUTPUT
to specify desired WPS type conversion.
- Returns:
corresponding IO in WPS format
- weaver.processes.convert.cwl2json_input_values(data: Dict[str, weaver.typedefs.CWL_IO_Value], schema: weaver.processes.constants.ProcessSchemaType = ProcessSchema.OGC) weaver.typedefs.ExecutionInputs [source]
Converts CWL formatted Job inputs to corresponding OGC API - Processes format.
- Parameters:
data – dictionary with inputs formatted as key-value pairs with relevant structure based on CWL types.
schema – either
OGC
orOLD
format respectively for mapping/listing representations.
- Raises:
TypeError – if input data is invalid.
ValueError – if any input value could not be parsed with expected schema.
- Returns:
converted inputs for Job submission either in
OGC
orOLD
format.
- weaver.processes.convert.convert_input_values_schema(inputs: weaver.typedefs.ExecutionInputs, schema: weaver.processes.constants.JobInputsOutputsSchema.OGC) weaver.typedefs.ExecutionInputsMap [source]
- weaver.processes.convert.convert_input_values_schema(inputs: weaver.typedefs.ExecutionInputs, schema: weaver.processes.constants.JobInputsOutputsSchema.OLD) weaver.typedefs.ExecutionInputsList
Convert execution input values between equivalent formats.
See also
normalize_ordered_io()
for I/O definitions.
- Parameters:
inputs – Inputs to convert.
schema – Desired schema.
- Returns:
Converted inputs.
- weaver.processes.convert.convert_output_params_schema(inputs: weaver.typedefs.ExecutionOutputs, schema: weaver.processes.constants.JobInputsOutputsSchema.OGC) weaver.typedefs.ExecutionOutputsMap [source]
- weaver.processes.convert.convert_output_params_schema(inputs: weaver.typedefs.ExecutionOutputs, schema: weaver.processes.constants.JobInputsOutputsSchema.OLD) weaver.typedefs.ExecutionOutputsList
Convert execution output parameters between equivalent formats.
Warning
These outputs are not values (i.e.: results), but submitted Job outputs for return definitions. Contents are transferred as-is without any consideration of
value
orhref
fields.See also
normalize_ordered_io()
for I/O definitions.
- Parameters:
outputs – Outputs to convert.
schema – Desired schema.
- Returns:
Converted outputs.
- weaver.processes.convert.repr2json_input_params(value: str, converter: Callable[[str], Any] | None = None) DataInputType [source]
Extracts and converts the value and its associated parameters from a KVP string representation.
This function only interprets a pre-extracted single-value definition (i.e.: without the input ID) from a parent KVP string.
See also
Use
repr2json_input_values()
For parsing multi-value arrays and the full KVP including the ID.- Parameters:
value – String representation of the value to be interpreted.
converter – Conversion function of the value after parsing.
- Returns:
Converted value and additional parameters if applicable.
- weaver.processes.convert.repr2json_input_values(inputs: List[str]) weaver.typedefs.ExecutionInputsList [source]
Converts inputs in string KVP representation to corresponding JSON values.
Expected format of the input is as follows:
input_id[:input_type]=input_value[@input_parameter][;input_array[@input_parameter]][;...]
- Where:
input_id
represents the target identifier of the inputinput_type
represents the conversion type, as required (includesFile
forhref
instead ofvalue
key in resulting object)input_value
represents the desired value subject to conversion byinput_type
input_array
represents any additional values for array-like inputs (maxOccurs > 1
)input_parameter
represents additional KVP details associated to eachinput_value
/input_array
part (i.e.: per array element if applicable)
The separator character for representing array-like values is
;
because the full KVP (already split into a list as argument to this function), could be formed of multiple comma (,
) or ampersand (&
) separated input definitions, depending on where the definition came from (e.g.: URI).The
input_parameter
portion can combine multiple parameters each separated by@
and themselves formed with KVP representation of the corresponding parameter names and values. Parameter names do not need to be consistent between distinct array elements. For example, a multi-parameters input could be formatted as follows:input_id=item_value1@param1=value1@param2=value2;item_value2@other1=value1
Note
Any character that matches one of the separators that should be interpreted literally should be URL-encoded.
Single (
'
) and double ("
) quotes are removed if they delimit aFile
reference.
- Parameters:
inputs – list of string inputs to parse.
- Returns:
parsed inputs if successful.
- weaver.processes.convert.any2cwl_literal_datatype(io_type: str) str | Type[weaver.utils.null] [source]
Solves common literal data-type names to supported ones for CWL.
- weaver.processes.convert.any2wps_literal_datatype(io_type: weaver.typedefs.AnyValueType | weaver.processes.constants.WPS_LiteralData_Type, is_value: bool = False, pywps: bool = False) str | Type[weaver.utils.null] [source]
Solves common literal data-type names to supported ones for WPS.
Verification is accomplished by name when
is_value=False
, otherwise with pythontype
whenis_value=True
.
- weaver.processes.convert.any2json_literal_allowed_value(io_allow: pywps.inout.literaltypes.AllowedValue | weaver.typedefs.JSON | str | float | int | bool) weaver.typedefs.JSON | str | str | float | int | bool | Type[weaver.utils.null] [source]
Converts an
AllowedValues
definition from different packages into standardized JSON representation of OGC-API.
- weaver.processes.convert.any2json_literal_data_domains(io_info: ANY_IO_Type) Type[weaver.utils.null] | List[weaver.typedefs.JSON] [source]
Extracts allowed value constrains from the input definition and generate the expected literal data domains.
The generated result, if applicable, corresponds to a list of a single instance of schema definition
weaver.wps_restapi.swagger_definitions.LiteralDataDomainList
with following structure.default: bool defaultValue: float, int, bool, str dataType: {name: string, <reference: url: string>} UOMs: - default: {uom: string, reference: url-string} - supported: [{uom: string, reference: url-string}] valueDefinition: oneOf: - string - url-string - {anyValue: bool} - [float, int, bool, str] - [{minimum: number/none, maximum: number/none, spacing: number/none, closure: str open/close variations}]
- weaver.processes.convert.json2oas_io_complex(io_info: JSON_IO_Type, io_hint: weaver.typedefs.OpenAPISchema | Type[weaver.utils.null] = null) weaver.typedefs.OpenAPISchema [source]
Convert a single-dimension complex JSON I/O definition into corresponding OpenAPI schema.
- weaver.processes.convert.json2oas_io_bbox(io_info: JSON_IO_Type, io_hint: weaver.typedefs.OpenAPISchema | Type[weaver.utils.null] = null) weaver.typedefs.OpenAPISchema [source]
Convert a single-dimension bounding box JSON I/O definition into corresponding OpenAPI schema.
See also
sd.OGC_API_BBOX_SCHEMA
- weaver.processes.convert.json2oas_io_literal_data_type(io_type: str) weaver.typedefs.JSON [source]
Converts various literal data types into corresponding OpenAPI fields.
- weaver.processes.convert.json2oas_io_allowed_values(io_base: weaver.typedefs.JSON, io_allowed: weaver.typedefs.JSON) List[weaver.typedefs.JSON] [source]
Converts literal data allowed values JSON definitions ino OpenAPI equivalent variations.
- weaver.processes.convert.json2oas_io_literal(io_info: JSON_IO_Type, io_hint: weaver.typedefs.OpenAPISchema | Type[weaver.utils.null] = null) weaver.typedefs.OpenAPISchema [source]
Convert a single-dimension literal value JSON I/O definition into corresponding OpenAPI schema.
- weaver.processes.convert.json2oas_io(io_info: JSON_IO_Type, io_hint: weaver.typedefs.OpenAPISchema | Type[weaver.utils.null] = null) weaver.typedefs.OpenAPISchema [source]
Converts definitions from a JSON Process I/O definition into corresponding OpenAPI schema.
- weaver.processes.convert.oas2json_io_literal(io_info: weaver.typedefs.OpenAPISchemaProperty) JSON_IO_TypedInfo | Type[weaver.utils.null] [source]
Converts a literal value I/O definition by OpenAPI schema into the equivalent JSON representation.
- weaver.processes.convert.oas2json_io_array(io_info: weaver.typedefs.OpenAPISchemaArray) JSON_IO_TypedInfo | Type[weaver.utils.null] [source]
Converts an array I/O definition by OpenAPI schema into the equivalent JSON representation.
- weaver.processes.convert.oas2json_io_object(io_info: weaver.typedefs.OpenAPISchemaObject, io_href: str = null) JSON_IO_TypedInfo | Type[weaver.utils.null] [source]
Converts an object I/O definition by OpenAPI schema into the equivalent JSON representation.
An explicit OpenAPI schema with
object
type can represent any of the following I/O:Bounding Box as GeoJSON feature
Complex JSON structure
See also
oas2json_io_file()
is used for file reference to be parsed as other Complex I/O.
- weaver.processes.convert.oas2json_io_keyword(io_info: weaver.typedefs.OpenAPISchemaKeyword) JSON_IO_TypedInfo | Type[weaver.utils.null] [source]
Converts a keyword I/O definition by OpenAPI schema into the equivalent JSON representation.
Keywords are defined as a list of combinations of OpenAPI schema representing how to combine them according to the keyword value, being one of
OAS_KEYWORD_TYPES
.
- weaver.processes.convert.oas2json_io_file(io_info: weaver.typedefs.OpenAPISchemaObject, io_href: str = null) JSON_IO_TypedInfo [source]
Converts a file reference I/O definition by OpenAPI schema into the equivalent JSON representation.
- weaver.processes.convert.oas2json_io_measure(io_info: weaver.typedefs.OpenAPISchemaObject) JSON_IO_TypedInfo | Type[weaver.utils.null] [source]
Convert a unit of measure (
UoM
) I/O definition by OpenAPI schema into JSON representation.This conversion projects an object (normally complex type) into a literal type, considering that other provided parameters are all metadata information.
- Parameters:
io_info – Potential OpenAPI schema of an UoM I/O.
- Returns:
Converted I/O if it matched the UoM format, or null otherwise.
- weaver.processes.convert.oas2json_io(io_info: weaver.typedefs.OpenAPISchema) JSON_IO_TypedInfo | Type[weaver.utils.null] [source]
Converts an I/O definition by OpenAPI schema into the equivalent JSON representation.
- weaver.processes.convert.oas_resolve_remote(io_info: weaver.typedefs.OpenAPISchema) weaver.typedefs.OpenAPISchema [source]
Perform remote OpenAPI schema
$ref
resolution.Resolution is performed only sufficiently to provide enough context for following JSON I/O conversion. Remote references are not resolved further than required to speedup loading time and avoid recursive error on self-referring schema. Passed sufficient levels of schema definitions, the specific contents is not important nor needs to be resolved as there is they cannot be mapped to anything else than
WPS_COMPLEX
I/O type.
- weaver.processes.convert.json2wps_datatype(io_info: JSON_IO_Type) str [source]
Converts a JSON input definition into the corresponding
pywps
parameters.Guesses the literal data-type from JSON I/O information in order to allow creation of the corresponding WPS I/O. Defaults to
string
if no suitable guess can be accomplished.
- weaver.processes.convert.json2wps_field(field_info: weaver.typedefs.JSON, field_category: str) Any [source]
Converts an I/O field from JSON literal, list, or dictionary to corresponding WPS types.
- Parameters:
field_info – literal data or information container describing the type to be generated.
field_category – one of
WPS_FIELD_MAPPING
keys to indicate how to parsefield_info
.
- weaver.processes.convert.json2wps_supported_uoms(io_info: JSON_IO_Type) Type[weaver.utils.null] | List[pywps.inout.basic.UOM] [source]
Obtains instances of supported Unit of Measure (UoM) from a JSON I/O definition.
- weaver.processes.convert.json2wps_allowed_values(io_info: JSON_IO_Type) Type[weaver.utils.null] | List[pywps.inout.literaltypes.AllowedValue] [source]
Obtains the allowed values constrains for the literal data type from a JSON I/O definition.
Converts the
literalDataDomains
definition intoallowed_values
understood bypywps
. Handles explicitallowed_values
if available and not previously defined byliteralDataDomains
.See also
Function
any2json_literal_data_domains()
defines generatedliteralDataDomains
JSON definition.
- weaver.processes.convert.json2wps_io(io_info: JSON_IO_Type, io_select: weaver.processes.constants.IO_Select_Type) WPS_IO_Type [source]
- weaver.processes.convert.wps2json_io(io_wps: WPS_IO_Type, forced_fields: bool = False) JSON_IO_Type [source]
Converts a
pywps
I/O into a JSON dictionary with corresponding standard keys names.Employs standard key names as defined by WPS 2.0.
- Parameters:
io_wps – Any
pywps
I/O definition to be converted to JSON representation.forced_fields – Request transfer of additional fields normally undefined for outputs if they are available by being forcefully inserted in the objects after their creation (i.e.: using
set_field()
). These fields can be useful for obtaining mandatory details for further processing operations (e.g.: OpenAPI schema conversion).
- weaver.processes.convert.wps2json_job_payload(wps_request: pywps.app.WPSRequest, wps_process: pywps.Process) weaver.typedefs.JSON [source]
Converts the input and output values of a
pywps
WPSExecute
request to corresponding WPS-REST job.The inputs and outputs must be parsed from XML POST payload or KVP GET query parameters, and converted to data container defined by
pywps
based on the process definition.
- weaver.processes.convert.get_field(io_object: weaver.typedefs.JSON | object, field: str, search_variations: bool = False, extra_variations: List[str] | None = None, only_variations: bool = False, pop_found: bool = False, key: bool = False, default: Any = null) Any [source]
Gets a field by name from various I/O object types.
Default value is
null
used for most situations to differentiate from literalNone
which is often used as default for parameters. TheNullType
allows to explicitly tell that there was ‘no field’ and not ‘no value’ in existing field. If you provided another value, it will be returned if not found within the input object.When
search_variation
is enabled and thatfield
could not be found within the object, field lookup will employ the values under thefield
entry withinWPS_FIELD_MAPPING
as additional field names to search for an existing property or key. Search continues until the first match is found, respecting order within the variations listing, and finally usesdefault
if no match was found.- Parameters:
io_object – Any I/O representation, either as a class instance or JSON container.
field – Name of the field to look for, either as property or key name based on input object type.
search_variations – If enabled, search for all variations to the field name to attempt search until matched.
extra_variations – Additional field names to consider as search variations, with priority over field mapping.
only_variations – If enabled, skip the first ‘basic’ field and start search directly with field variations.
pop_found – If enabled, whenever a match is found by field or variations, remove that entry from the object.
key – If enabled, whenever a match is found by field or variations, return matched key instead of the value.
default – Alternative default value to return if no match could be found.
- Returns:
Matched value (including search variations if enabled), or
default
.
- weaver.processes.convert.set_field(io_object: weaver.typedefs.JSON | object, field: str, value: Any, force: bool = False) None [source]
Sets a field by name into various I/O object types.
Field value is set only if not
null
to avoid inserting data considered invalid. Ifforce=True
, verification ofnull
value is ignored.
- weaver.processes.convert._are_different_and_set(item1: Any, item2: Any) bool [source]
Verifies if two items are set and are different of different “representative” value.
Compares two value representations and returns
True
only if both are notnull
, are of sametype
and of different representative value. By “representative”, we consider here the visual representation of byte/unicode strings rather than literal values to support XML/JSON and Python 2/3 implementations. Other non-string-like types are verified with literal (usual) equality method.
- weaver.processes.convert.is_equal_formats(format1: pywps.inout.formats.Format | weaver.typedefs.JSON, format2: pywps.inout.formats.Format | weaver.typedefs.JSON) bool [source]
Verifies for matching formats.
- weaver.processes.convert.normalize_ordered_io(io_section: JSON_IO_ListOrMap, order_hints: JSON_IO_ListOrMap | None = None) List[weaver.typedefs.JSON] [source]
Reorders and converts I/O from any representation (
dict
orlist
) using ordering hints.First, converts I/O definitions defined as dictionary to an equivalent
list
representation, in order to work only with a single representation method. Thelist
is chosen overdict
because sequences can enforce a specific order, while mapping (when saved as JSON or YAML) have no specific order. The list representation ensures that I/O order is preserved when written to file and reloaded afterwards regardless of server and/or library’s implementation of the mapping container.If this function fails to correctly order any I/O or cannot correctly guarantee such result because of the provided parameters (e.g.: no hints given when required), the result will not break nor change the final processing behaviour of parsers. This is merely cosmetic adjustments to ease readability of I/O to avoid always shuffling their order across multiple Application Package and Process reporting formats.
The important result of this function is to provide the I/O as a consistent list of objects, so it is less cumbersome to compare/merge/iterate over the elements with all functions that will follow.
Note
When defined as a dictionary, an
OrderedDict
is expected as input to ensure preserved field order. Prior to Python 3.7 or CPython 3.5, preserved order is not guaranteed for builtindict
. In this case theorder_hints
is required to ensure same order.This function is intended for parsing I/O from Process descriptions, Application Package and other definitions that employ a
"type"
field. For submitted execution I/O values, refer to other relevant functions.
- weaver.processes.convert.merge_io_formats(wps_formats: List[ANY_Format_Type], cwl_formats: List[ANY_Format_Type]) List[ANY_Format_Type] [source]
Merges I/O format definitions by matching
mime-type
field.In case of conflict, preserve the WPS version which can be more detailed (for example, by specifying
encoding
).Verifies if
DEFAULT_FORMAT_MISSING
was written to a single CWL format caused by a lack of any value provided as input. In this case, only WPS formats are kept.In the event that
DEFAULT_FORMAT_MISSING
was written to the CWL formats and that no WPS format was specified, theDEFAULT_FORMAT
is returned.- Raises:
PackageTypeError – if inputs are invalid format lists
- weaver.processes.convert.merge_io_fields(wps_io: WPS_IO_Type, cwl_io: WPS_IO_Type) WPS_IO_Type [source]
Combines corresponding I/O fields from WPS and CWL definitions.
See also
cwl2wps_io()
for conversion of CWL to WPS representation.
- weaver.processes.convert.merge_package_io(wps_io_list: List[ANY_IO_Type], cwl_io_list: List[WPS_IO_Type], io_select: weaver.processes.constants.IO_Select_Type) List[JSON_IO_Type] [source]
Merges corresponding parameters of different I/O definition sources.
Handled definition formats include I/O representation for CWL, OpenAPI, WPS and generic JSON using properties resembling
pywps
orowslib
objects.Update I/O definitions to use for Process creation and returned by
GetCapabilities
/DescribeProcess
. If WPS I/O definitions where provided during deployment, update CWL-to-WPS converted I/O with the WPS I/O complementary details. If an OpenAPIschema
definition was provided to define the I/O, infer the corresponding WPS I/O details. Then, considering those resolved definitions and any missing information that could be inferred, extend field requirements that can be retrieved from CWL definitions.Removes any deployment WPS I/O definitions that don’t match any CWL I/O by ID, since they will be of no use for the underlying Application Package. Adds missing deployment WPS I/O definitions using expected CWL I/O IDs.
See also
cwl2wps_io()
for conversion of CWL to WPS representation.
- weaver.processes.convert.check_io_compatible(wps_io: WPS_IO_Type, cwl_io: WPS_IO_Type, io_id: str) None [source]
Validate types to ensure they match categories, otherwise merging will cause more confusion.
For Literal/Complex I/O coming from WPS side, they should be matched exactly with Literal/Complex I/O on the CWL side.
Note
The :term`CWL` I/O in this case is expected to be a
pywps
converted I/O from the :term`CWL` definition, and not a direct :term`CWL` I/O definition.Warning
When BoundingBox for WPS, it should be mapped to ComplexInput on CWL side (since no equivalent).
- Raises:
PackageTypeError – If I/O are not compatible.