summaryrefslogtreecommitdiff
path: root/src/buildstream/_loader
diff options
context:
space:
mode:
authorTristan van Berkom <tristan.vanberkom@codethink.co.uk>2020-05-30 21:18:26 +0900
committerTristan van Berkom <tristan.vanberkom@codethink.co.uk>2020-05-30 21:22:58 +0900
commit49ab0bc22c66e12651ecc1fecd3511cfcd916b3e (patch)
treefac39a6e93d4834dbea5d38fce8514399dff60dd /src/buildstream/_loader
parentf2a5dbe9f888d5b8a4fc4e6abd666fde722bc8f7 (diff)
downloadbuildstream-49ab0bc22c66e12651ecc1fecd3511cfcd916b3e.tar.gz
loader: removing the NO_PROGRESS objecttristan/remove-loader-no-progress-object
While adding a mock task object to track progress in some loader tests in commit 17144d84c2b63daf6e3aa9b42c6c773f134e8660, a new `_NO_PROGRESS` object was added as an explicit marker to denote that progress information should not be reported. This complicates the code, None should be a sufficient value for not reporting progress, while still permitting mock task objects to capture progress if desired.
Diffstat (limited to 'src/buildstream/_loader')
-rw-r--r--src/buildstream/_loader/loader.py15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/buildstream/_loader/loader.py b/src/buildstream/_loader/loader.py
index 37e00ad4b..ae729f243 100644
--- a/src/buildstream/_loader/loader.py
+++ b/src/buildstream/_loader/loader.py
@@ -37,11 +37,6 @@ from ..types import CoreWarnings, _KeyStrength
from .._message import Message, MessageType
-# This should be used to deliberately disable progress reporting when
-# collecting an element
-_NO_PROGRESS = object()
-
-
# Loader():
#
# The Loader class does the heavy lifting of parsing target
@@ -157,7 +152,7 @@ class Loader:
self._clean_caches()
# Cache how many Elements have just been loaded
- if task is not _NO_PROGRESS:
+ if task:
# Workaround for task potentially being None (because no State object)
self.loaded = task.current_progress
@@ -232,7 +227,7 @@ class Loader:
#
# Any task counting *inside* the junction will be handled by
# its loader.
- meta_element = self._collect_element_no_deps(self._elements[filename], _NO_PROGRESS)
+ meta_element = self._collect_element_no_deps(self._elements[filename])
if meta_element.kind != "junction":
raise LoadError(
"{}{}: Expected junction but element kind is {}".format(provenance_str, filename, meta_element.kind),
@@ -598,7 +593,7 @@ class Loader:
# Returns:
# (MetaElement): A partially loaded MetaElement
#
- def _collect_element_no_deps(self, element, task):
+ def _collect_element_no_deps(self, element, task=None):
# Return the already built one, if we already built it
meta_element = self._meta_elements.get(element.name)
if meta_element:
@@ -654,7 +649,7 @@ class Loader:
# Cache it now, make sure it's already there before recursing
self._meta_elements[element.name] = meta_element
- if task is not _NO_PROGRESS:
+ if task:
task.add_current_progress()
return meta_element
@@ -670,7 +665,7 @@ class Loader:
# Returns:
# (MetaElement): A fully loaded MetaElement
#
- def _collect_element(self, top_element, task):
+ def _collect_element(self, top_element, task=None):
element_queue = [top_element]
meta_element_queue = [self._collect_element_no_deps(top_element, task)]