diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2024-08-29 09:23:05 -0700 |
|---|---|---|
| committer | Jussi Pakkanen <jpakkane@gmail.com> | 2025-02-05 17:45:38 +0200 |
| commit | b32e4e87b1c88eb235389c4f60f540154d720970 (patch) | |
| tree | ec52cf7639df0b937d9faee9e9d15e849a0d7384 | |
| parent | 4aa0e93922355c01c86ad41d985ec24e4ec8a1f6 (diff) | |
| download | meson-b32e4e87b1c88eb235389c4f60f540154d720970.tar.gz | |
options: Add a printable_choices method to UserOption
This provides a method to get choices for options in a printable form.
The goal is to make refactoring options simpler.
| -rw-r--r-- | mesonbuild/mintro.py | 7 | ||||
| -rw-r--r-- | mesonbuild/options.py | 9 |
2 files changed, 12 insertions, 4 deletions
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index b9b09c557..cd68911ce 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -315,14 +315,15 @@ def list_buildoptions(coredata: cdata.CoreData, subprojects: T.Optional[T.List[s elif isinstance(opt, options.UserBooleanOption): typestr = 'boolean' elif isinstance(opt, options.UserComboOption): - optdict['choices'] = opt.choices + optdict['choices'] = opt.printable_choices() typestr = 'combo' elif isinstance(opt, options.UserIntegerOption): typestr = 'integer' elif isinstance(opt, options.UserArrayOption): typestr = 'array' - if opt.choices: - optdict['choices'] = opt.choices + c = opt.printable_choices() + if c: + optdict['choices'] = c else: raise RuntimeError("Unknown option type") optdict['type'] = typestr diff --git a/mesonbuild/options.py b/mesonbuild/options.py index aea38ec3e..d0cf231dc 100644 --- a/mesonbuild/options.py +++ b/mesonbuild/options.py @@ -1,6 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright 2013-2024 Contributors to the The Meson project -# Copyright © 2019-2024 Intel Corporation +# Copyright © 2019-2025 Intel Corporation from __future__ import annotations from collections import OrderedDict @@ -265,6 +265,13 @@ class UserOption(T.Generic[_T], HoldableObject): assert isinstance(self.value, (str, int, bool, list)) return self.value + def printable_choices(self) -> T.Optional[T.List[str]]: + if not self.choices: + return None + if isinstance(self.choices, str): + return [self.choices] + return [str(c) for c in self.choices] + # Check that the input is a valid value and return the # "cleaned" or "native" version. For example the Boolean # option could take the string "true" and return True. |
