!import-all
tag
Constructor
ImportAllConstructor
dataclass
Custom PyYAML constructor for the !import-all
tag, which loads all files that match a
glob pattern into the current document.
As a Constructor, it can be called with a yaml.Loader
and a yaml.Node
to attempt to
construct a given node tagged as !import-all
into a Python object. In any valid use of the
tag, this node should always be a scalar string, and it should be in the form of a path glob
with no named wildcards, e.g.:
To standardize the parsing of the tag's argument, the Constructor uses an
ImportAllSpec
dataclass to hold the path pattern
object to be matched after it's been parsed from the string in the YAML document.
Source code in yaml_extras/yaml_import.py
__call__(loader, node)
Using the specified loader, attempt to construct a node tagged as !import-all
into a
sequence of Python objects.
For any valid use of the tag, the node should always be a scalar string, and it should be in the form of a path glob with no named wildcards.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loader
|
Loader
|
YAML loader |
required |
node
|
Node
|
|
required |
Returns:
Type | Description |
---|---|
list[Any]
|
list[Any]: List of objects loaded from the files that match the pattern. |
Source code in yaml_extras/yaml_import.py
load(loader_type, import_spec)
Utility function which, using the specified loader type and the ImportAllSpec
, attempts
to load all files that match the pattern into a list of objects (one per each file matched).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loader_type
|
Type[Loader]
|
YAML loader type |
required |
import_spec
|
ImportAllSpec
|
Dataclass containing the path pattern to be matched. |
required |
Returns:
Type | Description |
---|---|
list[Any]
|
list[Any]: List of objects loaded from the files that match the pattern. |
Source code in yaml_extras/yaml_import.py
Utility dataclass
ImportAllSpec
dataclass
Small utility dataclass for typing the parsed argument to the !import-all
tag as a
specialized PathPattern
type. E.g.,
Shall be parsed as,
Attributes:
Name | Type | Description |
---|---|---|
path_pattern |
PathPattern
|
Pattern for matching files to be imported. |
Methods:
Name | Description |
---|---|
from_str |
Parse a string into an |
Source code in yaml_extras/yaml_import.py
from_str(path_pattern_str)
classmethod
Parse a string into an ImportAllSpec
dataclass. It is expected that the string is a
valid path pattern with no named wildcards.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_pattern_str
|
str
|
String containing a path pattern to be parsed. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the user supplies named wildcards in the path pattern, which should only
be used in |
Returns:
Name | Type | Description |
---|---|---|
ImportAllSpec |
ImportAllSpec
|
Dataclass containing the path pattern to be matched. |