Print conda install output if running in debug mode, turn on debugging if --debug flag is used

This commit is contained in:
allegroai 2020-05-09 20:11:01 +03:00
parent 21f6a73f66
commit f6be64a4b5
3 changed files with 21 additions and 2 deletions

View File

@ -20,6 +20,8 @@ from .interface import get_parser
def run_command(parser, args, command_name): def run_command(parser, args, command_name):
debug = args.debug debug = args.debug
session.Session.set_debug_mode(debug)
if command_name and command_name.lower() in ('config', 'init'): if command_name and command_name.lower() in ('config', 'init'):
command_class = commands.Config command_class = commands.Config
elif len(command_name.split('.')) < 2: elif len(command_name.split('.')) < 2:

View File

@ -420,10 +420,14 @@ class CondaAPI(PackageManager):
try: try:
print('Executing Conda: {}'.format(command.serialize())) print('Executing Conda: {}'.format(command.serialize()))
result = command.get_output(stdin=DEVNULL, **kwargs) result = command.get_output(stdin=DEVNULL, **kwargs)
if self.session.debug_mode:
print(result)
except Exception as e: except Exception as e:
result = e.output if hasattr(e, 'output') else ''
if self.session.debug_mode:
print(result)
if raw: if raw:
raise raise
result = e.output if hasattr(e, 'output') else ''
if raw: if raw:
return result return result

View File

@ -63,6 +63,7 @@ def tree(*args):
class Session(_Session): class Session(_Session):
version = __version__ version = __version__
force_debug = False
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# make sure we set the environment variable so the parent session opens the correct file # 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() self.config = load()
else: else:
super(Session, self).__init__(*args, **kwargs) 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.log = self.get_logger(__name__)
self.trace = kwargs.get('trace', False) self.trace = kwargs.get('trace', False)
self._config_file = kwargs.get('config_file') or \ self._config_file = kwargs.get('config_file') or \
@ -154,9 +160,16 @@ class Session(_Session):
logger.propagate = True logger.propagate = True
return TrainsAgentLogger(logger) return TrainsAgentLogger(logger)
@staticmethod
def set_debug_mode(enable):
if enable:
import logging
logging.basicConfig(level=logging.DEBUG)
Session.force_debug = enable
@property @property
def debug_mode(self): def debug_mode(self):
return self.config.get("agent.debug", False) return Session.force_debug or self.config.get("agent.debug", False)
@property @property
def config_file(self): def config_file(self):