Skip to content

io

Functions for handling input/output operations.

deserialize_composition(
    composition_info: List[dict],
    local_path: Optional[Path] = None,
    **kwargs
) -> Composition

Deserialize a composition from output.

deserialize_layer(
    layer_info: dict,
    local_path: Optional[Path] = None,
    **kwargs: Any
) -> LayerConfig

Deserialize a layer configuration from a rendered layer.

deserialize_rendered_composition(
    composition_info: List[dict], location: Path
) -> RenderedComposition

Deserialize a rendered composition from output.

deserialize_rendered_layer(
    rendered_layer_info: dict, location: Path
) -> RenderedLayer

Deserialize a rendered layer from output.

Parameters:

rendered_layer_info

A dictionary containing the rendered layer information

TYPE: dict

location

The location of the rendered layer, typically the parent directory of the parent directory of the .composition.yaml file

TYPE: Path

Returns:

RenderedLayer

A rendered layer object

get_composition_from_path_or_url(
    path_or_url: str,
    checkout: Optional[str] = None,
    default_config: bool = False,
    directory: Optional[str] = None,
    no_input: bool = False,
    output_dir: Optional[Path] = None,
    overwrite_if_exists: bool = False,
    skip_if_file_exists: bool = False,
    initial_context: Optional[
        MutableMapping[str, Any]
    ] = None,
) -> Composition

Generate a Composition from a path or URL.

Parameters:

path_or_url

The path or url to the composition file or template

TYPE: str

checkout

The branch, tag or commit to check out after git clone

TYPE: Optional[str]

DEFAULT: None

default_config

Do not load a config file. Use the defaults instead

TYPE: bool

DEFAULT: False

directory

Directory within repo that holds cookiecutter.json file

TYPE: Optional[str]

DEFAULT: None

no_input

If True force each layer’s no_input attribute to True

TYPE: bool

DEFAULT: False

output_dir

Where to generate the project

TYPE: Optional[Path]

DEFAULT: None

overwrite_if_exists

Overwrite the contents of the output directory if it already exists

TYPE: bool

DEFAULT: False

skip_if_file_exists

Skip the files in the corresponding directories if they already exist

TYPE: bool

DEFAULT: False

initial_context

The initial context for the composition

TYPE: Optional[MutableMapping[str, Any]]

DEFAULT: None

Returns:

Composition

The composition object.

is_composition_file(path_or_url: Union[str, Path]) -> bool

Return True if the filename a composition file.

Parameters:

path_or_url

The path or URL to check

TYPE: Union[str, Path]

Returns:

bool

True if the path is a configuration file.

read_composition(
    path_or_url: Union[str, Path], **kwargs: Any
) -> Composition

Read a YAML file and return a Composition.

Parameters:

path_or_url

The location of the configuration file

TYPE: Union[str, Path]

**kwargs

Additional keyword arguments passed to the composition

TYPE: Any

DEFAULT: {}

Returns:

Composition

A composition

read_rendered_composition(
    path: Path,
) -> RenderedComposition

Read a .composition.yaml from a rendered project.

Parameters:

path

The path to the .composition.yaml file to read

TYPE: Path

Returns:

RenderedComposition

The rendered composition information

read_yaml(path_or_url: Union[str, Path]) -> List[dict]

Read a YAML file and return a list of dictionaries.

serialize_composition(
    layers: List[LayerConfig],
) -> List[dict]

Serialize a composition for output.

serialize_layer(layer: LayerConfig) -> dict

Serialize the layer configuration for outputting in a rendered layer.

serialize_rendered_composition(
    composition: RenderedComposition,
) -> List[dict]

Serialize a rendered composition for output.

serialize_rendered_layer(
    rendered_layer: RenderedLayer,
) -> dict

Serialize a rendered layer for output.

write_rendered_composition(
    composition: RenderedComposition,
) -> None

Write the composition file using the rendered layers to the appropriate place.

Parameters:

composition

The rendered composition object to export

TYPE: RenderedComposition

write_yaml(path: Path, contents: List[dict]) -> None

Write a YAML file.