Skip to content

Commit

Permalink
Merge pull request acisops#65 from jzuhone/logging_cleanup
Browse files Browse the repository at this point in the history
Improve logging to screen and run.dat
  • Loading branch information
jzuhone committed Jul 25, 2023
2 parents b4a805f + 3b9894e commit 090b176
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
repos:
- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.3.0
hooks:
- id: black
language_version: python3.11

- repo: https://github.com/pycqa/isort
rev: 5.11.4
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
43 changes: 20 additions & 23 deletions acis_thermal_check/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,7 @@ def run(self, args, override_limits=None):

# First, do some initial setup and log important information.

if args.model_spec is None:
model_spec = get_xija_model_spec(self.name)[0]
else:
model_spec = args.model_spec

if not isinstance(model_spec, dict):
with open(model_spec) as f:
model_spec = json.load(f)

proc = self._setup_proc_and_logger(args, model_spec)
proc, model_spec = self._setup_proc_and_logger(args)

# Record the selected state builder in the class attributes
# If there is no "state_builder" command line argument assume
Expand Down Expand Up @@ -1404,7 +1395,7 @@ def write_index_rst(self, outdir, context):
with open(outfile, "w") as fout:
fout.write(template.render(**context))

def _setup_proc_and_logger(self, args, model_spec):
def _setup_proc_and_logger(self, args):
"""
This method does some initial setup and logs important
information.
Expand All @@ -1417,7 +1408,17 @@ def _setup_proc_and_logger(self, args, model_spec):
model_spec : string
The path to the thermal model specification.
"""

Check failure on line 1410 in acis_thermal_check/main.py

View workflow job for this annotation

GitHub Actions / build

Ruff (D202)

acis_thermal_check/main.py:1399:9: D202 No blank lines allowed after function docstring (found 1)
import hashlib

if args.model_spec is None:
model_spec, cm_version = get_xija_model_spec(self.name)
ms_out = f"chandra_models v{cm_version}"
else:
model_spec = args.model_spec
cm_version = None
if not isinstance(model_spec, dict):
ms_out = str(Path(model_spec).resolve())
with open(model_spec) as f:
model_spec = json.load(f)

if not args.outdir.exists():
args.outdir.mkdir(parents=True)
Expand All @@ -1436,20 +1437,16 @@ def _setup_proc_and_logger(self, args, model_spec):
hist_limit=self.hist_limit,
)

if isinstance(model_spec, dict):
ms = json.dumps(model_spec, indent=4, sort_keys=True).encode()
else:
with open(model_spec, "rb") as f:
ms = f.read()
# Figure out the MD5 sum of the model spec file
md5sum = hashlib.md5(ms).hexdigest()
mylog.info(
"# %s_check run at %s by %s"
% (self.name, proc["run_time"], proc["run_user"]),

Check failure on line 1442 in acis_thermal_check/main.py

View workflow job for this annotation

GitHub Actions / build

Ruff (UP031)

acis_thermal_check/main.py:1441:13: UP031 Use format specifiers instead of percent format
)
mylog.info("# acis_thermal_check version = %s" % version)
mylog.info("# model_spec file MD5sum = %s" % md5sum)
mylog.info("Command line options:\n%s\n" % pformat(args.__dict__))
mylog.info("# acis_thermal_check version = %s", version)
mylog.info("# chandra_models version = %s", cm_version)
args_out = args.__dict__.copy()
args_out["outdir"] = str(args.outdir.resolve())
args_out["model_spec"] = ms_out
mylog.info("Command line options:\n%s\n", pformat(args_out))

if args.backstop_file is None:
self.bsdir = None
Expand All @@ -1459,7 +1456,7 @@ def _setup_proc_and_logger(self, args, model_spec):
self.bsdir = bf
else:
self.bsdir = PurePath(bf).parent
return proc
return proc, model_spec

def _determine_times(self, run_start, is_weekly_load):
"""
Expand Down

0 comments on commit 090b176

Please sign in to comment.