From 671caba7699c49e0b39aeb6bee36860332a5ea40 Mon Sep 17 00:00:00 2001 From: Douglas RAILLARD Date: Mon, 25 Mar 2019 21:14:01 +0100 Subject: [PATCH 1/3] lisa.conf: Add add_default_src to MultiSrcConf.__init__ Allow not adding the class attribute DEFAULT_SRC as a default source. --- lisa/conf.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lisa/conf.py b/lisa/conf.py index 3d809b9a4..8aae02ec7 100644 --- a/lisa/conf.py +++ b/lisa/conf.py @@ -459,15 +459,22 @@ class MultiSrcConfABC(Serializable, abc.ABC, metaclass=MultiSrcConfMeta): @classmethod @abc.abstractmethod - def from_map(cls, mapping): + def from_map(cls, mapping, add_default_src=True): raise NotImplementedError @classmethod - def from_yaml_map(cls, path): + def from_yaml_map(cls, path, add_default_src=True): """ Allow reloading from a plain mapping, to avoid having to specify a tag in the configuration file. The content is hosted under the top-level key specified in ``STRUCTURE``. + + :param path: Path to the YAML file + :type path: str + + :param add_default_src: Add a default source if available for that + class. + :type add_default_src: bool """ toplevel_key = cls.STRUCTURE.name @@ -481,7 +488,7 @@ class MultiSrcConfABC(Serializable, abc.ABC, metaclass=MultiSrcConfMeta): # "unwrap" an extra layer of toplevel key, to play well with !include if len(data) == 1 and toplevel_key in data.keys(): data = data[toplevel_key] - return cls.from_map(data) + return cls.from_map(data, add_default_src=add_default_src) def to_yaml_map(self, path): data = self.to_map() @@ -549,7 +556,7 @@ class MultiSrcConf(MultiSrcConfABC, Loggable, Mapping): when instances are built. """ - def __init__(self, conf=None, src='conf'): + def __init__(self, conf=None, src='conf', add_default_src=True): self._nested_init( structure=self.STRUCTURE, src_prio=[] @@ -558,7 +565,7 @@ class MultiSrcConf(MultiSrcConfABC, Loggable, Mapping): self.add_src(src, conf) # Give some preset in the the lowest prio source - if self.DEFAULT_SRC: + if self.DEFAULT_SRC and add_default_src: self.add_src('default', self.DEFAULT_SRC, fallback=True) @classmethod @@ -633,16 +640,16 @@ class MultiSrcConf(MultiSrcConfABC, Loggable, Mapping): return mapping @classmethod - def from_map(cls, mapping): + def from_map(cls, mapping, add_default_src=True): """ Create a new configuration instance, using the output of :meth:`to_map` """ - conf = mapping.get('conf', {}) + conf_src = mapping.get('conf', {}) src_override = mapping.get('source', {}) - plat_conf = cls(conf) - plat_conf.force_src_nested(src_override) - return plat_conf + conf = cls(conf_src, add_default_src=add_default_src) + conf.force_src_nested(src_override) + return conf def add_src(self, src, conf, filter_none=False, fallback=False): """ @@ -1116,8 +1123,8 @@ class SimpleMultiSrcConf(MultiSrcConf): this kind of configuration to keep the YAML interface simple and dict-like """ @classmethod - def from_map(cls, mapping): - return cls(mapping) + def from_map(cls, *args, **kwargs): + return cls(*args, **kwargs) def to_map(self): return dict(self._get_effective_map()) -- GitLab From e83193bec45d13f021c1d851b3ba4c96dac2e421 Mon Sep 17 00:00:00 2001 From: Douglas RAILLARD Date: Mon, 25 Mar 2019 21:15:34 +0100 Subject: [PATCH 2/3] lisa.conf: Change MultiSrcConf __init__ source name when unspecified Align better with actual usage, which allows removing a __init__ for a few subclasses. --- lisa/conf.py | 2 +- lisa/platforms/platinfo.py | 3 --- lisa/target.py | 3 --- lisa/trace.py | 3 --- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/lisa/conf.py b/lisa/conf.py index 8aae02ec7..4003f0cfd 100644 --- a/lisa/conf.py +++ b/lisa/conf.py @@ -556,7 +556,7 @@ class MultiSrcConf(MultiSrcConfABC, Loggable, Mapping): when instances are built. """ - def __init__(self, conf=None, src='conf', add_default_src=True): + def __init__(self, conf=None, src='user', add_default_src=True): self._nested_init( structure=self.STRUCTURE, src_prio=[] diff --git a/lisa/platforms/platinfo.py b/lisa/platforms/platinfo.py index 4b8429d54..28d498c1d 100644 --- a/lisa/platforms/platinfo.py +++ b/lisa/platforms/platinfo.py @@ -79,9 +79,6 @@ class PlatformInfo(MultiSrcConf, HideExekallID): )) """Some keys have a reserved meaning with an associated type.""" - def __init__(self, conf=None, src='user'): - super().__init__(conf=conf, src=src) - def add_target_src(self, target, rta_calib_res_dir, src='target', **kwargs): info = { 'nrg-model': self._nrg_model_from_target(target), diff --git a/lisa/target.py b/lisa/target.py index e9f789190..8874a53e1 100644 --- a/lisa/target.py +++ b/lisa/target.py @@ -141,9 +141,6 @@ class TargetConf(SimpleMultiSrcConf, HideExekallID): } } - def __init__(self, conf=None, src='user'): - super().__init__(conf=conf, src=src) - class Target(Loggable, HideExekallID, Configurable): """ Wrap :class:`devlib.target.Target` to provide additional features on top of diff --git a/lisa/trace.py b/lisa/trace.py index c27c572f9..25777fee5 100644 --- a/lisa/trace.py +++ b/lisa/trace.py @@ -1325,9 +1325,6 @@ class FtraceConf(SimpleMultiSrcConf, HideExekallID): KeyDesc('buffer-size', 'FTrace buffer size', [int]), )) - def __init__(self, conf=None, src='user'): - super().__init__(conf=conf, src=src) - def add_merged_src(self, src, conf, **kwargs): """ Merge-in a configuration source. -- GitLab From 5bd700789f3aba0f8e0fd574dcc5fa82609c2ed9 Mon Sep 17 00:00:00 2001 From: Douglas RAILLARD Date: Mon, 25 Mar 2019 21:23:13 +0100 Subject: [PATCH 3/3] exekall: Fix multiple uses of --conf Correctly merge configurations, without having DEFAULT_SRC overriding user configuration. Also always name the source after the basename of the YAML file. --- lisa/exekall_customize.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lisa/exekall_customize.py b/lisa/exekall_customize.py index 4ca9a4d50..5cfdd6e9a 100644 --- a/lisa/exekall_customize.py +++ b/lisa/exekall_customize.py @@ -104,7 +104,9 @@ class LISAAdaptor(AdaptorBase): for conf_path in self.args.conf: for conf_cls in conf_cls_set: try: - conf = conf_cls.from_yaml_map(conf_path) + # Do not add the default source, to avoid overriding user + # configuration with the default one. + conf = conf_cls.from_yaml_map(conf_path, add_default_src=False) except ValueError: continue else: @@ -119,13 +121,12 @@ class LISAAdaptor(AdaptorBase): # alternative sources. for (_, conf_cls), conf_and_path_seq in groupby(conf_list, key=keyfunc): conf_and_path_list = list(conf_and_path_seq) - # Since we use reversed order, we get the source override from the - # last one. - conf_and_path_list.reverse() - conf = conf_and_path_list[0][0] - for conf_src, conf_path in conf_and_path_list[1:]: - conf.add_src(conf_path, conf_src, fallback=True) + # Get the default configuration, and stack all user-defined keys + conf = conf_cls() + for conf_src, conf_path in conf_and_path_list: + src = os.path.basename(conf_path) + conf.add_src(src, conf_src) op_set.add(PrebuiltOperator( conf_cls, [conf], -- GitLab