def validate_workflow_options(d): """ 1. warn if an option provided in not a valid workflow option. 2. try to coerce raw string values if possible Return a list of tuples [(id, value)] to be consistent with the existing API """ for option_id in d: if option_id not in REGISTERED_WORKFLOW_OPTIONS: msg = "Unknown option. Ignoring workflow option '{i}'.".format(i=option_id) sys.stderr.write(msg + "\n") log.warn(msg) wopts = [] for option_id, schema in REGISTERED_WORKFLOW_OPTIONS.iteritems(): if option_id in d: raw_value = d[option_id] types_ = schema["properties"][option_id]["type"] coerced_value = crude_coerce_type_from_str(raw_value, types_) _ = jsonschema.validate(schema, {option_id: coerced_value}) wopts.append((option_id, coerced_value)) else: # grab default value = OP.get_default_from_schema(schema) wopts.append((option_id, value)) return wopts
def validate_workflow_options(d): """ 1. warn if an option provided in not a valid workflow option. 2. try to coerce raw string values if possible Return a list of tuples [(id, value)] to be consistent with the existing API """ for option_id in d: if option_id not in REGISTERED_WORKFLOW_OPTIONS: msg = "Unknown option. Ignoring workflow option '{i}'.".format( i=option_id) sys.stderr.write(msg + "\n") log.warn(msg) wopts = [] for option_id, schema in REGISTERED_WORKFLOW_OPTIONS.iteritems(): if option_id in d: raw_value = d[option_id] types_ = schema['properties'][option_id]['type'] coerced_value = crude_coerce_type_from_str(raw_value, types_) _ = jsonschema.validate(schema, {option_id: coerced_value}) wopts.append((option_id, coerced_value)) else: # grab default value = OP.get_default_from_schema(schema) wopts.append((option_id, value)) return wopts
def _raw_option_with_schema(option_id, raw_value, pacbio_option): """ This will attempt to coerce and validate the raw option type provided. The option id provided must be the same or as the provided PacBioOption instance, otherwise a KeyError will be raised. :type pacbio_option: PacBioOption :type option_id: str :param option_id: :param raw_value: :param pacbio_option: :return: """ error_msg = "Incompatible option id '{i}' and " \ "defined option type id '{o}'".format(i=option_id, o=pacbio_option.OPTION_TYPE_ID) if option_id == pacbio_option.option_id: # from raw string, try to coerce to the expected type coerced_value = crude_coerce_type_from_str( raw_value, pacbio_option.OPTION_TYPE_ID) if pacbio_option.OPTION_TYPE_ID == "string" and raw_value is None: coerced_value = "" _ = pacbio_option.validate_option(coerced_value) return coerced_value else: raise KeyError(error_msg)
def _raw_option_with_schema(option_id, raw_value, schema): option_id = option_id.strip() schema_option_id = schema['properties'].keys()[0] if option_id == schema_option_id: types_ = schema['properties'][option_id]['type'] coerced_value = crude_coerce_type_from_str(raw_value, types_) _ = jsonschema.validate(schema, {option_id: coerced_value}) value = coerced_value else: raise KeyError("Incompatible option id '{o}' and schema id '{i}'".format(o=option_id, i=schema_option_id)) return value
def _raw_option_with_schema(option_id, raw_value, schema): option_id = option_id.strip() schema_option_id = schema["properties"].keys()[0] if option_id == schema_option_id: types_ = schema["properties"][option_id]["type"] coerced_value = crude_coerce_type_from_str(raw_value, types_) _ = jsonschema.validate(schema, {option_id: coerced_value}) value = coerced_value else: raise KeyError("Incompatible option id '{o}' and schema id '{i}'".format(o=option_id, i=schema_option_id)) return value
def _raw_option_with_schema(option_id, raw_value, schema): option_id = option_id.strip() schema_option_id = schema['pb_option']['option_id'] if option_id == schema_option_id: pb_type = schema['pb_option']['type'] coerced_value = crude_coerce_type_from_str(raw_value, pb_type) if pb_type == "string" and raw_value is None: coerced_value = "" _ = jsonschema.validate(schema, {option_id: coerced_value}) value = coerced_value else: raise KeyError("Incompatible option id '{o}' and schema id '{i}'".format(o=option_id, i=schema_option_id)) return value
def _raw_option_with_schema(option_id, raw_value, schema): option_id = option_id.strip() schema_option_id = schema['pb_option']['option_id'] if option_id == schema_option_id: pb_type = schema['pb_option']['type'] coerced_value = crude_coerce_type_from_str(raw_value, pb_type) if pb_type == "string" and raw_value is None: coerced_value = "" _ = jsonschema.validate(schema, {option_id: coerced_value}) value = coerced_value else: raise KeyError( "Incompatible option id '{o}' and schema id '{i}'".format( o=option_id, i=schema_option_id)) return value