diff --git a/scripts/guru-shell b/scripts/guru-shell index ec4bd21..ede9ec5 100755 --- a/scripts/guru-shell +++ b/scripts/guru-shell @@ -39,6 +39,9 @@ export GURU_PYTHON_ROOT="$s_drive/$studio2023_path" export PYTHONPATH="$GURU_PYTHON_ROOT/env$pathsep$PYTHONPATH" export PYTHONPATH="$GURU_PYTHON_ROOT$pathsep$PYTHONPATH" +# Remove anything from PYTHONPATH that contains Maya_Shared. +export PYTHONPATH=$(echo $PYTHONPATH | sed "s/[^$pathsep]*Maya_Shared[^$pathsep]*//g" | sed "s/$pathsep$pathsep/$pathsep/g" | sed "s/^$pathsep//g" | sed "s/$pathsep$//g") + # Update the PATH to point to the studio's install of python if [ -d "/c/Programs/software/win/core/python/python_3.7.7" ]; then export PATH="/c/Programs/software/win/core/python/python_3.7.7:$PATH" diff --git a/scripts/pytb b/scripts/pytb index 6ec21b4..fe0bddb 100755 --- a/scripts/pytb +++ b/scripts/pytb @@ -23,6 +23,7 @@ def main() -> int: ap.add_argument( "--no-strip-referer", help="Strip referer from flask tbs", action="store_true" ) + ap.add_argument("--trace-only", help="Only print the trace", action="store_true") ap.add_argument( "-v", "--verbose", help="Enable verbose logging", action="store_true" ) @@ -61,7 +62,7 @@ def main() -> int: frames = [] is_in_frame = False for line in tb_lines[start_idx:]: - if line.startswith("File "): + if line.lstrip().startswith("File "): is_in_frame = True frames.append([line]) elif is_in_frame: @@ -90,28 +91,41 @@ def main() -> int: output_lines.append((statement, context)) # Figure out the longest statement - longest_statement = max(len(line[0]) for line in output_lines) + longest_statement = max(len(line[0]) for line in output_lines[:-1]) # Build the lines, padding the statements so that the files line up output = "" for statement, context in output_lines: output += f"{statement.ljust(longest_statement)}{context}\n" - longest_line = max(len(line) for line in output.splitlines()) - + # remove any trailing newlines output = output.rstrip() + # Figure out the longest line + output_trace = "\n".join(output.splitlines()[:-1]) + output_error = output.splitlines()[-1] + if args.trace_only: + longest_line = max(len(line) for line in output_trace.splitlines()) + else: + longest_line = max(len(line) for line in output.splitlines()) + # Pass over to rich to do the syntax highlighting - console = Console(record=True, width=longest_line+1) - console.print(Syntax(output, "python", background_color="default")) - + console = Console(record=True, width=longest_line + 1) + console.print(Syntax(output_trace, "python", background_color="default")) + if not args.trace_only: + console.print( + Syntax(output_error, "python", background_color="default") + ) + # Export an image file_name = f"Traceback {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}" if args.file: file_name += f" ({args.file.stem})" file_name += ".svg" OUTPUT_ROOT.mkdir(parents=True, exist_ok=True) - console.save_svg(OUTPUT_ROOT / file_name, title="Evan's Python Traceback Visualizer") + console.save_svg( + OUTPUT_ROOT / file_name, title="Evan's Python Traceback Visualizer" + ) return 0