def test_dependencies(): """Test merge_dependencies with complex overlapping cases""" deps1 = ['a', 'b', 'c', 'd', {'pip': ['x', 'y', 'z']}] deps2 = ['b=2.0.*', 'e', {'pip': ['x==1.0.0', 'w']}] deps3 = ['f<3', 'a>=4'] out = [ 'a', 'a>=4', 'b', 'b=2.0.*', 'c', 'd', 'e', 'f<3', { 'pip': ['w', 'x', 'x==1.0.0', 'y', 'z'] } ] assert cm.merge_dependencies([deps1, deps2, deps3]) == out # handling simple duplicates assert cm.merge_dependencies([['a'], ['a']]) == ['a']
def merge_conda_files(files: List[Path], result_file: Path) -> None: """ Merges the given Conda environment files using the conda_merge package, and writes the merged file to disk. :param files: The Conda environment files to read. :param result_file: The location where the merge results should be written. """ # This code is a slightly modified version of conda_merge. That code can't be re-used easily # it defaults to writing to stdout env_definitions = [conda_merge.read_file(str(f)) for f in files] unified_definition = {} NAME = "name" CHANNELS = "channels" DEPENDENCIES = "dependencies" name = conda_merge.merge_names(env.get(NAME) for env in env_definitions) if name: unified_definition[NAME] = name try: channels = conda_merge.merge_channels( env.get(CHANNELS) for env in env_definitions) except conda_merge.MergeError: logging.error("Failed to merge channel priorities.") raise if channels: unified_definition[CHANNELS] = channels deps = conda_merge.merge_dependencies( env.get(DEPENDENCIES) for env in env_definitions) if deps: unified_definition[DEPENDENCIES] = deps with result_file.open("w") as f: ruamel.yaml.dump(unified_definition, f, indent=2, default_flow_style=False)