hammurabi.preconditions package¶
Submodules¶
hammurabi.preconditions.base module¶
This module contains the definition of Rule which describes what to do with the received parameter and does the necessary changes.
The Rule is an abstract class which describes all the required methods and
parameters, but it can be extended and customized easily by inheriting from
it. A good example for this kind of customization is hammurabi.rules.text.LineExists
which adds more parameters to hammurabi.rules.files.SingleFileRule
which
inherits from hammurabi.rules.base.Rule
.
-
class
hammurabi.preconditions.base.
Precondition
(name: Optional[str] = None, param: Optional[Any] = None)[source]¶ Bases:
hammurabi.rules.abstract.AbstractRule
,abc.ABC
This class which describes the bare minimum and helper functions for Preconditions. A precondition defines what and how should be checked/validated before executing a Rule. Since preconditions are special rules, all the functions available what can be used for
hammurabi.rules.base.AbstractRule
.As said, preconditions are special from different angles. While this is not true for Rules, Preconditions will always have a name, hence giving a name to a Precondition is not necessary. In case no name given to a precondition, the name will be the name of the class and ” precondition” suffix.
Example usage:
>>> import logging >>> from typing import Optional >>> from pathlib import Path >>> from hammurabi import Precondition >>> >>> class IsFileExists(Precondition): >>> def __init__(self, path: Optional[Path] = None, **kwargs): >>> super().__init__(None, path, **kwargs) >>> >>> def task(self) -> bool: >>> return self.param and self.param.exists()
- Parameters
name (Optional[str]) – Name of the rule which will be used for printing
param (Any) – Input parameter of the rule will be used as
self.param
-
made_changes
¶
-
name
¶
-
param
¶
-
abstract
task
() → bool[source]¶ Abstract method representing how a
hammurabi.rules.base.Precondition.task()
must be parameterized. Any difference in the parameters or return type will result in pylint/mypy errors.To be able to use the power of
pipe
andchildren
, return something which can be generally used for other rules as in input.- Returns
Returns an output which can be used as an input for other rules
- Return type
Any (usually same as self.param’s type)