Part of #4950. Slice 1 of 5. Estimated 3 weeks.
Goal
Establish foundation for the refactor: typed exception hierarchy, centralized
sys.path bootstrap, and elimination of the worst cross-cutting code smells.
No behavior changes — this slice is groundwork.
Tasks
Exception hierarchy
Bootstrap module
Move from utils.py → core/
Kill star imports
Kill global mutable state
Kill import-time side effects
Standardize error handling
Fix test infrastructure (resolves #4936)
Misc
What we're NOT doing in Slice 1
- No protocol classes wrapping stdlib (
os.path, subprocess, time,
os.environ).
- No factory functions or service locators.
- No new abstraction layers.
Definition of done
Related
Part of #4950. Slice 1 of 5. Estimated 3 weeks.
Goal
Establish foundation for the refactor: typed exception hierarchy, centralized
sys.pathbootstrap, and elimination of the worst cross-cutting code smells.No behavior changes — this slice is groundwork.
Tasks
Exception hierarchy
CIME/core/exceptions.pywith typed hierarchy extending theexisting
CIMEError.CIMEErrorfromutils.py:155tocore/exceptions.py; re-exportfrom
utils.py.ConfigurationError,BuildError,BatchError,CaseError, etc.) — no callers yet, just establishing the hierarchy.Bootstrap module
CIME/core/config/bootstrap.pyconsolidating thesys.path.insertcalls scattered across 11+ files.
standard_script_setup.pyandstandard_module_setup.py.Move from
utils.py→core/CIMEError,expect,deprecate_action,fixup_sys_path,import_from_file,import_and_run_sub_or_cmd,run_sub_or_cmd→core/exceptions.pyandcore/config/bootstrap.pyas appropriate.IndentFormatter,set_logger_indent,configure_logging,setup_standard_logging_options) →CIME/core/logging.py.Kill star imports
from CIME.XML.standard_module_setup import *(~60 files).Currently injects
os,sys,re,expect,run_cmdetc. into everynamespace. Highest-impact code-quality fix in the entire refactor.
from CIME.test_status import *(~10 files, ~30 constants).Kill global mutable state
GLOBAL = {}(utils.py:21). Currently used to passSRCROOTbetween
case.py,create_test.py, andutils.get_src_root()viaimplicit global mutation. Replace with explicit parameter passing.
Kill import-time side effects
Servers/__init__.pyrunsshutil.which()at import time forglobus-url-copy,svn,wget. Make discovery lazy.Standardize error handling
sys.exit()calls (~6 sites in library code) and bareraise RuntimeError(~30 sites). Migrate toCIMEError/expect()where appropriate.
sys.exit()only in CLI entrypoints.Fix test infrastructure (resolves #4936)
conftest.pysotest_unit_*.pyruns without host model configor machine XML. Keep machine setup for system tests only.
Misc
__init__.pytoCIME/Tools/xmlconvertors/andCIME/ParamGen/(currently use try/except import fallbacks).
case.py:84-102and 10 siblingmodules — moves to
core/should reduce these.What we're NOT doing in Slice 1
os.path,subprocess,time,os.environ).Definition of done
standard_module_setupandtest_status.GLOBAL = {}eliminated; SRCROOT passed explicitly.sys.pathmanipulation consolidated inbootstrap.py.sys.exit()in library code.Servers/__init__.pydoesn't run executables at import time.test_unit_*.py) run without host model / machine config.utils.pykeep external imports working.Related
CIME/core/batch/#4997, Refactor Slice 3A: SRCROOT standardization (removeconfig_files.xml) #4998, Refactor Slice 3B: Move build logic intoCIME/core/build/#4999, Refactor Slice 4: DecomposeCasegod object #5000