datalad_next.constraints.basic
Basic constraints for declaring essential data types, values, and ranges
- class datalad_next.constraints.basic.EnsureBool[source]
Bases:
Constraint
Ensure that an input is a bool.
A couple of literal labels are supported, such as: False: '0', 'no', 'off', 'disable', 'false' True: '1', 'yes', 'on', 'enable', 'true'
- class datalad_next.constraints.basic.EnsureCallable[source]
Bases:
Constraint
Ensure an input is a callable object
- class datalad_next.constraints.basic.EnsureChoice(*values)[source]
Bases:
Constraint
Ensure an input is element of a set of possible values
- class datalad_next.constraints.basic.EnsureDType(dtype)[source]
Bases:
Constraint
Ensure that an input (or several inputs) are of a particular data type. .. rubric:: Examples
>>> c = EnsureDType(float) >>> type(c(8)) float >>> import numpy as np >>> c = EnsureDType(np.float64) >>> type(c(8)) numpy.float64
- class datalad_next.constraints.basic.EnsureFloat[source]
Bases:
EnsureDType
Ensure that an input (or several inputs) are of a data type 'float'.
- class datalad_next.constraints.basic.EnsureInt[source]
Bases:
EnsureDType
Ensure that an input (or several inputs) are of a data type 'int'.
- class datalad_next.constraints.basic.EnsureKeyChoice(key, values)[source]
Bases:
EnsureChoice
Ensure value under a key in an input is in a set of possible values
- class datalad_next.constraints.basic.EnsureNone[source]
Bases:
EnsureValue
Ensure an input is of value None
- class datalad_next.constraints.basic.EnsurePath(*, path_type: type = <class 'pathlib.Path'>, is_format: str | None = None, lexists: bool | None = None, is_mode: callable | None = None, ref: Path | None = None, ref_is: str = 'parent-or-same-as', dsarg: DatasetParameter | None = None)[source]
Bases:
Constraint
Ensures input is convertible to a (platform) path and returns a Path
Optionally, the path can be tested for existence and whether it is absolute or relative.
- for_dataset(dataset: DatasetParameter) Constraint [source]
Return an similarly parametrized variant that resolves paths against a given dataset (argument)
- class datalad_next.constraints.basic.EnsureRange(min=None, max=None)[source]
Bases:
Constraint
Ensure an input is within a particular range
No type checks are performed.
- class datalad_next.constraints.basic.EnsureStr(min_len: int = 0, match: str | None = None)[source]
Bases:
Constraint
Ensure an input is a string of some min. length and matching a pattern
Pattern matching is optional and minimum length is zero (empty string is OK).
No type conversion is performed.
- class datalad_next.constraints.basic.EnsureStrPrefix(prefix)[source]
Bases:
EnsureStr
Ensure an input is a string that starts with a given prefix.
- class datalad_next.constraints.basic.EnsureValue(value)[source]
Bases:
Constraint
Ensure an input is a particular value
- class datalad_next.constraints.basic.NoConstraint[source]
Bases:
Constraint
A constraint that represents no constraints