Elements¶
Element
¶
- class momotor.bundles.elements.base.Element(bundle)¶
Abstract base class for all elements of a
Bundle
- create(**kwargs)¶
Set this element’s attributes
Usage:
element = Element(bundle).create(...)
- Return type:
TypeVar
(ET
, bound= Element)- Returns:
self
- recreate(target_bundle, **kwargs)¶
Recreate this element in a target bundle
- classmethod recreate_list(elements, target_bundle, filter=None, **kwargs)¶
Recreate a list of elements
- Parameters:
elements (
Optional
[Iterator
[TypeVar
(ET
, bound= Element)]]) – List of elements to recreate (can be None)target_bundle (
Bundle
) – The target bundlefilter (
Optional
[Callable
[[TypeVar
(ET
, bound= Element)],bool
]]) – An optional callable to filter the list of elements before recreation. The callable receives an element and should return a booleankwargs – Additional keyword arguments are passed on to
recreate()
- Return type:
- Returns:
a list of elements or None if elements param was None
Checklet
¶
- class momotor.bundles.elements.checklets.Checklet(bundle)¶
A Checklet element encapsulating
checkletComplexType
- create(name=None, extras=None, version=None, entrypoint=None, repository=None, link=None, indices=None, package_versions=None, resources=None)¶
Set this element’s attributes
Usage:
element = Element(bundle).create(...)
- get_dist_name()¶
Return a distribution selector (ie. name, extras and version in a single string)
eg: “name[extra1,extra2]==1.0”
- Return type:
- static get_node_type()¶
Get the xsData node type
- Return type:
- get_resources()¶
Get the resources as a dictionary name -> Resource
- Return type:
- recreate(target_bundle)¶
Recreate this element in a target bundle
- classmethod recreate_list(elements, target_bundle, filter=None, **kwargs)¶
Recreate a list of elements
- Parameters:
elements (
Optional
[Iterator
[TypeVar
(ET
, bound= Element)]]) – List of elements to recreate (can be None)target_bundle (
Bundle
) – The target bundlefilter (
Optional
[Callable
[[TypeVar
(ET
, bound= Element)],bool
]]) – An optional callable to filter the list of elements before recreation. The callable receives an element and should return a booleankwargs – Additional keyword arguments are passed on to
recreate()
- Return type:
- Returns:
a list of elements or None if elements param was None
- property entrypoint: str¶
entrypoint attribute: Override the default package entrypoint
- Return type:
- property extras: Optional[FilterableTuple[str]]¶
extras attribute: The Python package extras (eg. “requests”)
- Return type:
- property package_versions: Optional[FilterableTuple[PackageVersion]]¶
package_versions attribute: (unused, untested)
- Return type:
- property repository: Optional[Repository]¶
repository attribute: where to retrieve the package from
- Return type:
- property resources: FilterableTuple[Resource]¶
resources attribute
- Return type:
Depends
¶
- class momotor.bundles.elements.steps.Depends(bundle)¶
A Depends element encapsulating
DependsComplexType
- create(*, step)¶
Set this element’s attributes
Usage:
element = Element(bundle).create(...)
- static get_node_type()¶
Get the xsData node type
- Return type:
- recreate(target_bundle)¶
Recreate this element in a target bundle
- classmethod recreate_list(elements, target_bundle, filter=None, **kwargs)¶
Recreate a list of elements
- Parameters:
elements (
Optional
[Iterator
[TypeVar
(ET
, bound= Element)]]) – List of elements to recreate (can be None)target_bundle (
Bundle
) – The target bundlefilter (
Optional
[Callable
[[TypeVar
(ET
, bound= Element)],bool
]]) – An optional callable to filter the list of elements before recreation. The callable receives an element and should return a booleankwargs – Additional keyword arguments are passed on to
recreate()
- Return type:
- Returns:
a list of elements or None if elements param was None
File
¶
- class momotor.bundles.elements.files.File(bundle)¶
A File element encapsulating
fileComplexType
- copy_to(destination, *, name=None, executable_attribute=False)¶
Copy attachment to given directory
If attachment is a file, creates a new file in the given directory. If name is provided this will be the name of the new file, otherwise the name of the source file is used.
If attachment is a directory, copies the contents of the source directory to the destination directory. If name is provided it is created as a new directory inside the destination directory.
Will not overwrite an existing file or directory.
- Parameters:
- Raises:
ValueError – when the attachment is not writeable as a file
FileExistsError – when a file already exists
- Return type:
- create(*, class_=None, name=None, src=None, content=<object object>, type=None, executable=False, attrs=None)¶
Set this file node’s attributes.
This creates an attachment for the bundle. The src or content parameters provide the content for the attachment. Only one of them can be set. When a file path is provided using src, the file must exist when the bundle is exported using one of the
Bundle.to_*
methods.Note that the src parameter of this method is not directly related to the src attribute of the <file> node in the generated XML when exporting the bundle, and how the src attribute is generated is an implementation detail of this library that can change between versions. Do not rely on an attachment being exported to a specific location in a generated zip bundle.
- Parameters:
class – The class attribute of the file node
name (
Union
[str
,PurePosixPath
,None
]) – The name attribute of the file nodesrc (
Union
[AttachmentSrc
,PurePath
,None
]) – The source of the file. See note above.content (
Union
[str
,bool
,None
,NewType()
(NoContentType
,object
)]) – The content of the file. Defaults toNO_CONTENT
.executable (
bool
) – The executable attribute of the file nodeattrs (
Optional
[Dict
]) – Additional attributes of the file node
- Return type:
TypeVar
(ET
, bound= File)
- file_ctime(path=None)¶
Get file creation time for the attachment.
- Return type:
- file_hashes(hash_names)¶
Calculate the hashes of the file.
Only for file attachments. Will return an empty dictionary if the file does not exist or is a directory.
- file_size(path=None)¶
Get file size for the content.
- static get_node_type()¶
Get the xsData node type
- Return type:
- has_inline_content()¶
Returns True if element has inline content, without processing the content
- Return type:
- has_inline_text_content()¶
Returns True if self.value would return text content (either bytes or str), without converting the content.
- Return type:
- has_writable_content()¶
- iterdir(*, include_empty_root=False)¶
Recursively iterate the contents of a directory attachment. The returned paths are relative to self.absolute_path
If the attachment is an empty directory and include_empty_root is True, a single None value is yielded
- Return type:
- open(path=None)¶
Open the attachment file for reading. Handles opening files directly from filesystem and from zipped bundles
- Parameters:
path (
Union
[str
,PurePosixPath
,None
]) – for directory attachments, path selects a file in that directory- Return type:
- Returns:
the opened file
- Raises:
FileNotFoundError – if the element has no attachment (when src is None), or when it’s a directory and path does not exist in that directory
IsADirectoryError – when it’s a directory
- read(path=None)¶
Read the contents of the attachment
- Parameters:
path (
Union
[str
,PurePosixPath
,None
]) – for directory attachments, path selects a file in that directory- Return type:
- Returns:
A bytes object with the full file contents
- recreate(target_bundle, *, class_=None, name=None)¶
Recreate this File in a target bundle, optionally changing the class_ or name.
If the node has a src attachment, the target bundle will link to the same file, the file will not be copied.
- classmethod recreate_list(elements, target_bundle, filter=None, **kwargs)¶
Recreate a list of elements
- Parameters:
elements (
Optional
[Iterator
[TypeVar
(ET
, bound= Element)]]) – List of elements to recreate (can be None)target_bundle (
Bundle
) – The target bundlefilter (
Optional
[Callable
[[TypeVar
(ET
, bound= Element)],bool
]]) – An optional callable to filter the list of elements before recreation. The callable receives an element and should return a booleankwargs – Additional keyword arguments are passed on to
recreate()
- Return type:
- Returns:
a list of elements or None if elements param was None
- validate_hashes(expected_hashes)¶
Validate hash values of the file.
Only for file attachments
- VALID_PROCESSED_TYPES: ClassVar = (<class 'str'>, <class 'bool'>, <class 'bytes'>, <class 'int'>, <class 'float'>, <class 'decimal.Decimal'>)¶
- property attrs: ImmutableOrderedDict[str, str]¶
Wildcard attributes
- Return type:
- property encoding: Optional[str]¶
encoding attribute: read-only, the encoding is automatically determined from the value
- property export_src: Optional[PurePosixPath]¶
- Return type:
- property src: Optional[PurePath]¶
src attribute: file path of the content.
An absolute path (Path object) when referencing a standalone file, or a relative path (PurePosixPath object) when referencing a file in a bundle
- property value: PT¶
value attribute: The content.
Setting value to None will generate a node with a <none/> tag. Set value to NO_CONTENT to create an empty content node.
Raises
NoContent
(a subclass of ValueError) if no content was set instead of returning NO_CONTENT, RaisesFileContent
(also a subclass of ValueError’) if the node refers to an external file.
Option
¶
- class momotor.bundles.elements.options.Option(bundle)¶
An Option element encapsulating
OptionComplexType
- create(*, name, domain=None, value=None, type=None, description=None, attrs=None)¶
Set this element’s attributes
Usage:
element = Element(bundle).create(...)
- Return type:
TypeVar
(ET
, bound= Option)- Returns:
self
- static get_node_type()¶
Get the xsData node type
- Return type:
- has_inline_content()¶
Returns True if element has inline content, without processing the content
- Return type:
- has_inline_text_content()¶
Returns True if self.value would return text content (either bytes or str), without converting the content.
- Return type:
- recreate(target_bundle, *, name=None, domain=None)¶
Recreate this Option in a target bundle, optionally changing the name or domain.
- classmethod recreate_list(elements, target_bundle, filter=None, **kwargs)¶
Recreate a list of elements
- Parameters:
elements (
Optional
[Iterator
[TypeVar
(ET
, bound= Element)]]) – List of elements to recreate (can be None)target_bundle (
Bundle
) – The target bundlefilter (
Optional
[Callable
[[TypeVar
(ET
, bound= Element)],bool
]]) – An optional callable to filter the list of elements before recreation. The callable receives an element and should return a booleankwargs – Additional keyword arguments are passed on to
recreate()
- Return type:
- Returns:
a list of elements or None if elements param was None
- VALID_PROCESSED_TYPES: ClassVar = (<class 'str'>, <class 'bool'>, <class 'bytes'>, <class 'int'>, <class 'float'>, <class 'decimal.Decimal'>)¶
- property attrs: ImmutableOrderedDict[str, str]¶
Wildcard attributes
- Return type:
- property domain_parts: Tuple[str, Optional[str]]¶
A tuple with the two parts of the
domain
.If
domain
equals <main>#<sub> this is (<main>, <sub>). Ifdomain
does not contain a#
, it equals (<domain>, None).
- property encoding: Optional[str]¶
encoding attribute: read-only, the encoding is automatically determined from the value
- property type: Optional[str]¶
The type attribute. Indicates the type of the value attribute: string, integer or float
- property value: PT¶
value attribute: The content.
Setting value to None will generate a node with a <none/> tag. Set value to NO_CONTENT to create an empty content node.
Raises
NoContent
(a subclass of ValueError) if no content was set instead of returning NO_CONTENT, RaisesFileContent
(also a subclass of ValueError’) if the node refers to an external file.
Property
¶
- class momotor.bundles.elements.properties.Property(bundle)¶
A Property element encapsulating
PropertyComplexType
- create(*, name, value=None, type=None, accept=None, attrs=None)¶
Set this element’s attributes
Usage:
element = Element(bundle).create(...)
- Return type:
TypeVar
(ET
, bound= Property)- Returns:
self
- static get_node_type()¶
Get the xsData node type
- Return type:
- has_inline_content()¶
Returns True if element has inline content, without processing the content
- Return type:
- has_inline_text_content()¶
Returns True if self.value would return text content (either bytes or str), without converting the content.
- Return type:
- recreate(target_bundle, *, name=None)¶
Recreate this Property in a target bundle, optionally changing the name.
- classmethod recreate_list(elements, target_bundle, filter=None, **kwargs)¶
Recreate a list of elements
- Parameters:
elements (
Optional
[Iterator
[TypeVar
(ET
, bound= Element)]]) – List of elements to recreate (can be None)target_bundle (
Bundle
) – The target bundlefilter (
Optional
[Callable
[[TypeVar
(ET
, bound= Element)],bool
]]) – An optional callable to filter the list of elements before recreation. The callable receives an element and should return a booleankwargs – Additional keyword arguments are passed on to
recreate()
- Return type:
- Returns:
a list of elements or None if elements param was None
- VALID_PROCESSED_TYPES: ClassVar = (<class 'str'>, <class 'bool'>, <class 'bytes'>, <class 'int'>, <class 'float'>, <class 'decimal.Decimal'>)¶
- property attrs: ImmutableOrderedDict[str, str]¶
Wildcard attributes
- Return type:
- property encoding: Optional[str]¶
encoding attribute: read-only, the encoding is automatically determined from the value
- property type: Optional[str]¶
The type attribute. Indicates the type of the value attribute: string, integer or float
- property value: PT¶
value attribute: The content.
Setting value to None will generate a node with a <none/> tag. Set value to NO_CONTENT to create an empty content node.
Raises
NoContent
(a subclass of ValueError) if no content was set instead of returning NO_CONTENT, RaisesFileContent
(also a subclass of ValueError’) if the node refers to an external file.
Resource
¶
- class momotor.bundles.elements.resources.Resource(bundle)¶
A Resource element encapsulating
ResourceComplexType
- create(*, name, value=None)¶
Set this element’s attributes
Usage:
element = Element(bundle).create(...)
- static get_node_type()¶
Get the xsData node type
- Return type:
- has_inline_content()¶
Returns True if element has inline content, without processing the content
- Return type:
- has_inline_text_content()¶
Returns True if self.value would return text content (either bytes or str), without converting the content.
- Return type:
- recreate(target_bundle, *, name=None)¶
Recreate this Resource in a target bundle, optionally changing the name.
- classmethod recreate_list(elements, target_bundle, filter=None, **kwargs)¶
Recreate a list of elements
- Parameters:
elements (
Optional
[Iterator
[TypeVar
(ET
, bound= Element)]]) – List of elements to recreate (can be None)target_bundle (
Bundle
) – The target bundlefilter (
Optional
[Callable
[[TypeVar
(ET
, bound= Element)],bool
]]) – An optional callable to filter the list of elements before recreation. The callable receives an element and should return a booleankwargs – Additional keyword arguments are passed on to
recreate()
- Return type:
- Returns:
a list of elements or None if elements param was None
- property value: PT¶
value attribute: The content.
Setting value to None will generate a node with a <none/> tag. Set value to NO_CONTENT to create an empty content node.
Raises
NoContent
(a subclass of ValueError) if no content was set instead of returning NO_CONTENT, RaisesFileContent
(also a subclass of ValueError’) if the node refers to an external file.
Result
¶
- class momotor.bundles.elements.result.Result(bundle)¶
A Result element encapsulating
ResultComplexType
- copy_files_to(destination, *, files=None)¶
Copy files to a directory
- create(*, step_id, outcome, checklet=None, properties=None, options=None, files=None, parent_id=None)¶
Set this element’s attributes
Usage:
element = Element(bundle).create(...)
- static get_node_type()¶
Get the xsData node type
- Return type:
- get_option_value(name, *, domain='checklet', default=<object object>)¶
Get the value for a single option. If multiple options match, the value of the first one found will be returned
- get_options(name, *, domain='checklet')¶
Get options
- Parameters:
- Return type:
- Returns:
A filterable tuple of all matching options.
- get_properties(name)¶
Get properties
- Parameters:
name (
str
) – name of the properties to get- Return type:
- Returns:
A list of all matching properties.
- get_property_value(name, *, default=<object object>)¶
Get the value for a single property. If multiple properties match, the value of the first one found will be returned
- recreate(target_bundle, *, step_id=None)¶
Recreate this Result in a target bundle, optionally changing the step_id.
- classmethod recreate_list(elements, target_bundle, filter=None, **kwargs)¶
Recreate a list of elements
- Parameters:
elements (
Optional
[Iterator
[TypeVar
(ET
, bound= Element)]]) – List of elements to recreate (can be None)target_bundle (
Bundle
) – The target bundlefilter (
Optional
[Callable
[[TypeVar
(ET
, bound= Element)],bool
]]) – An optional callable to filter the list of elements before recreation. The callable receives an element and should return a booleankwargs – Additional keyword arguments are passed on to
recreate()
- Return type:
- Returns:
a list of elements or None if elements param was None
- set_parent_id(parent_id)¶
Set the id of the result parent
- property files: FilterableTuple[File]¶
files children
- Return type:
- property options: FilterableTuple[Option]¶
options children
- Return type:
- property outcome: Literal['pass', 'fail', 'skip', 'error']¶
outcome attribute as string value. Valid values are
pass
,fail
,skip
anderror
- Return type:
Literal
[‘pass’, ‘fail’, ‘skip’, ‘error’]
- property properties: FilterableTuple[Property]¶
properties children
- Return type:
Results
¶
- class momotor.bundles.elements.results.Results(bundle)¶
A Results element encapsulating
ResultsComplexType
- create(*, id=None, results=None)¶
Set this element’s attributes
Usage:
element = Element(bundle).create(...)
- static get_node_type()¶
Get the xsData node type
- Return type:
- classmethod recreate_list(elements, target_bundle, filter=None, **kwargs)¶
Recreate a list of elements
- Parameters:
elements (
Optional
[Iterator
[TypeVar
(ET
, bound= Element)]]) – List of elements to recreate (can be None)target_bundle (
Bundle
) – The target bundlefilter (
Optional
[Callable
[[TypeVar
(ET
, bound= Element)],bool
]]) – An optional callable to filter the list of elements before recreation. The callable receives an element and should return a booleankwargs – Additional keyword arguments are passed on to
recreate()
- Return type:
- Returns:
a list of elements or None if elements param was None
- property results: ResultKeyedTuple¶
results children
- Return type:
- class momotor.bundles.elements.results.ResultKeyedTuple(results=None)¶
The results as a
KeyedTuple
ofResult
objects.The KeyedTuple allows access as a tuple or a mapping. Results are indexed by their step_id attribute
Step
¶
- class momotor.bundles.elements.steps.Step(bundle)¶
A Step element encapsulating
StepComplexType
- copy_files_to(destination, *, files=None)¶
Copy files to a directory
- create(*, id, priority='default', depends=None, checklet=None, options=None, files=None, resources=None)¶
Set this element’s attributes
Usage:
element = Element(bundle).create(...)
- static get_node_type()¶
Get the xsData node type
- Return type:
- get_option_value(name, *, domain='checklet', default=<object object>)¶
Get the value for a single option. If multiple options match, the value of the first one found will be returned
- get_options(name, *, domain='checklet')¶
Get options
- Parameters:
- Return type:
- Returns:
A filterable tuple of all matching options.
- get_resources()¶
get all resources needed by this step
- Return type:
- classmethod recreate_list(elements, target_bundle, filter=None, **kwargs)¶
Recreate a list of elements
- Parameters:
elements (
Optional
[Iterator
[TypeVar
(ET
, bound= Element)]]) – List of elements to recreate (can be None)target_bundle (
Bundle
) – The target bundlefilter (
Optional
[Callable
[[TypeVar
(ET
, bound= Element)],bool
]]) – An optional callable to filter the list of elements before recreation. The callable receives an element and should return a booleankwargs – Additional keyword arguments are passed on to
recreate()
- Return type:
- Returns:
a list of elements or None if elements param was None
- property depends: Optional[FilterableTuple[Depends]]¶
depends
- Return type:
- property files: FilterableTuple[File]¶
files children
- Return type:
- property options: FilterableTuple[Option]¶
options children
- Return type:
- property resources: FilterableTuple[Resource]¶
resources attribute
- Return type:
Types¶
- class momotor.bundles.elements.checklets.Link(src)¶
An immutable dataclass for a reference to a link
- class momotor.bundles.elements.checklets.PackageVersion(name, version)¶
An immutable dataclass for a reference to a package with version
- class momotor.bundles.elements.checklets.Repository(bundle)¶
- create(src, type, revision=None)¶
Set this element’s attributes
Usage:
element = Element(bundle).create(...)
- recreate(target_bundle)¶
Recreate this Repository in a target bundle.
The target bundle will link to the same attachment in src, the attachment will not be copied.
- class momotor.bundles.elements.result.Outcome(value)¶
An enum for the
Result.outcome
. MirrorsOutcomeSimpleType
- classmethod condition(state)¶
Get outcome based on a condition
- Return type:
TypeVar
(OT
)- Returns:
returns
Outcome.PASS
if state is truthy, otherwise returnsOutcome.FAIL
- classmethod from_simpletype(st)¶
Create an
Outcome
from anOutcomeSimpleType
- Return type:
TypeVar
(OT
)
- to_simpletype()¶
Convert into an
OutcomeSimpleType
- Return type:
- ERROR = 'error'¶
- FAIL = 'fail'¶
- PASS = 'pass'¶
- SKIP = 'skip'¶