Skip to content

data_merge

Tools for merging data.

COMPREHENSIVE = 'comprehensive'

Comprehensively merge the two data structures.

  • Scalars are overwritten by the new values
  • lists are merged and de-duplicated
  • dicts are recursively merged
DO_NOT_MERGE = 'do-not-merge'

Do not merge the data, use the file path to determine what to do.

NESTED_OVERWRITE = 'nested-overwrite'

Merge deeply nested structures and overwrite at the lowest level; A deep dict.update().

OVERWRITE = 'overwrite'

Overwrite at the top level like dict.update().

Bases: ChainMap

Provides merging and convenience functions for managing contexts.

is_empty: bool

The context has only one mapping and it is empty.

flatten() -> MutableMapping

Comprehensively merge all the maps into a single mapping.

comprehensive_merge(*args: MutableMapping) -> Any

Merges data comprehensively.

All arguments must be of the same type.

  • Scalars are overwritten by the new values
  • lists are merged and de-duplicated
  • dicts are recursively merged

Parameters:

*args

List of dicts to merge with the first one the base

TYPE: MutableMapping

DEFAULT: ()

Returns:

Any

The merged data

deep_merge(*dicts: dict) -> dict

Merges dicts deeply.

Parameters:

*dicts

List of dicts to merge with the first one as the base

TYPE: dict

DEFAULT: ()

Returns:

dict

The merged dict

TYPE: dict

freeze_data(obj: Any) -> Any

Check type and recursively return a new read-only object.

get_merge_strategy(
    path: Path, merge_strategies: Dict[str, str]
) -> str

Return the merge strategy of the path based on the layer configured rules.

Files that are not mergable return DO_NOT_MERGE.

Parameters:

path

The file path to evaluate.

TYPE: Path

merge_strategies

The glob pattern->strategy mapping

TYPE: Dict[str, str]

Returns:

str

The appropriate merge strategy.

merge_iterables(iter1: Iterable, iter2: Iterable) -> set

Merge and de-duplicate a bunch of lists into a single list.

Order is not guaranteed.

Parameters:

iter1

An Iterable

TYPE: Iterable

iter2

An Iterable

TYPE: Iterable

Returns:

set

The merged, de-duplicated sequence as a set