aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2023-01-17 13:46:01 -0800
committerEli Schwartz <eschwartz93@gmail.com>2023-01-20 00:18:42 -0500
commitc8b8e7e73221ccefdd79c9807d67241f60963e6c (patch)
tree0cccdf13df8985a572b065cd14b3cfc187913e77
parent432c46e67c3f528e956f6a696ba198bd0f89dbc0 (diff)
downloadmeson-c8b8e7e73221ccefdd79c9807d67241f60963e6c.zip
meson-c8b8e7e73221ccefdd79c9807d67241f60963e6c.tar.gz
meson-c8b8e7e73221ccefdd79c9807d67241f60963e6c.tar.bz2
coredata: allow deprecation to be passed to Option initializer
Instead of requiring it to be set outside the initializer
-rw-r--r--mesonbuild/coredata.py41
1 files changed, 24 insertions, 17 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 3b87896..893ac45 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -1,5 +1,4 @@
# Copyright 2012-2022 The Meson development team
-
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@@ -76,14 +75,15 @@ class MesonVersionMismatchException(MesonException):
class UserOption(T.Generic[_T], HoldableObject):
def __init__(self, description: str, choices: T.Optional[T.Union[str, T.List[_T]]],
- yielding: bool):
+ yielding: bool,
+ deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False):
super().__init__()
self.choices = choices
self.description = description
if not isinstance(yielding, bool):
raise MesonException('Value of "yielding" must be a boolean.')
self.yielding = yielding
- self.deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False
+ self.deprecated = deprecated
def listify(self, value: T.Any) -> T.List[T.Any]:
return [value]
@@ -102,8 +102,9 @@ class UserOption(T.Generic[_T], HoldableObject):
self.value = self.validate_value(newvalue)
class UserStringOption(UserOption[str]):
- def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING):
- super().__init__(description, None, yielding)
+ def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING,
+ deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False):
+ super().__init__(description, None, yielding, deprecated)
self.set_value(value)
def validate_value(self, value: T.Any) -> str:
@@ -112,8 +113,9 @@ class UserStringOption(UserOption[str]):
return value
class UserBooleanOption(UserOption[bool]):
- def __init__(self, description: str, value, yielding: bool = DEFAULT_YIELDING) -> None:
- super().__init__(description, [True, False], yielding)
+ def __init__(self, description: str, value, yielding: bool = DEFAULT_YIELDING,
+ deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False):
+ super().__init__(description, [True, False], yielding, deprecated)
self.set_value(value)
def __bool__(self) -> bool:
@@ -131,7 +133,8 @@ class UserBooleanOption(UserOption[bool]):
raise MesonException('Value %s is not boolean (true or false).' % value)
class UserIntegerOption(UserOption[int]):
- def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING):
+ def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING,
+ deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False):
min_value, max_value, default_value = value
self.min_value = min_value
self.max_value = max_value
@@ -141,7 +144,7 @@ class UserIntegerOption(UserOption[int]):
if max_value is not None:
c.append('<=' + str(max_value))
choices = ', '.join(c)
- super().__init__(description, choices, yielding)
+ super().__init__(description, choices, yielding, deprecated)
self.set_value(default_value)
def validate_value(self, value: T.Any) -> int:
@@ -169,8 +172,9 @@ class OctalInt(int):
return oct(int(self))
class UserUmaskOption(UserIntegerOption, UserOption[T.Union[str, OctalInt]]):
- def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING):
- super().__init__(description, (0, 0o777, value), yielding)
+ def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING,
+ deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False):
+ super().__init__(description, (0, 0o777, value), yielding, deprecated)
self.choices = ['preserve', '0000-0777']
def printable_value(self) -> str:
@@ -191,8 +195,9 @@ class UserUmaskOption(UserIntegerOption, UserOption[T.Union[str, OctalInt]]):
class UserComboOption(UserOption[str]):
def __init__(self, description: str, choices: T.List[str], value: T.Any,
- yielding: bool = DEFAULT_YIELDING):
- super().__init__(description, choices, yielding)
+ yielding: bool = DEFAULT_YIELDING,
+ deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False):
+ super().__init__(description, choices, yielding, deprecated)
if not isinstance(self.choices, list):
raise MesonException('Combo choices must be an array.')
for i in self.choices:
@@ -218,8 +223,9 @@ class UserArrayOption(UserOption[T.List[str]]):
def __init__(self, description: str, value: T.Union[str, T.List[str]],
split_args: bool = False, user_input: bool = False,
allow_dups: bool = False, yielding: bool = DEFAULT_YIELDING,
- choices: T.Optional[T.List[str]] = None) -> None:
- super().__init__(description, choices if choices is not None else [], yielding)
+ choices: T.Optional[T.List[str]] = None,
+ deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False):
+ super().__init__(description, choices if choices is not None else [], yielding, deprecated)
self.split_args = split_args
self.allow_dups = allow_dups
self.value = self.validate_value(value, user_input=user_input)
@@ -277,8 +283,9 @@ class UserArrayOption(UserOption[T.List[str]]):
class UserFeatureOption(UserComboOption):
static_choices = ['enabled', 'disabled', 'auto']
- def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING):
- super().__init__(description, self.static_choices, value, yielding)
+ def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING,
+ deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False):
+ super().__init__(description, self.static_choices, value, yielding, deprecated)
self.name: T.Optional[str] = None # TODO: Refactor options to all store their name
def is_enabled(self) -> bool: