From dbfc9d0908626c42036f0a4a1e7d8c45eaedc7d2 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 1 Jan 2024 10:07:34 -0500 Subject: [PATCH] dlang module: simplify dependency handling with DRY It can be a list or a single dependency, but the same logic happens either way. Instead of manually expanding the logic for both cases, just convert it to a list as needed. --- mesonbuild/modules/dlang.py | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/mesonbuild/modules/dlang.py b/mesonbuild/modules/dlang.py index ed4ac8c62..34fea9081 100644 --- a/mesonbuild/modules/dlang.py +++ b/mesonbuild/modules/dlang.py @@ -13,7 +13,7 @@ from .. import mlog from ..dependencies import Dependency from ..dependencies.dub import DubDependency from ..interpreterbase import typed_pos_args -from ..mesonlib import Popen_safe, MesonException +from ..mesonlib import Popen_safe, MesonException, listify class DlangModule(ExtensionModule): class_dubbin = None @@ -69,27 +69,18 @@ class DlangModule(ExtensionModule): for key, value in kwargs.items(): if key == 'dependencies': + values = listify(value, flatten=False) config[key] = {} - if isinstance(value, list): - for dep in value: - if isinstance(dep, Dependency): - name = dep.get_name() - ret, res = self._call_dubbin(['describe', name]) - if ret == 0: - version = dep.get_version() - if version is None: - config[key][name] = '' - else: - config[key][name] = version - elif isinstance(value, Dependency): - name = value.get_name() - ret, res = self._call_dubbin(['describe', name]) - if ret == 0: - version = value.get_version() - if version is None: - config[key][name] = '' - else: - config[key][name] = version + for dep in values: + if isinstance(dep, Dependency): + name = dep.get_name() + ret, res = self._call_dubbin(['describe', name]) + if ret == 0: + version = dep.get_version() + if version is None: + config[key][name] = '' + else: + config[key][name] = version else: config[key] = value