From f6be64a4b56b32920078cae91444f6f27b1236e8 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Sat, 9 May 2020 20:11:01 +0300 Subject: [PATCH] Print conda install output if running in debug mode, turn on debugging if --debug flag is used --- trains_agent/__main__.py | 2 ++ trains_agent/helper/package/conda_api.py | 6 +++++- trains_agent/session.py | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/trains_agent/__main__.py b/trains_agent/__main__.py index 5ca6f43..3f63bbd 100644 --- a/trains_agent/__main__.py +++ b/trains_agent/__main__.py @@ -20,6 +20,8 @@ from .interface import get_parser def run_command(parser, args, command_name): debug = args.debug + session.Session.set_debug_mode(debug) + if command_name and command_name.lower() in ('config', 'init'): command_class = commands.Config elif len(command_name.split('.')) < 2: diff --git a/trains_agent/helper/package/conda_api.py b/trains_agent/helper/package/conda_api.py index 9ef24d0..ddda0c3 100644 --- a/trains_agent/helper/package/conda_api.py +++ b/trains_agent/helper/package/conda_api.py @@ -420,10 +420,14 @@ class CondaAPI(PackageManager): try: print('Executing Conda: {}'.format(command.serialize())) result = command.get_output(stdin=DEVNULL, **kwargs) + if self.session.debug_mode: + print(result) except Exception as e: + result = e.output if hasattr(e, 'output') else '' + if self.session.debug_mode: + print(result) if raw: raise - result = e.output if hasattr(e, 'output') else '' if raw: return result diff --git a/trains_agent/session.py b/trains_agent/session.py index 44164ab..0cbeb23 100644 --- a/trains_agent/session.py +++ b/trains_agent/session.py @@ -63,6 +63,7 @@ def tree(*args): class Session(_Session): version = __version__ + force_debug = False def __init__(self, *args, **kwargs): # make sure we set the environment variable so the parent session opens the correct file @@ -83,6 +84,11 @@ class Session(_Session): self.config = load() else: super(Session, self).__init__(*args, **kwargs) + + # set force debug mode, if it's on: + if Session.force_debug: + self.config["agent"]["debug"] = True + self.log = self.get_logger(__name__) self.trace = kwargs.get('trace', False) self._config_file = kwargs.get('config_file') or \ @@ -154,9 +160,16 @@ class Session(_Session): logger.propagate = True return TrainsAgentLogger(logger) + @staticmethod + def set_debug_mode(enable): + if enable: + import logging + logging.basicConfig(level=logging.DEBUG) + Session.force_debug = enable + @property def debug_mode(self): - return self.config.get("agent.debug", False) + return Session.force_debug or self.config.get("agent.debug", False) @property def config_file(self):