Skip to content

Add interactive CLI and refactor tbots.py#3657

Open
StarrryNight wants to merge 19 commits intoUBC-Thunderbots:masterfrom
StarrryNight:upgrade_tbotspy
Open

Add interactive CLI and refactor tbots.py#3657
StarrryNight wants to merge 19 commits intoUBC-Thunderbots:masterfrom
StarrryNight:upgrade_tbotspy

Conversation

@StarrryNight
Copy link
Copy Markdown
Contributor

@StarrryNight StarrryNight commented Mar 21, 2026

Description

Note: commit history is cooked because I had to recommit everything together. Full commit history here: #3656
This ticket resolves #3623.

  1. It adds an interactive cli by calling ./tbots.py without any arguments/flags. This uses a new module questionary.
Screencast.from.2026-03-21.13-16-09.mp4
  1. It refactors ./tbots.py by streamlining main function, removing dead flags, and adding a dataclass to facilitate calling of helper functions.

Testing Done

Interactive cli works, tbots.py works.

Resolved Issues

#3623

Length Justification and Key Files to Review

Review Checklist

It is the reviewers responsibility to also make sure every item here has been covered

  • Function & Class comments: All function definitions (usually in the .h file) should have a javadoc style comment at the start of them. For examples, see the functions defined in thunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class.
  • Remove all commented out code
  • Remove extra print statements: for example, those just used for testing
  • Resolve all TODO's: All TODO (or similar) statements should either be completed or associated with a github issue

nycrat
nycrat previously approved these changes Mar 22, 2026
Comment thread src/tbots.py Outdated
Comment on lines +270 to +271
test = "all" if not test else test
args.extend(["test", "--suite" if test == "all" else test])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just straight up use if not test instead of setting to "all" then checking again

@Andrewyx
Copy link
Copy Markdown
Contributor

@StarrryNight Is this ready for review?

Copy link
Copy Markdown
Contributor

@sauravbanna sauravbanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes look great ! sorry for long ass comment but i think would be cleaner

Comment thread src/tbots.py Outdated
],
).ask()
if "enable_autoref" in options:
args.append("--enable_autoref")
Copy link
Copy Markdown
Contributor

@sauravbanna sauravbanna Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be a bit hard to explain, but i think combining typer and questionary here is a bit overkill. this is the flow right now:

  1. define Options in typer, with the flags as strings (eg: "--enable_autoref")
  2. check for the questionary choices if "flag" in options
  3. based on choices create a list of raw strings again (not using the typer options yet)
  4. convert strings to Typer options
  5. Call main() -> convert typer options to BuildOptions
  6. do our own validation and create the command

i don't really see what the point of converting from questionary choices -> strings -> typer options -> BuildOptions is.

we can instead directly go from questionary choices -> BuildOptions.

we can make BuildOptions use the Builder pattern. start with empty options, and append new options as the user chooses them in the cli. then pass the whole options to main

build_options = BuildOptions()
...

options = questionary.checkbox(...)
build_options = build_options.set_autoref("enable_autoref" in options)
...

we can then extract this from main()

validate(opts)
command = create_command(ctx, opts)
...

into its own helper. so the flow would be:

  1. call main() (entry point)
  2. if no args
    • call interactive cli -> create BuildOptions
    • call helper with BuildOptions to validate + create + run command
  3. if args:
    • create BuildOptions from args (like we do right now)
    • call helper with build options

Comment thread src/tbots.py Outdated
Comment on lines +265 to +266
if "record_stats" in options:
args.append("--record_stats")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a reminder, in #3652, --record_stats now takes in an argument of number of minutes. Also, in #3673, there is a new --enable_autogc flag which should be added.

@nycrat
Copy link
Copy Markdown
Member

nycrat commented Apr 11, 2026

@StarrryNight specifying --record_stats does not work:

================================= Running: ======================================

bazel run --copt=-O3 --spawn_strategy=local --test_env=DISPLAY=:0 //software/thunderscope:thunderscope_main -- --record_stats - - 1 --enable_thunderscope

=================================================================================

INFO: Invocation ID: 026a9ee1-4540-4077-866b-4e911a5c4143
INFO: Analyzed target //software/thunderscope:thunderscope_main (300 packages loaded, 29417 targets configured).
INFO: Found 1 target...
Target //software/thunderscope:thunderscope_main up-to-date:
  bazel-bin/software/thunderscope/thunderscope_main
INFO: Elapsed time: 5.183s, Critical Path: 0.05s
INFO: 1 process: 2646 action cache hit, 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/software/thunderscope/thunderscope_main <args omitted>
usage: thunderscope_main.py [-h] [--layout LAYOUT] [--simulator_runtime_dir SIMULATOR_RUNTIME_DIR] [--blue_full_system_runtime_dir BLUE_FULL_SYSTEM_RUNTIME_DIR]
                            [--yellow_full_system_runtime_dir YELLOW_FULL_SYSTEM_RUNTIME_DIR] [--debug_blue_full_system] [--debug_yellow_full_system] [--debug_simulator]
                            [--visualize_cpp_test] [--log_level {DEBUG,INFO,WARNING,FATAL}] [--blue_log BLUE_LOG] [--yellow_log YELLOW_LOG] [--verbose]
                            [--run_blue | --run_yellow] [--run_diagnostics] [--interface INTERFACE] [--channel CHANNEL]
                            [--visualization_buffer_size VISUALIZATION_BUFFER_SIZE] [--enable_realism] [--estop_baudrate ESTOP_BAUDRATE] [--ci_mode] [--enable_autogc]
                            [--enable_autoref] [--show_autoref_gui] [--sudo] [--keyboard_estop | --disable_communication] [--empty] [--launch_gc]
                            [--record_stats RECORD_STATS]
thunderscope_main.py: error: argument --record_stats: invalid int value: '-'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve tbots.py

4 participants