Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

target: store features and options #1504

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
warn(
warnings.warn(

"get_target_option is deprecated, access the options on the target directly.",
DeprecationWarning,
stacklevel=2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? This isn't a wrapper method.

)

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
warn(
warnings.warn(

"set_target_option is deprecated, use the YAML configuration instead.",
DeprecationWarning,
stacklevel=2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? This isn't a wrapper method.

)
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
warn(
warnings.warn(

"use get_all_features instead. For target features, use target.features instead.",
DeprecationWarning,
stacklevel=2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? This isn't a wrapper method.

)
return get_all_features()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return get_all_features()
return self.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
Loading