From e23f6b397e07df6043bf7dbb64ef5426c3459aef Mon Sep 17 00:00:00 2001 From: Angelos Evripiotis Date: Thu, 7 Mar 2019 11:14:27 +0000 Subject: element: refactor, rm unused temp var --- buildstream/element.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/buildstream/element.py b/buildstream/element.py index d4e4a30ed..72b44aa9a 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -245,8 +245,7 @@ class Element(Plugin): self.__variables = Variables(variables) # Collect the composited environment now that we have variables - env = self.__extract_environment(meta) - self.__environment = env + self.__environment = self.__extract_environment(meta) # Collect the environment nocache blacklist list nocache = self.__extract_env_nocache(meta) -- cgit v1.2.1 From d8fc3e8f6e3d20860d71eb847a05ed795c46e935 Mon Sep 17 00:00:00 2001 From: Angelos Evripiotis Date: Tue, 12 Mar 2019 17:19:14 +0000 Subject: Element.__init_defaults: init if no plugin_conf Still initialize `Element.__defaults` as usual, even if a `plugin_conf` is not specified. As part of the work on !1101 to introduce `ArtifactElement`s, a special case for `__init_defaults` was made, such that none of the usual defaults would be loaded. This seems to be because it has no config and none of the defaults are required by ArtifactElement, although they don't seem to adversely affect it. Instead, treat a 'None' `plugin_conf` in the same way as the existing case of a missing file. This avoids the appearance of having plugin-specific behaviour in the base-class, and is perhaps less puzzling to new contributors. --- buildstream/element.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/buildstream/element.py b/buildstream/element.py index 72b44aa9a..5d1f0622b 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -2369,20 +2369,18 @@ class Element(Plugin): defaults['public'] = element_public def __init_defaults(self, plugin_conf): - if plugin_conf is None: - return - # Defaults are loaded once per class and then reused # if not self.__defaults_set: - - # Load the plugin's accompanying .yaml file if one was provided defaults = {} - try: - defaults = _yaml.load(plugin_conf, os.path.basename(plugin_conf)) - except LoadError as e: - if e.reason != LoadErrorReason.MISSING_FILE: - raise e + + if plugin_conf is not None: + # Load the plugin's accompanying .yaml file if one was provided + try: + defaults = _yaml.load(plugin_conf, os.path.basename(plugin_conf)) + except LoadError as e: + if e.reason != LoadErrorReason.MISSING_FILE: + raise e # Special case; compose any element-wide split-rules declarations self.__compose_default_splits(defaults) -- cgit v1.2.1 From 499f6115fffbca18bb18dd1ab937872904aac56f Mon Sep 17 00:00:00 2001 From: Angelos Evripiotis Date: Tue, 12 Mar 2019 17:27:22 +0000 Subject: element.py: remove redundant `__defaults_set` Use the conventional `None` value to indicate that the class variable `__defaults` is not yet initialized. This lets us remove `__defaults_set`. --- buildstream/element.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/buildstream/element.py b/buildstream/element.py index 5d1f0622b..9ec65edaa 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -132,8 +132,7 @@ class Element(Plugin): All elements derive from this class, this interface defines how the core will be interacting with Elements. """ - __defaults = {} # The defaults from the yaml file and project - __defaults_set = False # Flag, in case there are no defaults at all + __defaults = None # The defaults from the yaml file and project __instantiated_elements = {} # A hash of Element by MetaElement __redundant_source_refs = [] # A list of (source, ref) tuples which were redundantly specified @@ -2371,7 +2370,7 @@ class Element(Plugin): def __init_defaults(self, plugin_conf): # Defaults are loaded once per class and then reused # - if not self.__defaults_set: + if self.__defaults is None: defaults = {} if plugin_conf is not None: @@ -2399,7 +2398,6 @@ class Element(Plugin): # Set the data class wide type(self).__defaults = defaults - type(self).__defaults_set = True # This will resolve the final environment to be used when # creating sandboxes for this element -- cgit v1.2.1