diff options
-rw-r--r-- | src/buildstream/_cas/cascache.py | 5 | ||||
-rw-r--r-- | src/buildstream/_cas/casremote.py | 4 | ||||
-rw-r--r-- | src/buildstream/_cas/casserver.py | 8 | ||||
-rw-r--r-- | src/buildstream/_frontend/app.py | 3 | ||||
-rw-r--r-- | src/buildstream/_frontend/cli.py | 5 | ||||
-rw-r--r-- | src/buildstream/_includes.py | 7 | ||||
-rw-r--r-- | src/buildstream/_loader/loader.py | 23 | ||||
-rw-r--r-- | src/buildstream/_project.py | 5 | ||||
-rw-r--r-- | src/buildstream/_stream.py | 12 | ||||
-rw-r--r-- | src/buildstream/sandbox/_sandboxbuildbox.py | 6 | ||||
-rw-r--r-- | src/buildstream/sandbox/_sandboxbwrap.py | 5 | ||||
-rw-r--r-- | src/buildstream/sandbox/_sandboxchroot.py | 11 | ||||
-rw-r--r-- | src/buildstream/sandbox/_sandboxremote.py | 23 | ||||
-rw-r--r-- | src/buildstream/utils.py | 6 |
14 files changed, 63 insertions, 60 deletions
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py index b4bba2b6d..fa6705b70 100644 --- a/src/buildstream/_cas/cascache.py +++ b/src/buildstream/_cas/cascache.py @@ -341,8 +341,7 @@ class CASCache(): except grpc.RpcError as e: if e.code() != grpc.StatusCode.NOT_FOUND: raise CASCacheError("Failed to pull ref {}: {}".format(ref, e)) from e - else: - return False + return False except BlobNotFound: return False @@ -481,7 +480,7 @@ class CASCache(): blob_response = response.responses[0] if blob_response.status.code == code_pb2.RESOURCE_EXHAUSTED: raise CASCacheError("Cache too full", reason="cache-too-full") - elif blob_response.status.code != code_pb2.OK: + if blob_response.status.code != code_pb2.OK: raise CASCacheError("Failed to capture blob {}: {}".format(path, blob_response.status.code)) digest.CopyFrom(blob_response.digest) diff --git a/src/buildstream/_cas/casremote.py b/src/buildstream/_cas/casremote.py index 05b57d3d4..ba0477550 100644 --- a/src/buildstream/_cas/casremote.py +++ b/src/buildstream/_cas/casremote.py @@ -291,8 +291,8 @@ class _CASBatchRead(): if missing_blobs is None: raise BlobNotFound(response.digest.hash, "Failed to download blob {}: {}".format( response.digest.hash, response.status.code)) - else: - missing_blobs.append(response.digest) + + missing_blobs.append(response.digest) if response.status.code != code_pb2.OK: raise CASRemoteError("Failed to download blob {}: {}".format( diff --git a/src/buildstream/_cas/casserver.py b/src/buildstream/_cas/casserver.py index 5a4c2b7ac..ca7a21955 100644 --- a/src/buildstream/_cas/casserver.py +++ b/src/buildstream/_cas/casserver.py @@ -291,10 +291,10 @@ class _ContentAddressableStorageServicer(remote_execution_pb2_grpc.ContentAddres except OSError as e: if e.errno != errno.ENOENT: raise - else: - d = response.missing_blob_digests.add() - d.hash = digest.hash - d.size_bytes = digest.size_bytes + + d = response.missing_blob_digests.add() + d.hash = digest.hash + d.size_bytes = digest.size_bytes return response diff --git a/src/buildstream/_frontend/app.py b/src/buildstream/_frontend/app.py index 236e8f80b..f9729a7ce 100644 --- a/src/buildstream/_frontend/app.py +++ b/src/buildstream/_frontend/app.py @@ -915,7 +915,8 @@ def _prefix_choice_value_proc(choices): if not remaining_candidate: raise UsageError("Expected one of {}, got {}".format(choices, user_input)) - elif len(remaining_candidate) == 1: + + if len(remaining_candidate) == 1: return remaining_candidate[0] else: raise UsageError("Ambiguous input. '{}' can refer to one of {}".format(user_input, remaining_candidate)) diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py index 3fad1664d..d45e3a578 100644 --- a/src/buildstream/_frontend/cli.py +++ b/src/buildstream/_frontend/cli.py @@ -629,9 +629,8 @@ def shell(app, element, sysroot, mount, isolate, build_, cli_buildtree, pull_, c if cli_buildtree == "always": # Exit early if it won't be possible to even fetch a buildtree with always option raise AppError("Artifact was created without buildtree, unable to launch shell with it") - else: - click.echo("WARNING: Artifact created without buildtree, shell will be loaded without it", - err=True) + click.echo("WARNING: Artifact created without buildtree, shell will be loaded without it", + err=True) else: # If the value has defaulted to ask and in non interactive mode, don't consider the buildtree, this # being the default behaviour of the command diff --git a/src/buildstream/_includes.py b/src/buildstream/_includes.py index 0ba40e63d..c04601b91 100644 --- a/src/buildstream/_includes.py +++ b/src/buildstream/_includes.py @@ -58,12 +58,13 @@ class Includes: message = "{}: Include block references a file that could not be found: '{}'.".format( include_provenance, include) raise LoadError(message, LoadErrorReason.MISSING_FILE) from e - elif e.reason == LoadErrorReason.LOADING_DIRECTORY: + if e.reason == LoadErrorReason.LOADING_DIRECTORY: message = "{}: Include block references a directory instead of a file: '{}'.".format( include_provenance, include) raise LoadError(message, LoadErrorReason.LOADING_DIRECTORY) from e - else: - raise + + # Otherwise, we don't know the reason, so just raise + raise if file_path in included: include_provenance = includes_node.get_provenance() diff --git a/src/buildstream/_loader/loader.py b/src/buildstream/_loader/loader.py index b2dc7c1c3..5599c8b71 100644 --- a/src/buildstream/_loader/loader.py +++ b/src/buildstream/_loader/loader.py @@ -250,7 +250,7 @@ class Loader(): raise LoadError(message, LoadErrorReason.MISSING_FILE, detail=detail) from e - elif e.reason == LoadErrorReason.LOADING_DIRECTORY: + if e.reason == LoadErrorReason.LOADING_DIRECTORY: # If a <directory>.bst file exists in the element path, # let's suggest this as a plausible alternative. message = str(e) @@ -261,8 +261,10 @@ class Loader(): element_name = filename + '.bst' detail = "Did you mean '{}'?\n".format(element_name) raise LoadError(message, LoadErrorReason.LOADING_DIRECTORY, detail=detail) from e - else: - raise + + # Otherwise, we don't know the reason, so just raise + raise + kind = node.get_str(Symbol.KIND) if kind == "junction": self._first_pass_options.process_node(node) @@ -561,11 +563,11 @@ class Loader(): if level == 0: # junction element not found in this or ancestor projects raise - else: - # mark junction as not available to allow detection of - # conflicting junctions in subprojects - self._loaders[filename] = None - return None + + # mark junction as not available to allow detection of + # conflicting junctions in subprojects + self._loaders[filename] = None + return None # meta junction element # XXX: This is a likely point for progress reporting to end up @@ -636,8 +638,9 @@ class Loader(): if element.path: message += " Was expecting it at path '{}' in the junction's source.".format(element.path) raise LoadError(message=message, reason=LoadErrorReason.INVALID_JUNCTION) from e - else: - raise + + # Otherwise, we don't know the reason, so just raise + raise loader = project.loader self._loaders[filename] = loader diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py index 6cbf3d889..ceba4c44b 100644 --- a/src/buildstream/_project.py +++ b/src/buildstream/_project.py @@ -581,8 +581,9 @@ class Project(): # Raise a more specific error here if e.reason == LoadErrorReason.MISSING_FILE: raise LoadError(str(e), LoadErrorReason.MISSING_PROJECT_CONF) from e - else: - raise + + # Otherwise re-raise the original exception + raise pre_config_node = self._default_config_node.clone() self._project_conf._composite(pre_config_node) diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py index b3e0a6183..2e43bb1a2 100644 --- a/src/buildstream/_stream.py +++ b/src/buildstream/_stream.py @@ -217,8 +217,8 @@ class Stream(): message = "Buildtree is not cached locally or in available remotes" if usebuildtree == "always": raise StreamError(message) - else: - self._message(MessageType.INFO, message + ", shell will be loaded without it") + + self._message(MessageType.INFO, message + ", shell will be loaded without it") else: buildtree = True @@ -481,9 +481,9 @@ class Stream(): msg = "{} is not cached".format(element.name) if self._context.sched_error_action != _SchedulerErrorAction.CONTINUE: raise StreamError("Push failed: " + msg) - else: - self._message(MessageType.WARN, msg) - uncached_elements.append(element) + + self._message(MessageType.WARN, msg) + uncached_elements.append(element) if cached_elements: self._scheduler.clear_queues() @@ -1356,7 +1356,7 @@ class Stream(): if status == SchedStatus.ERROR: raise StreamError() - elif status == SchedStatus.TERMINATED: + if status == SchedStatus.TERMINATED: raise StreamError(terminated=True) # _fetch() diff --git a/src/buildstream/sandbox/_sandboxbuildbox.py b/src/buildstream/sandbox/_sandboxbuildbox.py index 99c7322a3..4258ee26d 100644 --- a/src/buildstream/sandbox/_sandboxbuildbox.py +++ b/src/buildstream/sandbox/_sandboxbuildbox.py @@ -38,8 +38,8 @@ class SandboxBuildBox(Sandbox): def __init__(self, context, project, directory, **kwargs): if kwargs.get('allow_real_directory'): raise SandboxError("BuildBox does not support real directories") - else: - kwargs['allow_real_directory'] = False + + kwargs['allow_real_directory'] = False super().__init__(context, project, directory, **kwargs) @classmethod @@ -61,7 +61,7 @@ class SandboxBuildBox(Sandbox): # Check host os and architecture match if config.build_os != platform.get_host_os(): raise SandboxError("Configured and host OS don't match.") - elif config.build_arch != platform.get_host_arch(): + if config.build_arch != platform.get_host_arch(): raise SandboxError("Configured and host architecture don't match.") return True diff --git a/src/buildstream/sandbox/_sandboxbwrap.py b/src/buildstream/sandbox/_sandboxbwrap.py index d8541354c..bd60eafc1 100644 --- a/src/buildstream/sandbox/_sandboxbwrap.py +++ b/src/buildstream/sandbox/_sandboxbwrap.py @@ -129,9 +129,8 @@ class SandboxBwrap(Sandbox): host_arch = local_platform.get_host_arch() if config.build_os != host_os: raise SandboxError("Configured and host OS don't match.") - elif config.build_arch != host_arch: - if not local_platform.can_crossbuild(config): - raise SandboxError("Configured architecture and host architecture don't match.") + if config.build_arch != host_arch and not local_platform.can_crossbuild(config): + raise SandboxError("Configured architecture and host architecture don't match.") return True diff --git a/src/buildstream/sandbox/_sandboxchroot.py b/src/buildstream/sandbox/_sandboxchroot.py index eb8f53308..8d4c54058 100644 --- a/src/buildstream/sandbox/_sandboxchroot.py +++ b/src/buildstream/sandbox/_sandboxchroot.py @@ -70,7 +70,7 @@ class SandboxChroot(Sandbox): # Check host os and architecture match if config.build_os != host_os: raise PlatformError("Configured and host OS don't match.") - elif config.build_arch != host_arch: + if config.build_arch != host_arch: raise PlatformError("Configured and host architecture don't match.") return True @@ -218,8 +218,9 @@ class SandboxChroot(Sandbox): raise SandboxError('Could not chroot into {} or chdir into {}. ' 'Ensure you are root and that the relevant directory exists.' .format(rootfs, cwd)) from e - else: - raise SandboxError('Could not run command {}: {}'.format(command, e)) from e + + # Otherwise, raise a more general error + raise SandboxError('Could not run command {}: {}'.format(command, e)) from e return code @@ -252,8 +253,8 @@ class SandboxChroot(Sandbox): if err.errno == 1: raise SandboxError("Permission denied while creating device node: {}.".format(err) + "BuildStream reqiures root permissions for these setttings.") - else: - raise + + raise yield diff --git a/src/buildstream/sandbox/_sandboxremote.py b/src/buildstream/sandbox/_sandboxremote.py index e9e145d1f..cf034dbf9 100644 --- a/src/buildstream/sandbox/_sandboxremote.py +++ b/src/buildstream/sandbox/_sandboxremote.py @@ -210,14 +210,14 @@ class SandboxRemote(Sandbox): raise SandboxError("Failed contacting remote execution server at {}." .format(self.exec_url)) - elif status_code in (grpc.StatusCode.INVALID_ARGUMENT, - grpc.StatusCode.FAILED_PRECONDITION, - grpc.StatusCode.RESOURCE_EXHAUSTED, - grpc.StatusCode.INTERNAL, - grpc.StatusCode.DEADLINE_EXCEEDED): + if status_code in (grpc.StatusCode.INVALID_ARGUMENT, + grpc.StatusCode.FAILED_PRECONDITION, + grpc.StatusCode.RESOURCE_EXHAUSTED, + grpc.StatusCode.INTERNAL, + grpc.StatusCode.DEADLINE_EXCEEDED): raise SandboxError("{} ({}).".format(e.details(), status_code.name)) - elif running_operation and status_code == grpc.StatusCode.UNIMPLEMENTED: + if running_operation and status_code == grpc.StatusCode.UNIMPLEMENTED: raise SandboxError("Failed trying to recover from connection loss: " "server does not support operation status polling recovery.") @@ -267,10 +267,10 @@ class SandboxRemote(Sandbox): # if output_files: raise SandboxError("Output files were returned when we didn't request any.") - elif not output_directories: + if not output_directories: error_text = "No output directory was returned from the build server." raise SandboxError(error_text) - elif len(output_directories) > 1: + if len(output_directories) > 1: error_text = "More than one output directory was returned from the build server: {}." raise SandboxError(error_text.format(output_directories)) @@ -458,8 +458,7 @@ class SandboxRemote(Sandbox): if e.code() != grpc.StatusCode.NOT_FOUND: raise SandboxError("Failed to query action cache: {} ({})" .format(e.code(), e.details())) - else: - return None + return None else: self.info("Action result found in action cache") return result @@ -499,8 +498,8 @@ class SandboxRemote(Sandbox): # system failed at processing the execution request. if execution_response.status.message: raise SandboxError(execution_response.status.message) - else: - raise SandboxError("Remote server failed at executing the build request.") + # Otherwise, report the failure in a more general manner + raise SandboxError("Remote server failed at executing the build request.") return execution_response.result diff --git a/src/buildstream/utils.py b/src/buildstream/utils.py index 32d23d27c..de7c14b70 100644 --- a/src/buildstream/utils.py +++ b/src/buildstream/utils.py @@ -1406,9 +1406,9 @@ def _get_compression(tar): if suffix == '.tar': raise UtilError("Expected compression with unknown file extension ('{}'), " "supported extensions are ('.tar'), ('.gz'), ('.xz'), ('.bz2')".format(ext)) - else: - # Assume just an unconventional name was provided, default to uncompressed - return '' + + # Assume just an unconventional name was provided, default to uncompressed + return '' # _is_single_threaded() |