Skip to content

Commit

Permalink
Merge pull request #301 from choosehappy/bug-fixes
Browse files Browse the repository at this point in the history
added debug option
  • Loading branch information
jacksonjacobs1 authored May 22, 2024
2 parents 37da20a + c5f34a9 commit 8aec606
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
8 changes: 5 additions & 3 deletions histoqc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 -----------------------------------
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 9 additions & 8 deletions histoqc/_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 8aec606

Please sign in to comment.