mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:38:11 +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
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
|
@dataclass
|
||||||
class Configuration:
|
class Configuration:
|
||||||
"""Run configuration, populated from command-line or environment variable data."""
|
"""Run configuration, populated from command-line or environment variable data."""
|
||||||
|
@ -158,33 +185,6 @@ class Configuration:
|
||||||
# Arbitrary extra arguments
|
# Arbitrary extra arguments
|
||||||
extra_arguments: list[str] = field(default_factory=list)
|
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
|
@property
|
||||||
@arguments_generator(prefix="-accel")
|
@arguments_generator(prefix="-accel")
|
||||||
def accelerator_arguments(self) -> str | None:
|
def accelerator_arguments(self) -> str | None:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue