ESCOMP / CTSM

Community Terrestrial Systems Model (includes the Community Land Model of CESM)
http://www.cesm.ucar.edu/models/cesm2.0/land/
Other
308 stars 312 forks source link

Change python print statements to using standard python logging #1601

Open ekluzek opened 2 years ago

ekluzek commented 2 years ago

There's a few python modules under the python directory that still use a print statement rather than using python logging. These should be updated to use our standard python logging system.

for example "git grep 'print(' shows the following...

ctsm/config_utils.py: print("val = ", val, " in var not in allowed_values") ctsm/lilac_build_ctsm.py: print('Initial setup complete; it is now safe to work with the runtime inputs in\n' ctsm/os_utils.py: print('ERROR while running:') ctsm/os_utils.py: print(' '.join(cmd)) ctsm/os_utils.py: print('From {}'.format(cwd)) ctsm/os_utils.py: print('') ctsm/os_utils.py: print(error.output) ctsm/os_utils.py: print('') ctsm/os_utils.py: print('ERROR trying to run:') ctsm/os_utils.py: print(' '.join(cmd)) ctsm/os_utils.py: print('From {}'.format(cwd)) ctsm/run_sys_tests.py: print("Testroot: {}\n".format(testroot)) ctsm/run_sys_tests.py: print(output) ctsm/subset_data.py: print("Must supply a positional argument: 'point' or 'region'.") ctsm/subset_data.py: print("See ./subset_data --help for more help.") ctsm/subset_data.py: print("Must supply one of:") ctsm/subset_data.py: print(" --create-surface \n --create-landuse \n --create-datm \n --create-domain") ctsm/subset_data.py: print("See ./subset_data --help for more help.") ctsm/utils.py: print("val = ", val, " in var not in allowed_values")

adrifoster commented 2 years ago

ctsm/subset_data.py: print("Must supply a positional argument: 'point' or 'region'.") ctsm/subset_data.py: print("See ./subset_data --help for more help.") ctsm/subset_data.py: print("Must supply one of:") ctsm/subset_data.py: print(" --create-surface \n --create-landuse \n --create-datm \n --create-domain") ctsm/subset_data.py: print("See ./subset_data --help for more help.")

I think these were actually going to get changed to argparse.ArgumentErrors? @negin513 clarify if I am wrong though!

ekluzek commented 2 years ago

Note, we decided in our new command line standards for python tools (and meeting yesterday with a group of us), that some careful use of print statements are acceptable. The minimum required output should be done using print statements, for the minimum list of things that should be done no matter what. The INFO and DEBUG levels should also be used for extra logging output. But, even so I think most of this list should be changed from print to logging.