diff options
Diffstat (limited to 'src/buildstream/_frontend/app.py')
-rw-r--r-- | src/buildstream/_frontend/app.py | 148 |
1 files changed, 34 insertions, 114 deletions
diff --git a/src/buildstream/_frontend/app.py b/src/buildstream/_frontend/app.py index 3be035c0c..9a12f3083 100644 --- a/src/buildstream/_frontend/app.py +++ b/src/buildstream/_frontend/app.py @@ -289,8 +289,7 @@ class App: # don't stop them with an offer to create a project for them. if e.reason == LoadErrorReason.MISSING_PROJECT_CONF: click.echo( - "No project found. You can create a new project like so:", - err=True, + "No project found. You can create a new project like so:", err=True, ) click.echo("", err=True) click.echo(" bst init", err=True) @@ -309,13 +308,9 @@ class App: if session_name: elapsed = self.stream.elapsed_time - if ( - isinstance(e, StreamError) and e.terminated - ): # pylint: disable=no-member + if isinstance(e, StreamError) and e.terminated: # pylint: disable=no-member self._message( - MessageType.WARN, - session_name + " Terminated", - elapsed=elapsed, + MessageType.WARN, session_name + " Terminated", elapsed=elapsed, ) else: self._message(MessageType.FAIL, session_name, elapsed=elapsed) @@ -330,8 +325,7 @@ class App: self._error_exit(e) except RecursionError: click.echo( - "RecursionError: Dependency depth is too large. Maximum recursion depth exceeded.", - err=True, + "RecursionError: Dependency depth is too large. Maximum recursion depth exceeded.", err=True, ) sys.exit(-1) @@ -339,9 +333,7 @@ class App: # No exceptions occurred, print session time and summary if session_name: self._message( - MessageType.SUCCESS, - session_name, - elapsed=self.stream.elapsed_time, + MessageType.SUCCESS, session_name, elapsed=self.stream.elapsed_time, ) if self._started: self._print_summary() @@ -389,8 +381,7 @@ class App: # Abort if the project.conf already exists, unless `--force` was specified in `bst init` if not force and os.path.exists(project_path): raise AppError( - "A project.conf already exists at: {}".format(project_path), - reason="project-exists", + "A project.conf already exists at: {}".format(project_path), reason="project-exists", ) if project_name: @@ -407,11 +398,7 @@ class App: ) else: # Collect the parameters using an interactive session - ( - project_name, - format_version, - element_path, - ) = self._init_project_interactive( + (project_name, format_version, element_path,) = self._init_project_interactive( project_name, format_version, element_path ) @@ -419,20 +406,14 @@ class App: try: os.makedirs(directory, exist_ok=True) except IOError as e: - raise AppError( - "Error creating project directory {}: {}".format(directory, e) - ) from e + raise AppError("Error creating project directory {}: {}".format(directory, e)) from e # Create the elements sub-directory if it doesnt exist elements_path = os.path.join(directory, element_path) try: os.makedirs(elements_path, exist_ok=True) except IOError as e: - raise AppError( - "Error creating elements sub-directory {}: {}".format( - elements_path, e - ) - ) from e + raise AppError("Error creating elements sub-directory {}: {}".format(elements_path, e)) from e # Dont use ruamel.yaml here, because it doesnt let # us programatically insert comments or whitespace at @@ -554,11 +535,7 @@ class App: def _maybe_render_status(self): # If we're suspended or terminating, then dont render the status area - if ( - self._status - and self.stream - and not (self.stream.suspended or self.stream.terminated) - ): + if self._status and self.stream and not (self.stream.suspended or self.stream.terminated): self._status.render() # @@ -591,9 +568,7 @@ class App: try: choice = click.prompt( "Choice:", - value_proc=_prefix_choice_value_proc( - ["continue", "quit", "terminate"] - ), + value_proc=_prefix_choice_value_proc(["continue", "quit", "terminate"]), default="continue", err=True, ) @@ -641,9 +616,7 @@ class App: self._status.clear() click.echo( "\n\n\nBUG: Message handling out of sync, " - + "unable to retrieve failure message for element {}\n\n\n\n\n".format( - full_name - ), + + "unable to retrieve failure message for element {}\n\n\n\n\n".format(full_name), err=True, ) else: @@ -682,9 +655,7 @@ class App: if failure.logfile: summary += " (l)og - View the full log file\n" if failure.sandbox: - summary += ( - " (s)hell - Drop into a shell in the failed build sandbox\n" - ) + summary += " (s)hell - Drop into a shell in the failed build sandbox\n" summary += "\nPressing ^C will terminate jobs and exit\n" choices = ["continue", "quit", "terminate", "retry"] @@ -698,16 +669,12 @@ class App: click.echo(summary, err=True) self._notify( - "BuildStream failure", - "{} on element {}".format(failure.action_name, full_name), + "BuildStream failure", "{} on element {}".format(failure.action_name, full_name), ) try: choice = click.prompt( - "Choice:", - default="continue", - err=True, - value_proc=_prefix_choice_value_proc(choices), + "Choice:", default="continue", err=True, value_proc=_prefix_choice_value_proc(choices), ) except click.Abort: # Ensure a newline after automatically printed '^C' @@ -718,26 +685,17 @@ class App: # if choice == "shell": click.echo( - "\nDropping into an interactive shell in the failed build sandbox\n", - err=True, + "\nDropping into an interactive shell in the failed build sandbox\n", err=True, ) try: unique_id, element_key = element prompt = self.shell_prompt(full_name, element_key) self.stream.shell( - None, - Scope.BUILD, - prompt, - isolate=True, - usebuildtree="always", - unique_id=unique_id, + None, Scope.BUILD, prompt, isolate=True, usebuildtree="always", unique_id=unique_id, ) except BstError as e: click.echo( - "Error while attempting to create interactive shell: {}".format( - e - ), - err=True, + "Error while attempting to create interactive shell: {}".format(e), err=True, ) elif choice == "log": with open(failure.logfile, "r") as logfile: @@ -752,9 +710,7 @@ class App: click.echo("\nCompleting ongoing tasks before quitting\n", err=True) self.stream.quit() elif choice == "continue": - click.echo( - "\nContinuing with other non failing elements\n", err=True - ) + click.echo("\nContinuing with other non failing elements\n", err=True) elif choice == "retry": click.echo("\nRetrying failed job\n", err=True) unique_id = element[0] @@ -768,10 +724,7 @@ class App: self._started = True if self._session_name: self.logger.print_heading( - self.project, - self.stream, - log_file=self._main_options["log_file"], - styling=self.colors, + self.project, self.stream, log_file=self._main_options["log_file"], styling=self.colors, ) # @@ -779,9 +732,7 @@ class App: # def _print_summary(self): click.echo("", err=True) - self.logger.print_summary( - self.stream, self._main_options["log_file"], styling=self.colors - ) + self.logger.print_summary(self.stream, self._main_options["log_file"], styling=self.colors) # _error_exit() # @@ -797,9 +748,7 @@ class App: def _error_exit(self, error, prefix=None): click.echo("", err=True) - if ( - self.context is None or self.context.log_debug is None - ): # Context might not be initialized, default to cmd + if self.context is None or self.context.log_debug is None: # Context might not be initialized, default to cmd debug = self._main_options["debug"] else: debug = self.context.log_debug @@ -831,10 +780,7 @@ class App: return # Hold on to the failure messages - if ( - message.message_type in [MessageType.FAIL, MessageType.BUG] - and message.element_name is not None - ): + if message.message_type in [MessageType.FAIL, MessageType.BUG] and message.element_name is not None: self._fail_messages[message.element_name] = message # Send to frontend if appropriate @@ -866,9 +812,8 @@ class App: # Some validation routines for project initialization # def _assert_format_version(self, format_version): - message = ( - "The version must be supported by this " - + "version of buildstream (0 - {})\n".format(BST_FORMAT_VERSION) + message = "The version must be supported by this " + "version of buildstream (0 - {})\n".format( + BST_FORMAT_VERSION ) # Validate that it is an integer @@ -911,9 +856,7 @@ class App: # format_version (int): The user selected format version # element_path (str): The user selected element path # - def _init_project_interactive( - self, project_name, format_version=BST_FORMAT_VERSION, element_path="elements" - ): + def _init_project_interactive(self, project_name, format_version=BST_FORMAT_VERSION, element_path="elements"): def project_name_proc(user_input): try: node._assert_symbol_name(user_input, "project name") @@ -940,12 +883,8 @@ class App: # Collect project name click.echo("", err=True) - click.echo( - self._content_profile.fmt("Choose a unique name for your project"), err=True - ) - click.echo( - self._format_profile.fmt("-------------------------------------"), err=True - ) + click.echo(self._content_profile.fmt("Choose a unique name for your project"), err=True) + click.echo(self._format_profile.fmt("-------------------------------------"), err=True) click.echo("", err=True) click.echo( self._detail_profile.fmt( @@ -969,25 +908,15 @@ class App: err=True, ) click.echo("", err=True) - project_name = click.prompt( - self._content_profile.fmt("Project name"), - value_proc=project_name_proc, - err=True, - ) + project_name = click.prompt(self._content_profile.fmt("Project name"), value_proc=project_name_proc, err=True,) click.echo("", err=True) # Collect format version click.echo( - self._content_profile.fmt( - "Select the minimum required format version for your project" - ), - err=True, + self._content_profile.fmt("Select the minimum required format version for your project"), err=True, ) click.echo( - self._format_profile.fmt( - "-----------------------------------------------------------" - ), - err=True, + self._format_profile.fmt("-----------------------------------------------------------"), err=True, ) click.echo("", err=True) click.echo( @@ -1047,10 +976,7 @@ class App: ) click.echo("", err=True) element_path = click.prompt( - self._content_profile.fmt("Element path"), - value_proc=element_path_proc, - default=element_path, - err=True, + self._content_profile.fmt("Element path"), value_proc=element_path_proc, default=element_path, err=True, ) return (project_name, format_version, element_path) @@ -1070,9 +996,7 @@ class App: # def _prefix_choice_value_proc(choices): def value_proc(user_input): - remaining_candidate = [ - choice for choice in choices if choice.startswith(user_input) - ] + remaining_candidate = [choice for choice in choices if choice.startswith(user_input)] if not remaining_candidate: raise UsageError("Expected one of {}, got {}".format(choices, user_input)) @@ -1080,10 +1004,6 @@ def _prefix_choice_value_proc(choices): if len(remaining_candidate) == 1: return remaining_candidate[0] else: - raise UsageError( - "Ambiguous input. '{}' can refer to one of {}".format( - user_input, remaining_candidate - ) - ) + raise UsageError("Ambiguous input. '{}' can refer to one of {}".format(user_input, remaining_candidate)) return value_proc |