rail_pz_service.common package
Common files for pz-rail-service
- rail_pz_service.common.test_files.setup_test_area()[source]
Download test files to setup a project testsing area
- Returns:
0 for success, error code otherwise
- Return type:
int
Notes
This will download files into ‘tests/temp_data’, and could take a few minutes.
This will not download the files if they are already present
CLI Parameters
Common options for pz-rail-service CLIs
- class rail_pz_service.common.common_options.DictParamType[source]
Bases:
ParamTypeRepresents the dictionary type of a CLI parameter.
Validates and converts values from the command line string or Python into a Python dict.
All key-value pairs must be separated by one semicolon.
Key and value must be separated by one colon
- Converts sequences separeted by dots into a list: list value items
must be separated by commas.
Converts numbers to int.
- Usage
>>> @click.option("--param", default=None, type=DictParamType()) ... def command(param): ... ...
CLI: command –param=’page:1; name:Items; rules:1, 2, three; extra:A,;’
Example
>>> param_value = 'page:1; name:Items; rules:1, 2, three; extra:A,;' >>> DictParamType().convert(param_value, None, None) {'page': 1, 'name': 'Items', 'rules': [1, 2, 'three'], 'extra': ['A']}`
- convert(value, param, ctx)[source]
Converts CLI value to the dictionary structure.
- Parameters:
value (Any) – The value to convert.
param ((click.Parameter | None)) – The parameter that is using this type to convert its value.
ctx ((click.Context | None)) – The current context that arrived at this value.
- Returns:
dict
- Return type:
The validated and converted dictionary.
- Raises:
click.BadParameter – If the validation is failed.:
- name: str = 'dictionary'
the descriptive name of this type
- class rail_pz_service.common.common_options.EnumChoice(enum, *, case_sensitive=True)[source]
Bases:
ChoiceA version of click.Choice specialized for enum types.
- Parameters:
enum (type[Enum])
case_sensitive (bool)
- convert(value, param, ctx)[source]
Convert the value to the correct type. This is not called if the value is
None(the missing value).This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.
The
paramandctxarguments may beNonein certain situations, such as when converting prompt input.If the value cannot be converted, call
fail()with a descriptive message.- Parameters:
value (Any) – The value to convert.
param (Parameter | None) – The parameter that is using this type to convert its value. May be
None.ctx (Context | None) – The current context that arrived at this value. May be
None.self (EnumChoice)
- Return type:
Enum
Exception Classes
pz-rail-service specific error types
- exception rail_pz_service.common.errors.RAILBadDatasetError[source]
Bases:
RuntimeErrorRaised when a requested input dataset fails validation checks
- exception rail_pz_service.common.errors.RAILBadInputError[source]
Bases:
FileNotFoundErrorRaised when a functions input is not what is expected
- exception rail_pz_service.common.errors.RAILBadModelError[source]
Bases:
RuntimeErrorRaised when a requested input model fails validation checks
- exception rail_pz_service.common.errors.RAILFileNotFoundError[source]
Bases:
FileNotFoundErrorRaised when a requested input file is not found
- exception rail_pz_service.common.errors.RAILIDMismatchError[source]
Bases:
ValueErrorRaised when there is an ID mismatch between row IDs
- exception rail_pz_service.common.errors.RAILImportError[source]
Bases:
ImportErrorRaised when RAIL failed to import a module
- exception rail_pz_service.common.errors.RAILIntegrityError[source]
Bases:
RuntimeErrorRaised when catching a sqlalchemy.exc.IntegrityError
- exception rail_pz_service.common.errors.RAILMissingIDError[source]
Bases:
KeyErrorRaised when no row matches the requested ID
- exception rail_pz_service.common.errors.RAILMissingInputError[source]
Bases:
FileNotFoundErrorRaised when a function is missing a required input
- exception rail_pz_service.common.errors.RAILMissingNameError[source]
Bases:
KeyErrorRaised when no row matches the requested name
- exception rail_pz_service.common.errors.RAILMissingRowCreateInputError[source]
Bases:
AttributeErrorRaised when call to create a row is missing required information