You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/02/04 07:38:21 UTC
[buildstream] 15/18: Add some basic type hinting
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch tpollard/subrebase
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 03bc9ef7f68dbdbe9e65e3a0322d14c19f9c699a
Author: Tom Pollard <to...@codethink.co.uk>
AuthorDate: Thu Nov 7 14:44:58 2019 +0000
Add some basic type hinting
---
src/buildstream/_exceptions.py | 2 +-
src/buildstream/_frontend/app.py | 2 +-
src/buildstream/_scheduler/scheduler.py | 14 +++++++-------
src/buildstream/_stream.py | 29 +++++++++++++++--------------
4 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/src/buildstream/_exceptions.py b/src/buildstream/_exceptions.py
index 69acc69..01b641e 100644
--- a/src/buildstream/_exceptions.py
+++ b/src/buildstream/_exceptions.py
@@ -49,7 +49,7 @@ def get_last_exception():
#
# Sets the last exception from the main process, used if Stream is running a subprocess
#
-def set_last_exception(exception):
+def set_last_exception(exception: Exception) -> None:
if "BST_TEST_SUITE" in os.environ:
global _last_exception
_last_exception = exception
diff --git a/src/buildstream/_frontend/app.py b/src/buildstream/_frontend/app.py
index 704a489..b69be1a 100644
--- a/src/buildstream/_frontend/app.py
+++ b/src/buildstream/_frontend/app.py
@@ -964,7 +964,7 @@ class App:
return (project_name, format_version, element_path)
- def _handle_run_exception(self, exception, session_name):
+ def _handle_run_exception(self, exception: BstError, session_name: str) -> None:
# Print a nice summary if this is a session
if session_name:
elapsed = self.stream.elapsed_time
diff --git a/src/buildstream/_scheduler/scheduler.py b/src/buildstream/_scheduler/scheduler.py
index 92710bf..25279ad 100644
--- a/src/buildstream/_scheduler/scheduler.py
+++ b/src/buildstream/_scheduler/scheduler.py
@@ -368,7 +368,7 @@ class Scheduler:
# domain (ErrorDomain): Enum for the domain from which the error occurred
# reason (str): String identifier representing the reason for the error
#
- def set_last_task_error(self, domain, reason):
+ def set_last_task_error(self, domain, reason: str) -> None:
task_error = domain, reason
notification = Notification(NotificationType.TASK_ERROR, task_error=task_error)
self._notify_front(notification)
@@ -614,14 +614,14 @@ class Scheduler:
queue._task_group.failed_tasks.remove(element._get_full_name())
queue.enqueue([element])
- def _notify_front(self, notification):
+ def _notify_front(self, notification: Notification) -> None:
# Check if we need to call the notifier callback
if self._notify_front_queue:
self._notify_front_queue.put(notification)
else:
self._notifier(notification)
- def _notification_handler(self, notification):
+ def _notification_handler(self, notification: Notification) -> None:
if notification.notification_type == NotificationType.TERMINATE:
self.terminate_jobs()
elif notification.notification_type == NotificationType.QUIT:
@@ -639,20 +639,20 @@ class Scheduler:
# as we don't want to pickle exceptions between processes
raise ValueError("Unrecognised notification type received")
- def _loop(self):
+ def _loop(self) -> None:
while not self._notify_back_queue.empty():
notification = self._notify_back_queue.get_nowait()
self._notification_handler(notification)
- def _start_listening(self):
+ def _start_listening(self) -> None:
if self._notify_back_queue:
self.loop.add_reader(self._notify_back_queue._reader.fileno(), self._loop)
- def _stop_listening(self):
+ def _stop_listening(self) -> None:
if self._notify_back_queue:
self.loop.remove_reader(self._notify_back_queue._reader.fileno())
- def _update_task_groups(self, name, complete_name, task, full_name=None):
+ def _update_task_groups(self, name: str, complete_name: str, task: str, full_name: str = None) -> None:
if self._notify_front_queue:
changes = (name, complete_name, task, full_name)
self._notify_front(Notification(NotificationType.TASK_GROUPS, task_groups=changes))
diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py
index 854d161..77821f1 100644
--- a/src/buildstream/_stream.py
+++ b/src/buildstream/_stream.py
@@ -134,7 +134,7 @@ class Stream:
self._sourcecache = self._context.sourcecache
@staticmethod
- def _subprocess_main(func, notify, *args, **kwargs):
+ def _subprocess_main(func, notify, *args, **kwargs) -> None:
# Set main process
utils._set_stream_pid()
@@ -1740,7 +1740,7 @@ class Stream:
return element_targets, artifact_refs
- def _notification_handler(self, notification):
+ def _notification_handler(self, notification: Notification) -> None:
if notification.notification_type == NotificationType.TASK_GROUPS:
queue_name, complete_name, task_event, element_name = notification.task_groups
try:
@@ -1790,59 +1790,60 @@ class Stream:
else:
raise StreamError("Unrecognised notification type received")
- def _notify_back(self, notification):
+ def _notify_back(self, notification: Notification) -> None:
if self._notify_back_queue:
self._notify_back_queue.put(notification)
else:
self._scheduler._notification_handler(notification)
- def _notify_front(self, notification):
+ def _notify_front(self, notification: Notification) -> None:
if self._notify_front_queue:
self._notify_front_queue.put(notification)
else:
self._notification_handler(notification)
- def _loop(self):
+ def _loop(self) -> None:
while not self._notify_front_queue.empty():
notification = self._notify_front_queue.get_nowait()
self._notification_handler(notification)
- def _start_listening(self):
+ def _start_listening(self) -> None:
if self._notify_front_queue:
self.loop.add_reader(self._notify_front_queue._reader.fileno(), self._loop)
- def _stop_listening(self):
+ def _stop_listening(self) -> None:
if self._notify_front_queue:
self.loop.remove_reader(self._notify_front_queue._reader.fileno())
- def _watch_casd(self):
+ def _watch_casd(self) -> None:
if self._context.get_cascache().get_casd_process_manager().process:
self._casd_process = self._context.get_cascache().get_casd_process_manager().process
self._watcher = asyncio.get_child_watcher()
self._watcher.attach_loop(self.loop)
self._watcher.add_child_handler(self._casd_process.pid, self._abort_on_casd_failure)
- def _abort_on_casd_failure(self, pid, returncode):
+ def _abort_on_casd_failure(self, pid: int, returncode: int) -> None:
message = Message(MessageType.BUG, "buildbox-casd died while the pipeline was active.")
self._notify_front(Notification(NotificationType.MESSAGE, message=message))
self._casd_process.returncode = returncode
notification = Notification(NotificationType.TERMINATE)
self._notify_back(notification)
- def _stop_watching_casd(self):
+ def _stop_watching_casd(self) -> None:
self._watcher.remove_child_handler(self._casd_process.pid)
self._watcher.close()
self._casd_process = None
- def _handle_exception(self, loop, context):
+ def _handle_exception(self, loop, context: dict) -> None:
exception = context.get("exception")
# Set the last exception for the test suite if needed
- set_last_exception(exception)
+ if exception:
+ set_last_exception(exception)
# Add it to context
self._context._subprocess_exception = exception
self.loop.stop()
- def _connect_signals(self):
+ def _connect_signals(self) -> None:
if self.loop:
self.loop.add_signal_handler(signal.SIGINT, self._interrupt_callback)
self.loop.add_signal_handler(
@@ -1852,7 +1853,7 @@ class Stream:
signal.SIGTSTP, lambda: self._notify_back(Notification(NotificationType.SIGTSTP))
)
- def _disconnect_signals(self):
+ def _disconnect_signals(self) -> None:
if self.loop:
self.loop.remove_signal_handler(signal.SIGINT)
self.loop.remove_signal_handler(signal.SIGTSTP)