Repository navigation
refac: main decomposition - #561
Conversation
Config still exposed Config.get()/ensure_loaded()/reset() classmethods while MutmutState (added by #509) already used a bare config()/state()-style accessor. Replace the classmethod API with module-level config()/reset_config() functions to match, and migrate the remaining module-level globals in mutmut/__init__.py (stats_time, duration_by_test, tests_by_mangled_function_name, _stats, _covered_lines) onto MutmutState, keeping deprecated __getattr__ shims for external readers of the old mutmut.* attributes. Renames local variables that shadowed the new config()/state() function names where needed to avoid UnboundLocalError, and repoints test fixtures/monkeypatches that patched Config.get() at the class/module level to instead mutate the live config()/state() singleton instances in place, so patches stay visible to modules that already imported config by reference.
Move timeout management from threading/ to workers/ package. - Move src/mutmut/threading/timeout.py -> src/mutmut/workers/timeout.py - Update __main__.py import to use new location - Move tests/threading/ -> tests/workers/
Non-functional reorganization: move cohesive groups of code out of the
__main__.py into dedicated modules. No behavior change.
New/extended modules:
- stats.py: status/emoji maps, Stat, collect_stat,
calculate_summary_stats, print_stats, load_stats, save_stats
- runners/harness.py: TestRunner ABC, PytestRunner, HammettRunner,
ListAllTestsResult, collected_test_names, unused, and the
test-runner exceptions (Collect/BadTestExecutionCommands)
- ui/browse.py: ResultBrowser Textual app wrapped in
run_result_browser(); get_diff_for_mutant/apply_mutant are injected
to avoid a circular import back into __main__. Uses upstream #543's
@work/Lock/get_current_worker diff-loading model.
- ui/terminal.py: spinner + status_printer/print_status
- utils/file_utils.py: walk_all_files/walk_source_files/
walk_mutatable_files, copy_src_dir, copy_also_copy_files,
setup_source_paths
Move result_browser_layout.tcss into ui/ so Textual's CSS_PATH
resolves relative to ui/browse.py.
__main__.py re-imports the moved public names, so external
`from mutmut.__main__ import ...` call sites keep working unchanged.
Repoint code_coverage.py's TYPE_CHECKING import to runners.harness.
|
Looks good to me. Some minor things I noticed (feel free to address, not necessary):
And do you plan to put more code into the workers module? Currently, it feels a bit empty. I guess the |
…pply.py Remove the need to pass in function to the browser and move mutation functions out of main.
I have more coming for the workers package (namely forking strategies you can find in #510). I got a little stuck since I changed jobs and lost access to the computer I was doing this work with, but I'm set back up now so will be merging it all in short order. Fixed the issues pointed out in your review, thanks |
3 more or less independent commits that work towards the same ultimate goal.
1.
refactor(config): unifyConfig/MutmutStateto function-based singletonsConfigstill exposedConfig.get()/ensure_loaded()/reset()classmethods whileMutmutState(#509) already used a barestate()accessor. Replaces the classmethod APIwith module-level
config()/reset_config()to match, and migrates the lastmodule-level globals in
mutmut/__init__.py(stats_time,duration_by_test,tests_by_mangled_function_name,_stats,_covered_lines,_excluded_lines) ontoMutmutState. Deprecated__getattr__shims are kept for external readers of the oldmutmut.*attributes.Test fixtures that patched
Config.get()at the class level now mutate the live singletonin place, so patches stay visible to modules that imported
configby reference.2.
refactor(workers): create workers packageRenames
mutmut/threading/tomutmut/workers/(and the matching test package). Purerename;
timeout.pyis unchanged.3.
refactor: extract__main__.pycomponents into dedicated modulesMoves cohesive groups out of the oversized
__main__.py(2064 → 1399 lines):stats.py: status/emoji maps,Stat,collect_stat,calculate_summary_stats,print_stats,load_stats,save_statsrunners/harness.py:TestRunnerABC,PytestRunner,HammettRunner,ListAllTestsResult, test-runner exceptionsui/browse.py:ResultBrowserwrapped inrun_result_browser();get_diff_for_mutant/apply_mutantare injected to avoid a circular import back into__main__ui/terminal.py: spinner +status_printer/print_statusutils/file_utils.py: thewalk_*helpers,copy_src_dir,copy_also_copy_files,setup_source_pathsresult_browser_layout.tcssmoves intoui/so Textual'sCSS_PATHresolves relative toui/browse.py.__main__.pyre-imports the moved public names, so externalfrom mutmut.__main__ import ...call sites keep working unchanged.Notes for reviewers
These commits were written before several fixes landed on
main, so I needed to re-apply some changes,would appreciate a review on that.
call.when != "call"guard (run_stats records the teardown duration per test (missing call.when filter), starving the per-mutant timeout budget #544) now lives inrunners/harness.py_excluded_lines(wip: don't mutate lines excluded from coverage #547) was added toMutmutState, since it postdates the config refactor