From 72b362c5571c5b789eadc4bcef52568ff3dbcfa7 Mon Sep 17 00:00:00 2001 From: jackson Date: Thu, 16 May 2024 17:24:57 -0400 Subject: [PATCH 1/3] added debug option --- histoqc/__main__.py | 6 ++++-- histoqc/_pipeline.py | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/histoqc/__main__.py b/histoqc/__main__.py index d86ff7d..02363d8 100644 --- a/histoqc/__main__.py +++ b/histoqc/__main__.py @@ -65,6 +65,7 @@ def main(argv=None): parser.add_argument('--symlink', metavar="TARGET_DIR", help="create symlink to outdir in TARGET_DIR", default=None) + parser.add_argument('--debug', action='store_true', help="trigger debugging behavior") args = parser.parse_args(argv) # --- multiprocessing and logging setup ----------------------------------- @@ -162,10 +163,11 @@ def main(argv=None): 'shared_dict': mpm.dict(), 'num_files': num_files, 'force': args.force, - 'seed': args.seed + 'seed': args.seed, + 'debug': args.debug } failed = mpm.list() - setup_plotting_backend(lm.logger) + setup_plotting_backend(lm.logger, debug=args.debug) try: if args.nprocesses > 1: diff --git a/histoqc/_pipeline.py b/histoqc/_pipeline.py index 5012ce4..66a5922 100644 --- a/histoqc/_pipeline.py +++ b/histoqc/_pipeline.py @@ -188,7 +188,7 @@ def log_pipeline(config, log_manager): # --- worker process helpers ------------------------------------------ -def setup_plotting_backend(logger=None): +def setup_plotting_backend(logger=None, debug=False): """loads the correct matplotlib backend Parameters @@ -197,13 +197,13 @@ def setup_plotting_backend(logger=None): the logging.Logger instance """ import matplotlib - if platform.system() != "Windows" and not os.environ.get('DISPLAY'): - if logger is not None: - logger.info('no display found. Using non-interactive Agg backend') - matplotlib.use('Agg') - else: + + if debug and (platform.system() == "Windows" or os.environ.get('DISPLAY')): matplotlib.use('TkAgg') + else: + matplotlib.use('Agg') + class BatchedResultFile: """BatchedResultFile encapsulates the results writing From c75c89afe5b027da5193fb947047a968d57dc8a1 Mon Sep 17 00:00:00 2001 From: jackson Date: Fri, 17 May 2024 09:05:14 -0400 Subject: [PATCH 2/3] added logging.info message --- histoqc/_pipeline.py | 1 + 1 file changed, 1 insertion(+) diff --git a/histoqc/_pipeline.py b/histoqc/_pipeline.py index 66a5922..1e21ad4 100644 --- a/histoqc/_pipeline.py +++ b/histoqc/_pipeline.py @@ -200,6 +200,7 @@ def setup_plotting_backend(logger=None, debug=False): if debug and (platform.system() == "Windows" or os.environ.get('DISPLAY')): matplotlib.use('TkAgg') + logger.info("Display found and debug mode enabled. Using TkAgg backend for matplotlib.") else: matplotlib.use('Agg') From c5f34a93b0911bbf3d386faa61128ef3507ca3d0 Mon Sep 17 00:00:00 2001 From: jackson Date: Tue, 21 May 2024 15:06:19 -0400 Subject: [PATCH 3/3] set debugging level to DEBUG conditionally --- histoqc/__main__.py | 2 +- histoqc/_pipeline.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/histoqc/__main__.py b/histoqc/__main__.py index 02363d8..1324cf2 100644 --- a/histoqc/__main__.py +++ b/histoqc/__main__.py @@ -105,7 +105,7 @@ def main(argv=None): # --- create output directory and move log -------------------------------- args.outdir = os.path.expanduser(args.outdir) os.makedirs(args.outdir, exist_ok=True) - move_logging_file_handler(logging.getLogger(), args.outdir) + move_logging_file_handler(logging.getLogger(), args.outdir, args.debug) if BatchedResultFile.results_in_path(args.outdir): if args.force: diff --git a/histoqc/_pipeline.py b/histoqc/_pipeline.py index 1e21ad4..2c61e6d 100644 --- a/histoqc/_pipeline.py +++ b/histoqc/_pipeline.py @@ -67,7 +67,7 @@ def setup_logging(*, capture_warnings, filter_warnings): logging.captureWarnings(capture_warnings) -def move_logging_file_handler(logger, destination): +def move_logging_file_handler(logger, destination, debug=False): """point the logging file handlers to the new destination Parameters @@ -94,7 +94,7 @@ def move_logging_file_handler(logger, destination): new_filename = shutil.move(handler.baseFilename, destination) new_handler = logging.FileHandler(new_filename, mode='a') - new_handler.setLevel(handler.level) + new_handler.setLevel(logging.DEBUG if debug else handler.level) new_handler.setFormatter(handler.formatter) logger.addHandler(new_handler)