mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2024-11-22 11:00:47 +00:00
deep_merge implemented
recursively merges dicts in profiles patch bump
This commit is contained in:
parent
b0acde6a52
commit
278566c2e0
@ -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 <code@onyxandiris.online>"]
|
||||
license = "MIT"
|
||||
|
@ -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.."
|
||||
)
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user