diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-04-16 18:26:05 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-04-16 18:26:05 +0900 |
commit | cd90fbde079ac42e930c45fcab509d49205fe54c (patch) | |
tree | fcac2d2304d943ecc07eca1f8d51359e47acaec9 | |
parent | ca2331c3f314ff53428b5ca9c8c2efc9d2dbd7cc (diff) | |
download | buildstream-cd90fbde079ac42e930c45fcab509d49205fe54c.tar.gz |
Clean up element/source instantiation code paths.
This removes the extra `kind` parameter from all of the related
codepaths, it is redundant since the `kind` attribute is already
stored on the MetaElement and MetaSource objects.
-rw-r--r-- | buildstream/_elementfactory.py | 5 | ||||
-rw-r--r-- | buildstream/_loader.py | 6 | ||||
-rw-r--r-- | buildstream/_pipeline.py | 6 | ||||
-rw-r--r-- | buildstream/_project.py | 18 | ||||
-rw-r--r-- | buildstream/_sourcefactory.py | 5 |
5 files changed, 16 insertions, 24 deletions
diff --git a/buildstream/_elementfactory.py b/buildstream/_elementfactory.py index bd7c3f240..bc1d95082 100644 --- a/buildstream/_elementfactory.py +++ b/buildstream/_elementfactory.py @@ -42,7 +42,6 @@ class ElementFactory(PluginContext): # objects on demand for a given pipeline. # # Args: - # kind (str): The kind of Element to create # context (object): The Context object for processing # project (object): The project object # artifacts (ArtifactCache): The artifact cache @@ -54,6 +53,6 @@ class ElementFactory(PluginContext): # PluginError (if the kind lookup failed) # LoadError (if the element itself took issue with the config) # - def create(self, kind, context, project, artifacts, meta): - element_type, default_config = self.lookup(kind) + def create(self, context, project, artifacts, meta): + element_type, default_config = self.lookup(meta.kind) return element_type(context, project, artifacts, meta, default_config) diff --git a/buildstream/_loader.py b/buildstream/_loader.py index 2fc7d8f0c..f3716d439 100644 --- a/buildstream/_loader.py +++ b/buildstream/_loader.py @@ -339,16 +339,14 @@ class Loader(): raise LoadError(LoadErrorReason.INVALID_DATA, "{}: Expected junction but element kind is {}".format(filename, meta_element.kind)) - element = meta_element.project.create_element(meta_element.kind, - self.artifacts, + element = meta_element.project.create_element(self.artifacts, meta_element) os.makedirs(self.context.builddir, exist_ok=True) basedir = tempfile.mkdtemp(prefix="{}-".format(element.normal_name), dir=self.context.builddir) for meta_source in meta_element.sources: - source = meta_element.project.create_source(meta_source.kind, - meta_source) + source = meta_element.project.create_source(meta_source) redundant_ref = source._load_ref() if redundant_ref: self._message(MessageType.WARN, diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py index 0cdf432a6..6fd05db87 100644 --- a/buildstream/_pipeline.py +++ b/buildstream/_pipeline.py @@ -633,9 +633,7 @@ class Pipeline(): if meta_element in self._resolved_elements: return self._resolved_elements[meta_element] - element = meta_element.project.create_element(meta_element.kind, - self._artifacts, - meta_element) + element = meta_element.project.create_element(self._artifacts, meta_element) self._resolved_elements[meta_element] = element @@ -647,7 +645,7 @@ class Pipeline(): # resolve sources for meta_source in meta_element.sources: - source = meta_element.project.create_source(meta_source.kind, meta_source) + source = meta_element.project.create_source(meta_source) redundant_ref = source._load_ref() element._add_source(source) diff --git a/buildstream/_project.py b/buildstream/_project.py index e71bdf0f1..745289c2b 100644 --- a/buildstream/_project.py +++ b/buildstream/_project.py @@ -171,16 +171,15 @@ class Project(): # Instantiate and return an element # # Args: - # kind (str): The kind of Element to create # artifacts (ArtifactCache): The artifact cache - # meta (object): The loaded MetaElement + # meta (MetaElement): The loaded MetaElement # # Returns: # (Element): A newly created Element object of the appropriate kind # - def create_element(self, kind, artifacts, meta): - element = self._element_factory.create(kind, self._context, self, artifacts, meta) - version = self._element_format_versions.get(kind, 0) + def create_element(self, artifacts, meta): + element = self._element_factory.create(self._context, self, artifacts, meta) + version = self._element_format_versions.get(meta.kind, 0) self._assert_plugin_format(element, version) return element @@ -189,15 +188,14 @@ class Project(): # Instantiate and return a Source # # Args: - # kind (str): The kind of Source to create - # meta (object): The loaded MetaSource + # meta (MetaSource): The loaded MetaSource # # Returns: # (Source): A newly created Source object of the appropriate kind # - def create_source(self, kind, meta): - source = self._source_factory.create(kind, self._context, self, meta) - version = self._source_format_versions.get(kind, 0) + def create_source(self, meta): + source = self._source_factory.create(self._context, self, meta) + version = self._source_format_versions.get(meta.kind, 0) self._assert_plugin_format(source, version) return source diff --git a/buildstream/_sourcefactory.py b/buildstream/_sourcefactory.py index 09bf1b04a..dad3ddf68 100644 --- a/buildstream/_sourcefactory.py +++ b/buildstream/_sourcefactory.py @@ -42,7 +42,6 @@ class SourceFactory(PluginContext): # objects on demand for a given pipeline. # # Args: - # kind (str): The kind of Source to create # context (object): The Context object for processing # project (object): The project object # meta (object): The loaded MetaSource @@ -54,6 +53,6 @@ class SourceFactory(PluginContext): # PluginError (if the kind lookup failed) # LoadError (if the source itself took issue with the config) # - def create(self, kind, context, project, meta): - source_type, _ = self.lookup(kind) + def create(self, context, project, meta): + source_type, _ = self.lookup(meta.kind) return source_type(context, project, meta) |