Skip to content

Commit 69ddf88

Browse files
authored
Merge pull request #2539 from ESMCI/jgfouca/upgrade_preview_run
Upgrade preview_run. Redo the formatting of output to make it prettier Add some output for key derived attributes Add logger.info suggestion to user to run preview_run Test suite: by-hand, code-checker Test baseline: Test namelist changes: Test status: bit for bit Fixes [CIME Github issue #] User interface changes?: preview_run output improvements Update gh-pages html (Y/N)?: N Code review: @jedwards4b
2 parents 674e3ac + bd4ea78 commit 69ddf88

File tree

5 files changed

+45
-18
lines changed

5 files changed

+45
-18
lines changed

scripts/Tools/preview_run

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Example:
1919
from standard_script_setup import *
2020

2121
from CIME.case import Case
22+
from CIME.utils import set_logger_indent
2223

2324
logger = logging.getLogger(__name__)
2425

@@ -56,18 +57,30 @@ def _main_func(description):
5657
logging.disable(logging.INFO)
5758

5859
with Case(caseroot, read_only=False) as case:
59-
print("BATCH SUBMIT: (nodes {})".format(case.num_nodes))
60+
print("CASE INFO:")
61+
print(" nodes: {}".format(case.num_nodes))
62+
print(" total tasks: {}".format(case.total_tasks))
63+
print(" tasks per node: {}".format(case.tasks_per_node))
64+
print(" thread count: {}".format(case.thread_count))
65+
print("")
66+
67+
print("BATCH INFO:")
6068
if job is None:
6169
job = case.get_primary_job()
6270

71+
set_logger_indent(" ")
6372
job_id_to_cmd = case.submit_jobs(dry_run=True, job=job)
6473
for job_id, cmd in job_id_to_cmd:
74+
print(" FOR JOB: {}".format(job_id))
75+
print(" ENV:")
6576
case.load_env(job=job_id, reset=True, verbose=True)
66-
print(" {} -> {}".format(job_id, case.get_resolved_value(cmd)))
77+
print(" SUBMIT CMD:")
78+
print(" {}".format(case.get_resolved_value(cmd)))
6779
print("")
6880

6981
if job == case.get_primary_job():
70-
print("MPIRUN: {}".format(case.get_mpirun_cmd()))
82+
print("MPIRUN:")
83+
print (" {}".format(case.get_mpirun_cmd()))
7184

7285
if __name__ == "__main__":
7386
_main_func(__doc__)

scripts/lib/CIME/XML/env_mach_specific.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,13 @@ def make_env_mach_specific_file(self, shell, case):
179179

180180
def _load_envs(self, envs_to_set, verbose=False):
181181
for env_name, env_value in envs_to_set:
182+
logger_func = logger.warning if verbose else logger.debug
182183
if env_value is None and env_name in os.environ:
183184
del os.environ[env_name]
185+
logger_func("Unsetting Environment {}".format(env_name))
184186
elif env_value is not None:
185187
os.environ[env_name] = env_value
186-
if verbose:
187-
if env_value is not None:
188-
logger.warning("Setting Environment {}={}".format(env_name, env_value))
189-
else:
190-
logger.warning("Unsetting Environment {}".format(env_name))
188+
logger_func("Setting Environment {}={}".format(env_name, env_value))
191189

192190
def _compute_module_actions(self, module_nodes, case, job=None):
193191
return self._compute_actions(module_nodes, "command", case, job=job)
@@ -298,11 +296,9 @@ def _get_module_commands(self, modules_to_load, shell):
298296
return cmds
299297

300298
def _load_module_modules(self, modules_to_load, verbose=False):
299+
logger_func = logger.warning if verbose else logger.debug
301300
for cmd in self._get_module_commands(modules_to_load, "python"):
302-
if verbose:
303-
logger.warning("module command is {}".format(cmd))
304-
else:
305-
logger.debug("module command is {}".format(cmd))
301+
logger_func("module command is {}".format(cmd))
306302
stat, py_module_code, errout = run_cmd(cmd)
307303
expect(stat==0 and (len(errout) == 0 or self.allow_error()),
308304
"module command {} failed with message:\n{}".format(cmd, errout))
@@ -311,6 +307,7 @@ def _load_module_modules(self, modules_to_load, verbose=False):
311307
def _load_modules_generic(self, modules_to_load, verbose=False):
312308
sh_init_cmd = self.get_module_system_init_path("sh")
313309
sh_mod_cmd = self.get_module_system_cmd_path("sh")
310+
logger_func = logger.warning if verbose else logger.debug
314311

315312
# Purpose is for environment management system that does not have
316313
# a python interface and therefore can only determine what they
@@ -330,10 +327,7 @@ def _load_modules_generic(self, modules_to_load, verbose=False):
330327
# Use null terminated lines to give us something more definitive to split on.
331328
# Env vars can contain newlines, so splitting on newlines can be ambiguous
332329
cmd += " && env -0"
333-
if verbose:
334-
logger.warning("cmd: {}".format(cmd))
335-
else:
336-
logger.debug("cmd: {}".format(cmd))
330+
logger_func("cmd: {}".format(cmd))
337331
output = run_cmd_no_fail(cmd)
338332

339333
###################################################

scripts/lib/CIME/case/case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from CIME.utils import convert_to_type, get_model
1414
from CIME.utils import get_project, get_charge_account, check_name
1515
from CIME.utils import get_current_commit, safe_copy
16-
from CIME.locked_files import LOCKED_DIR, lock_file
16+
from CIME.locked_files import LOCKED_DIR, lock_file
1717
from CIME.XML.machines import Machines
1818
from CIME.XML.pes import Pes
1919
from CIME.XML.files import Files

scripts/lib/CIME/case/case_setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ def _case_setup_impl(case, caseroot, clean=False, test_mode=False, reset=False):
205205
env_module.make_env_mach_specific_file("csh", case)
206206
env_module.save_all_env_info("software_environment.txt")
207207

208+
logger.info("You can now run './preview_run' to get more info on how your case will be run")
209+
208210
###############################################################################
209211
def case_setup(self, clean=False, test_mode=False, reset=False):
210212
###############################################################################

scripts/lib/CIME/utils.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ def redirect_logger(new_target, logger_name):
5656
root_log.handlers = orig_root_loggers
5757
log.handlers = orig_handlers
5858

59+
class IndentFormatter(logging.Formatter):
60+
def __init__(self, indent, fmt=None, datefmt=None):
61+
logging.Formatter.__init__(self, fmt, datefmt)
62+
self._indent = indent
63+
64+
def format(self, record):
65+
record.msg = "{}{}".format(self._indent, record.msg)
66+
out = logging.Formatter.format(self, record)
67+
return out
68+
69+
def set_logger_indent(indent):
70+
root_log = logging.getLogger()
71+
root_log.handlers = []
72+
formatter = IndentFormatter(indent)
73+
74+
handler = logging.StreamHandler()
75+
handler.setFormatter(formatter)
76+
root_log.addHandler(handler)
77+
5978
class EnvironmentContext(object):
6079
"""
6180
Context manager for environment variables
@@ -1003,7 +1022,6 @@ def parse_args_and_handle_standard_logging_options(args, parser=None):
10031022
root_logger.setLevel(logging.INFO)
10041023
return args
10051024

1006-
10071025
def get_logging_options():
10081026
"""
10091027
Use to pass same logging options as was used for current

0 commit comments

Comments
 (0)