Skip to content

Commit

Permalink
target: store features and options
Browse files Browse the repository at this point in the history
Instead of always having to revert to the configuration for options and
features, store both directly in the target object. Also deprecate the
setters and getters for both in the configuration object.

Reasoning is that setters are not required for this, the YAML
configuration should be changed instead. The getters are not required if
the options and features are bound to the target which is more intuitive
anyway.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
  • Loading branch information
Emantor committed Sep 27, 2024
1 parent 6b54121 commit c9e9555
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
11 changes: 11 additions & 0 deletions labgrid/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ def get_target_option(self, target, name, default=None):
configuration, or if the target can not be found in the
configuration.
"""
warn(
"get_target_option is deprecated, access the options on the target directly.",
DeprecationWarning,
stacklevel=2,
)

if target not in self.data['targets']:
raise KeyError(f"No target '{target}' found in configuration")

Expand All @@ -224,6 +230,11 @@ def set_target_option(self, target, name, value):
KeyError: if the requested target can not be found in the
configuration
"""
warn(
"set_target_option is deprecated, use the YAML configuration instead.",
DeprecationWarning,
stacklevel=2,
)
assert isinstance(target, str)
assert isinstance(name, str)

Expand Down
8 changes: 8 additions & 0 deletions labgrid/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ def get_features(self):
return self.config.get_features()

def get_target_features(self):
warn(
"use get_all_features instead. For target features, use target.features instead.",
DeprecationWarning,
stacklevel=2,
)
return get_all_features()

def get_all_features(self):
flags = set()
for value in self.config.get_targets().values():
flags = flags | set(value.get('features', {}))
Expand Down
4 changes: 3 additions & 1 deletion labgrid/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ def make_driver(self, target, driver, name, args):
def make_target(self, name, config, *, env=None):
from .target import Target

target = Target(name, env=env)
target = Target(name, env=env,
features=frozenset(config.get('features')),
options=frozenset(config.get('options')))
for item in TargetFactory._convert_to_named_list(config.get('resources', {})):
resource = item.pop('cls')
name = item.pop('name', None)
Expand Down
2 changes: 1 addition & 1 deletion labgrid/pytestplugin/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def pytest_collection_modifyitems(config, items):
if not env:
return

have_feature = env.get_features() | env.get_target_features()
have_feature = env.get_features() | env.get_all_features()

for item in items:
want_feature = set()
Expand Down
2 changes: 2 additions & 0 deletions labgrid/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
class Target:
name = attr.ib(validator=attr.validators.instance_of(str))
env = attr.ib(default=None)
features = attr.ib(default=set())
options = attr.ib(default=set())

def __attrs_post_init__(self):
self.log = logging.getLogger(f"target({self.name})")
Expand Down

0 comments on commit c9e9555

Please sign in to comment.