mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
Meta/run.py: Move arguments_generator() out of class
@staticmethod decorators seem to not work in 3.9. Just move arguments_generator() to the toplevel.
This commit is contained in:
parent
a659d7a4c2
commit
7fcce6b6c4
Notes:
sideshowbarker
2024-07-17 05:01:20 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/7fcce6b6c4 Pull-request: https://github.com/SerenityOS/serenity/pull/22792 Reviewed-by: https://github.com/ADKaster ✅
1 changed files with 27 additions and 27 deletions
54
Meta/run.py
54
Meta/run.py
|
@ -85,6 +85,33 @@ class MachineType(Enum):
|
|||
]
|
||||
|
||||
|
||||
def arguments_generator(prefix: str) -> Any:
|
||||
"""
|
||||
Construct an argument generator that returns some prefix and the member value(s) if the member value
|
||||
is not None, or returns an empty list otherwise.
|
||||
The member value is the return value of the function decorated with this decorator.
|
||||
If a default is provided, in this case we return [prefix, default] instead.
|
||||
Many of our configurable QEMU arguments work like this.
|
||||
"""
|
||||
|
||||
def decorate_function(member_accessor: Callable[[Configuration], str | list[str]]):
|
||||
def generate_arguments(self: Configuration) -> list[str]:
|
||||
member_value = member_accessor(self)
|
||||
if member_value is not None:
|
||||
if type(member_value) is list:
|
||||
# apply the prefix to every element of the list
|
||||
return list(chain(*zip(repeat(prefix), member_value)))
|
||||
# NOTE: the typechecker gets confused and can't figure out that
|
||||
# type(member_value) is *always* str here.
|
||||
elif type(member_value) is str:
|
||||
return [prefix, member_value]
|
||||
return []
|
||||
|
||||
return generate_arguments
|
||||
|
||||
return decorate_function
|
||||
|
||||
|
||||
@dataclass
|
||||
class Configuration:
|
||||
"""Run configuration, populated from command-line or environment variable data."""
|
||||
|
@ -158,33 +185,6 @@ class Configuration:
|
|||
# Arbitrary extra arguments
|
||||
extra_arguments: list[str] = field(default_factory=list)
|
||||
|
||||
@staticmethod
|
||||
def arguments_generator(prefix: str) -> Any:
|
||||
"""
|
||||
Construct an argument generator that returns some prefix and the member value(s) if the member value
|
||||
is not None, or returns an empty list otherwise.
|
||||
The member value is the return value of the function decorated with this decorator.
|
||||
If a default is provided, in this case we return [prefix, default] instead.
|
||||
Many of our configurable QEMU arguments work like this.
|
||||
"""
|
||||
|
||||
def decorate_function(member_accessor: Callable[[Configuration], str | list[str]]):
|
||||
def generate_arguments(self: Configuration) -> list[str]:
|
||||
member_value = member_accessor(self)
|
||||
if member_value is not None:
|
||||
if type(member_value) is list:
|
||||
# apply the prefix to every element of the list
|
||||
return list(chain(*zip(repeat(prefix), member_value)))
|
||||
# NOTE: the typechecker gets confused and can't figure out that
|
||||
# type(member_value) is *always* str here.
|
||||
elif type(member_value) is str:
|
||||
return [prefix, member_value]
|
||||
return []
|
||||
|
||||
return generate_arguments
|
||||
|
||||
return decorate_function
|
||||
|
||||
@property
|
||||
@arguments_generator(prefix="-accel")
|
||||
def accelerator_arguments(self) -> str | None:
|
||||
|
|
Loading…
Add table
Reference in a new issue