-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-108834: Cleanup libregrtest #108858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-108834: Cleanup libregrtest #108858
Conversation
8d30aa5
to
60092e9
Compare
60092e9
to
f878f60
Compare
@AlexWaygood @serhiy-storchaka: I would like to merge this change as soon as possible since it's a large refactor, and it's likely that it will get conflicts if it waits for too long. This work should prepare libregrtest to get type annotations. I would prefer to move most code at least: rename variables, functions, etc. Instead of having a serie of multiple commits. As usual, I plan to backport this change to stable branches (3.11 and 3.12). Otherwise, backport is just impossible. @AlexWaygood and me would like to add annotations and then run mypy on a CI, as already done for Argument Clinic. The regrtest project has a long history. It was added in 1996 by commit 152494a. When it was created, it was 170 lines long and has 4 command line options:
Some of these features were implemented in A few years ago, I decided to split the giant mono The problem is that for type annotation, it's very unclear what a Namespace contains. It may or may not have arguments (see my commit message of this PR: This large refactoring cleans up everything at once (!) to pass simple types like I tried to create only short files, the longest is still sadly
To understand where the
I supposed that it was designed to be able to use regrtest as an API: pass parameters to the main() function, without having to use the command line interface. In the main branch, this feature is still supported, the magic def main(tests=None, **kwargs):
Regrtest().main(tests=tests, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very brief review, thanks!
FilterTuple = tuple[str] | ||
|
||
|
||
# Avoid enum.Enum to reduce the number of imports when tests are run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now when you import dataclasses
you import half of the stdlib: it imports inspect
and it imports enum
.
Maybe this can be made into an StrEnum
as it should be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no. That's bad :-( I should maybe rewrite the code to avoid this heavy dataclasses
module. I didn't know that it has so many dependencies. In the past, I worked hard to strictly limit the number of modules imported by test.libregrtest
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two tiny nits I noticed, but I've only skim-read through so far (will try to look more in-depth tomorrow)
Remove "global variables" from libregrtest: no longer pass 'ns' magic namespace which was used to get and set 'random' attributes. Instead, each class has its own attributes, and some classes are even read-only (frozen dataclass), like RunTests. Reorganize files: * Rename runtest.py to single.py. * Rename runtest_mp.py to mp_runner.py. * Create findtests.py, result.py, results.py and worker.py. Reorganize classes: * Copy command line options ('ns' namespace) to Regrtest and RunTests attributes: add many attributes. * Add Results class with methods: get_state(), display_result(), get_exitcode(), JUnit methods, etc. * Add Logger class: log(), display_progress(), system load tracker. * Remove WorkerJob class: the worker now gets a RunTests instance. Move function and methods: * Convert Regrtest.list_cases() to a function. * Convert display_header(), display_sanitizers(), set_temp_dir() and create_temp_dir() methods of Regrtest to functions in utils.py. Rename set_temp_dir() to select_temp_dir(). Rename create_temp_dir() to make_temp_dir(). * Move abs_module_name() and normalize_test_name() to utils.py. * Move capture_output() to utils.py. * Rename dash_R() to runtest_refleak() * Merge display_sanitizers() code into display_header(). cmdline.py changes: * Rename internal --worker-args command line option to --worker-json. * Rename ns.trace to ns.coverage. * No longer gets the number of CPUs: it's now done by Regrtest class. * Add missing attributes to Namespace: coverage, threshold, wait. Misc: * Add test_parse_memlimit() and test_set_memlimit() to test_support. * Add some type annotations.
b2ec0f5
to
de5a058
Compare
PR rebased on main to retrieve test_support changes (fix a merge conflict). |
This change is so larger, that it is not realistic to expect a review. If you split it on several smaller PRs, you can get reviews. Do it if you have any doubts or want to get some advices. But if these changes look straightforward to you, and you are sure in them, you can merge this PR. I approve it blindly. I believe that you know what you do, and some mistakes, if they happen, can be fixed later. Just ensure that these changes will be backported to 3.12 and 3.11. |
I close this PR. Instead I will split it in a long serie of small changes: #109162 |
Remove "global variables" from libregrtest: no longer pass 'ns' magic namespace which was used to get and set 'random' attributes. Instead, each class has its own attributes, and some classes are even read-only (frozen dataclass), like RunTests.
Reorganize files:
Reorganize classes:
Move function and methods:
cmdline.py changes:
Misc: