diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-03-20 17:46:01 +0000 |
---|---|---|
committer | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-03-21 11:14:00 +0000 |
commit | 2ee5fc900e00c2ce2e7d4aef96eb15185bb01aad (patch) | |
tree | 0e5235a4f41a48be409546e002c059271d986523 | |
parent | 97c6fc32eeaa5b463863c8d3d275ffc55f60d91f (diff) | |
download | buildstream-2ee5fc900e00c2ce2e7d4aef96eb15185bb01aad.tar.gz |
plugin.py: make _unique_id accessible to the core
_unique_id is set at instantiation and never modified afterwards.
Since the guildelines for the project is to never modify directly
an object's state, accessing _unique_id as an attribute is safe.
Moreover this will save us some cost of calling functions.
-rw-r--r-- | buildstream/_frontend/app.py | 2 | ||||
-rw-r--r-- | buildstream/_scheduler/jobs/elementjob.py | 4 | ||||
-rw-r--r-- | buildstream/_scheduler/queues/queue.py | 2 | ||||
-rw-r--r-- | buildstream/element.py | 8 | ||||
-rw-r--r-- | buildstream/plugin.py | 15 | ||||
-rw-r--r-- | buildstream/sandbox/sandbox.py | 2 |
6 files changed, 13 insertions, 20 deletions
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py index 67fcc8370..a659b202a 100644 --- a/buildstream/_frontend/app.py +++ b/buildstream/_frontend/app.py @@ -531,7 +531,7 @@ class App(): queue = job.queue # Get the last failure message for additional context - failure = self._fail_messages.get(element._get_unique_id()) + failure = self._fail_messages.get(element._unique_id) # XXX This is dangerous, sometimes we get the job completed *before* # the failure message reaches us ?? diff --git a/buildstream/_scheduler/jobs/elementjob.py b/buildstream/_scheduler/jobs/elementjob.py index fa0d34fb3..fb5d38e11 100644 --- a/buildstream/_scheduler/jobs/elementjob.py +++ b/buildstream/_scheduler/jobs/elementjob.py @@ -73,7 +73,7 @@ class ElementJob(Job): self._complete_cb = complete_cb # The complete callable function # Set the task wide ID for logging purposes - self.set_task_id(element._get_unique_id()) + self.set_task_id(element._unique_id) @property def element(self): @@ -100,7 +100,7 @@ class ElementJob(Job): args = dict(kwargs) args['scheduler'] = True self._scheduler.context.message( - Message(self._element._get_unique_id(), + Message(self._element._unique_id, message_type, message, **args)) diff --git a/buildstream/_scheduler/queues/queue.py b/buildstream/_scheduler/queues/queue.py index 9f0563fa5..1efcffc16 100644 --- a/buildstream/_scheduler/queues/queue.py +++ b/buildstream/_scheduler/queues/queue.py @@ -316,7 +316,7 @@ class Queue(): # a message for the element they are processing def _message(self, element, message_type, brief, **kwargs): context = element._get_context() - message = Message(element._get_unique_id(), message_type, brief, **kwargs) + message = Message(element._unique_id, message_type, brief, **kwargs) context.message(message) def _element_log_path(self, element): diff --git a/buildstream/element.py b/buildstream/element.py index 5e7b7e4e6..c7289f54a 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -1412,7 +1412,7 @@ class Element(Plugin): for index, source in enumerate(self.__sources): old_ref = source.get_ref() new_ref = source._track(self.__sources[0:index]) - refs.append((source._get_unique_id(), new_ref)) + refs.append((source._unique_id, new_ref)) # Complimentary warning that the new ref will be unused. if old_ref != new_ref and self._get_workspace(): @@ -2952,7 +2952,7 @@ class Element(Plugin): # def __update_state_recursively(self): queue = UniquePriorityQueue() - queue.push(self.__node_id, self) + queue.push(self._unique_id, self) while queue: element = queue.pop() @@ -2962,10 +2962,10 @@ class Element(Plugin): if element.__ready_for_runtime != old_ready_for_runtime: for rdep in element.__reverse_dependencies_for_build: - queue.push(rdep.__node_id, rdep) + queue.push(rdep._unique_id, rdep) for rdep in element.__reverse_dependencies_for_runtime: - queue.push(rdep.__node_id, rdep) + queue.push(rdep._unique_id, rdep) def _overlap_error_detail(f, forbidden_overlap_elements, elements): diff --git a/buildstream/plugin.py b/buildstream/plugin.py index 9769debca..a235feb7f 100644 --- a/buildstream/plugin.py +++ b/buildstream/plugin.py @@ -216,10 +216,10 @@ class Plugin(): # Unique ID # # This id allows to uniquely identify a plugin. - self.__unique_id = next(self.__id_generator) + self._unique_id = next(self.__id_generator) # register ourself in the table containing all existing plugins - self.__TABLE[self.__unique_id] = self + self.__TABLE[self._unique_id] = self self.__context = context # The Context object self.__project = project # The Project object @@ -602,7 +602,7 @@ class Plugin(): self.call(... command which takes time ...) """ with self.__context.timed_activity(activity_name, - unique_id=self.__unique_id, + unique_id=self._unique_id, detail=detail, silent_nested=silent_nested): yield @@ -713,13 +713,6 @@ class Plugin(): def _get_project(self): return self.__project - # _get_unique_id(): - # - # Fetch the plugin's unique identifier - # - def _get_unique_id(self): - return self.__unique_id - # _get_provenance(): # # Fetch bst file, line and column of the entity @@ -804,7 +797,7 @@ class Plugin(): return (exit_code, output) def __message(self, message_type, brief, **kwargs): - message = Message(self.__unique_id, message_type, brief, **kwargs) + message = Message(self._unique_id, message_type, brief, **kwargs) self.__context.message(message) def __note_command(self, output, *popenargs, **kwargs): diff --git a/buildstream/sandbox/sandbox.py b/buildstream/sandbox/sandbox.py index f11ddea1d..93db2f8ca 100644 --- a/buildstream/sandbox/sandbox.py +++ b/buildstream/sandbox/sandbox.py @@ -122,7 +122,7 @@ class Sandbox(): # Plugin ID for logging plugin = kwargs.get('plugin', None) if plugin: - self.__plugin_id = plugin._get_unique_id() + self.__plugin_id = plugin._unique_id else: self.__plugin_id = None |