Skip to content

Commit

Permalink
Fixed a bug where additional context wasn't passed to the composition.
Browse files Browse the repository at this point in the history
  • Loading branch information
coordt committed May 10, 2023
1 parent 71313de commit bd8b571
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cookie_composer/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from pydantic import AnyHttpUrl, BaseModel, DirectoryPath, Field, root_validator

from cookie_composer.data_merge import comprehensive_merge
from cookie_composer.exceptions import GitError, MissingCompositionFileError
from cookie_composer.matching import rel_fnmatch

Expand Down Expand Up @@ -202,12 +203,13 @@ def is_composition_file(path_or_url: Union[str, Path]) -> bool:
return Path(path_or_url).suffix in {".yaml", ".yml"}


def read_composition(path_or_url: Union[str, Path]) -> Composition:
def read_composition(path_or_url: Union[str, Path], **kwargs) -> Composition:
"""
Read a YAML file and return a :class:`~.Composition`.
Args:
path_or_url: The location of the configuration file
kwargs: Additional keyword arguments passed to the composition
Returns:
A composition
Expand All @@ -225,7 +227,11 @@ def read_composition(path_or_url: Union[str, Path]) -> Composition:
of = fsspec.open(path_or_url, mode="rt")
with of as f:
contents = list(yaml.load_all(f))
templates = [LayerConfig(**doc) for doc in contents]
templates = []
for doc in contents:
new_doc = comprehensive_merge(doc, kwargs)
templates.append(LayerConfig(**new_doc))

for tmpl in templates:
tmpl.template = urllib.parse.urljoin(str(path_or_url), str(tmpl.template))

Expand Down Expand Up @@ -354,7 +360,13 @@ def get_composition_from_path_or_url(
The composition object.
"""
if is_composition_file(path_or_url):
composition = read_composition(path_or_url)
composition = read_composition(
path_or_url=path_or_url,
checkout=checkout,
no_input=no_input or default_config,
skip_if_file_exists=skip_if_file_exists,
context=initial_context or {},
)
logger.info(f"Rendering composition {path_or_url} to {output_dir}.")
else:
overwrite_rules = ["*"] if overwrite_if_exists else []
Expand Down

0 comments on commit bd8b571

Please sign in to comment.