diff --git a/pyproject.toml b/pyproject.toml index 5dfc835..af94587 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "voicemeeter-api" -version = "2.3.0" +version = "2.3.1" description = "A Python wrapper for the Voiceemeter API" authors = ["onyx-and-iris "] license = "MIT" diff --git a/voicemeeterlib/remote.py b/voicemeeterlib/remote.py index 8bd8a03..5e61896 100644 --- a/voicemeeterlib/remote.py +++ b/voicemeeterlib/remote.py @@ -1,3 +1,4 @@ +import copy import ctypes as ct import logging import time @@ -13,7 +14,7 @@ from .kinds import KindId from .misc import Midi, VmGui from .subject import Subject from .updater import Producer, Updater -from .util import grouper, polling, script +from .util import deep_merge, grouper, polling, script logger = logging.getLogger(__name__) @@ -306,14 +307,18 @@ class Remote(CBindings): f"Known configs: {list(self.configs.keys())}", ) try: - config = self.configs[name].copy() + config = self.configs[name] except KeyError as e: self.logger.error(("\n").join(ERR_MSG)) raise VMError(("\n").join(ERR_MSG)) from e if "extends" in config: - extended = config.pop("extends") - config = self.configs[extended] | config + extended = config["extends"] + config = { + k: v + for k, v in deep_merge(self.configs[extended], config) + if k not in ("extends") + } self.logger.debug( f"profile '{name}' extends '{extended}', profiles merged.." ) diff --git a/voicemeeterlib/util.py b/voicemeeterlib/util.py index f826fc7..783a081 100644 --- a/voicemeeterlib/util.py +++ b/voicemeeterlib/util.py @@ -1,3 +1,4 @@ +import copy import functools from itertools import zip_longest from typing import Iterator @@ -70,3 +71,17 @@ def grouper(n, iterable, fillvalue=None): """ args = [iter(iterable)] * n return zip_longest(fillvalue=fillvalue, *args) + + +def deep_merge(dict1, dict2): + """Generator function for deep merging two dicts""" + for k in set(dict1) | set(dict2): + if k in dict1 and k in dict2: + if isinstance(dict1[k], dict) and isinstance(dict2[k], dict): + yield k, dict(deep_merge(dict1[k], dict2[k])) + else: + yield k, dict2[k] + elif k in dict1: + yield k, dict1[k] + else: + yield k, dict2[k]