refac: main decomposition - #561
Open
nicklafleur wants to merge 3 commits into
Open
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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