diff options
author | Eli Schwartz <eschwartz93@gmail.com> | 2024-01-01 10:07:34 -0500 |
---|---|---|
committer | Eli Schwartz <eschwartz93@gmail.com> | 2024-02-12 18:52:42 -0500 |
commit | dbfc9d0908626c42036f0a4a1e7d8c45eaedc7d2 (patch) | |
tree | 7c3c09cef40a24427fa0e6ce946094a6ef1e181a /mesonbuild/modules | |
parent | f4f50db44155a4e050c58a74849ba8859e5daf51 (diff) | |
download | meson-dbfc9d0908626c42036f0a4a1e7d8c45eaedc7d2.zip meson-dbfc9d0908626c42036f0a4a1e7d8c45eaedc7d2.tar.gz meson-dbfc9d0908626c42036f0a4a1e7d8c45eaedc7d2.tar.bz2 |
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.
Diffstat (limited to 'mesonbuild/modules')
-rw-r--r-- | mesonbuild/modules/dlang.py | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/mesonbuild/modules/dlang.py b/mesonbuild/modules/dlang.py index ed4ac8c..34fea90 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 |