diff --git a/histoqc/__main__.py b/histoqc/__main__.py index d86ff7d..1324cf2 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 ----------------------------------- @@ -104,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: @@ -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..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) @@ -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,12 +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') + logger.info("Display found and debug mode enabled. Using TkAgg backend for matplotlib.") + + else: + matplotlib.use('Agg') class BatchedResultFile: