Skip to content

gemini refactored runtest.py#4821

Merged
bdbaddog merged 9 commits intoSCons:masterfrom
bdbaddog:refactor_runtest_ai
Jan 28, 2026
Merged

gemini refactored runtest.py#4821
bdbaddog merged 9 commits intoSCons:masterfrom
bdbaddog:refactor_runtest_ai

Conversation

@bdbaddog
Copy link
Copy Markdown
Contributor

@bdbaddog bdbaddog commented Jan 25, 2026

Experimenting with Gemini refactoring runtest.py

I asked it to update the code to current best python practices.

Also added config file to get gemini to use the AGENTS.md (and not just gemini.md).
In theory most LLM's should read this now or at some point in the future.

Added an AGENTS.md file which tells LLMs info about our source tree and practices.

Contributor Checklist:

  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt and RELEASE.txt (and read the README.rst).
  • I have updated the appropriate documentation

@bdbaddog bdbaddog requested a review from mwichmann January 25, 2026 05:26
@mwichmann
Copy link
Copy Markdown
Collaborator

mwichmann commented Jan 25, 2026

Nit:

warning: squelched 13 whitespace errors
warning: 18 lines add whitespace errors.

@mwichmann
Copy link
Copy Markdown
Collaborator

If the model is to improve the flow, it does that, but now we've got a main(), it's 240 lines long, which isn't really ideal. 65 lines are test discovery, I suggest we ask our chatty friend to factor that out into a function.

@mwichmann
Copy link
Copy Markdown
Collaborator

The CI error is that it oversimplified one case. Old code:

# did we end up with any tests?
if not tests:
    sys.stderr.write(parser.format_usage() + """
error: no tests matching the specification were found.
       See "Test selection options" in the help for details on
       how to specify and/or exclude tests.
""")
    sys.exit(1)

New code:

    if not tests:
        sys.stderr.write("error: no tests matching the specification were found.\n")
        sys.exit(1)

Not entirely sure why it would want to do that...

@mwichmann
Copy link
Copy Markdown
Collaborator

mwichmann commented Jan 25, 2026

Not entirely sure why it would want to do that...

And the answer is, after the refactoring, the argparse parser object is not in scope when that error is generated. Those sorts of effects were why I never finished off this size of refactor...

@mwichmann
Copy link
Copy Markdown
Collaborator

From the plan it proposed:

  1. Phase 3: Replace manual threading with concurrent.futures.

It didn't do this, and I'm fine with that. I did experiment once with using the ThreadPoolExecutor, but (to my eyes, anyway) it made the code more complicated rather than less. Our usage of threads is very basic here.

@mwichmann mwichmann added the testsuite Things that only affect the SCons testing. Do not use just because a PR has tests. label Jan 25, 2026
@bdbaddog
Copy link
Copy Markdown
Contributor Author

From the plan it proposed:

3. Phase 3: Replace manual threading with `concurrent.futures`.

It didn't do this, and I'm fine with that. I did experiment once with using the ThreadPoolExecutor, but (to my eyes, anyway) it made the code more complicated rather than less. Our usage of threads is very basic here.

Yes. I only asked it do do phase 1 and 2.

        sys.stderr.write("error: no tests matching the specification were found.\n")

Asking gemini to refactor to allow that to stay the same.

@bdbaddog
Copy link
Copy Markdown
Contributor Author

Nit:

warning: squelched 13 whitespace errors
warning: 18 lines add whitespace errors.

What's this from?

@bdbaddog
Copy link
Copy Markdown
Contributor Author

After refactoring here's the size in LOC for each function in runtest.py

┌────────────────────┬────────────┬──────────┬───────────┐
│ Function           │ Start Line │ End Line │ Total LOC │
├────────────────────┼────────────┼──────────┼───────────┤
│ get_template_command │ 44         │ 78       │ 35        │
│ posint             │ 171        │ 176      │ 6         │
│ build_parser       │ 179        │ 285      │ 107       │
│ process_arguments  │ 287        │ 337      │ 51        │
│ parse_args         │ 339        │ 344      │ 6         │
│ scanlist           │ 347        │ 355      │ 9         │
│ find_unit_tests      │ 358        │ 369      │ 12        │
│ find_e2e_tests       │ 372        │ 391      │ 20        │
│ setup_logging      │ 393        │ 501      │ 109       │
│ log_result         │ 504        │ 519      │ 16        │
│ run_test           │ 522        │ 558      │ 37        │
│ setup_env          │ 573        │ 643      │ 71        │
│ discover_tests     │ 645        │ 701      │ 57        │
│ create_run_context   │ 703        │ 722      │ 20        │
│ execute_tests      │ 724        │ 744      │ 21        │
│ report_results     │ 746        │ 817      │ 72        │
│ main               │ 819        │ 838      │ 20        │
└────────────────────┴────────────┴──────────┴───────────┘

…as well as GEMINI.md and CONTEXT.md). Most LLM's will read AGENTS.md for initial context for the project
@mwichmann
Copy link
Copy Markdown
Collaborator

Nit:

warning: squelched 13 whitespace errors
warning: 18 lines add whitespace errors.

What's this from?

pulling down the patch and applying it (wget https://github.com/SCons/scons/pull/4821.patch) - the file is apparently full of trailing spaces, which in normal cases would be handled by .editorconfig

@mwichmann
Copy link
Copy Markdown
Collaborator

Although only minor changes, I'd call this round an improvement.

…rings

Updated all docstrings in runtest.py to be Sphinx-compatible.
Renamed report_results function to display_results.

Assisted-by: Gemini
Signed-off-by: William Deegan <bill@baddogconsulting.com>
Updated all docstrings in runtest.py from Sphinx-compatible to Google style.

Assisted-by: Gemini
Signed-off-by: William Deegan <bill@baddogconsulting.com>
@bdbaddog bdbaddog changed the title [WIP] gemini refactored runtest.py gemini refactored runtest.py Jan 27, 2026
@bdbaddog bdbaddog merged commit aaa4bf9 into SCons:master Jan 28, 2026
@mwichmann mwichmann added this to the NextRelease milestone Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testsuite Things that only affect the SCons testing. Do not use just because a PR has tests.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants