!import-all-parameterized
tag
Constructor
ImportAllParameterizedConstructor
dataclass
Custom PyYAML constructor for the !import-all-parameterized
tag, which loads all files that
match a glob pattern into the current document, including merging the named wildcards into each
result.
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-parameterized
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
valid path pattern, optionally with named wildcards, e.g.:
my-data: !import-all-parameterized data/{file_name:*}.yml
more-data: !import-all-parameterized data/{sub_dirs:**}/info.yml
To standardize the parsing of the tag's argument, the Constructor uses an
ImportAllParameterizedSpec
dataclass
to hold the path pattern object to be matched after it's been parsed from the string in the YAML
document.
Methods:
Name | Description |
---|---|
__call__ |
Construct a node tagged as |
load |
Using a specified loader type, load the contents of the files that match the pattern into a sequence of objects, including merging the named wildcards into each result. |
Source code in yaml_extras/yaml_import.py
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
|
__call__(loader, node)
Using the specified loader, attempt to construct a node tagged as
!import-all-parameterized
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 valid path
pattern, optionally with 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, including merging the named wildcards into each result. |
Source code in yaml_extras/yaml_import.py
load(loader_type, import_spec)
Utility function which, using the specified loader type and the
ImportAllParameterizedSpec
, attempts to load the contents of the files that match the
pattern into a sequence of objects, including merging the named wildcards into the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loader_type
|
Type[Loader]
|
YAML loader type |
required |
import_spec
|
ImportAllParameterizedSpec
|
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, including merging the named wildcards into each result. |
Source code in yaml_extras/yaml_import.py
Utility dataclass
ImportAllParameterizedSpec
dataclass
Small utility dataclass for typing the parsed argument to the !import-all-parameterized
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, optionally using named wildcards. |
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 ImportAllParameterizedSpec
dataclass. It is expected that the
string contains a valid path pattern, optionally with named wildcards for extracting
some metadata strings from the matched file paths.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_pattern_str
|
str
|
String containing a path pattern to be parsed. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the PathPattern fails to be parsed from the provided string. |
Returns:
Name | Type | Description |
---|---|---|
ImportAllParameterizedSpec |
ImportAllParameterizedSpec
|
Dataclass containing the path pattern to be matched. |