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

rail_pz_service.common.test_files.teardown_test_area()[source]
Return type:

None

CLI Parameters

Common options for pz-rail-service CLIs

class rail_pz_service.common.common_options.DictParamType[source]

Bases: ParamType

Represents 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: Choice

A 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 param and ctx arguments may be None in 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

class rail_pz_service.common.common_options.OutputEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Options for output format

json = 2
yaml = 1
class rail_pz_service.common.common_options.PartialOption(*param_decls, **attrs)[source]

Bases: object

Wrap partially specified click.option decorator for convenient reuse.

Parameters:
  • param_decls (str)

  • attrs (Any)

Exception Classes

pz-rail-service specific error types

exception rail_pz_service.common.errors.RAILBadDatasetError[source]

Bases: RuntimeError

Raised when a requested input dataset fails validation checks

exception rail_pz_service.common.errors.RAILBadInputError[source]

Bases: FileNotFoundError

Raised when a functions input is not what is expected

exception rail_pz_service.common.errors.RAILBadModelError[source]

Bases: RuntimeError

Raised when a requested input model fails validation checks

exception rail_pz_service.common.errors.RAILFileNotFoundError[source]

Bases: FileNotFoundError

Raised when a requested input file is not found

exception rail_pz_service.common.errors.RAILIDMismatchError[source]

Bases: ValueError

Raised when there is an ID mismatch between row IDs

exception rail_pz_service.common.errors.RAILImportError[source]

Bases: ImportError

Raised when RAIL failed to import a module

exception rail_pz_service.common.errors.RAILIntegrityError[source]

Bases: RuntimeError

Raised when catching a sqlalchemy.exc.IntegrityError

exception rail_pz_service.common.errors.RAILMissingIDError[source]

Bases: KeyError

Raised when no row matches the requested ID

exception rail_pz_service.common.errors.RAILMissingInputError[source]

Bases: FileNotFoundError

Raised when a function is missing a required input

exception rail_pz_service.common.errors.RAILMissingNameError[source]

Bases: KeyError

Raised when no row matches the requested name

exception rail_pz_service.common.errors.RAILMissingRowCreateInputError[source]

Bases: AttributeError

Raised when call to create a row is missing required information

exception rail_pz_service.common.errors.RAILRequestError[source]

Bases: RuntimeError

Raised when a RAIL request failed

exception rail_pz_service.common.errors.RAILStatementError[source]

Bases: RuntimeError

Raised when catching a sqlalchemy.exc.StatementError