From ea09ed9f7611528c9a0b0a3fa9775c5d14b06bf4 2012-08-14 13:15:30 From: Thomas Kluyver Date: 2012-08-14 13:15:30 Subject: [PATCH] Fix IPython.utils.warn API so messages are automatically displayed followed by a newline. --- diff --git a/IPython/core/history.py b/IPython/core/history.py index 73f1b72..1dff7e1 100644 --- a/IPython/core/history.py +++ b/IPython/core/history.py @@ -137,7 +137,7 @@ class HistoryAccessor(Configurable): self.hist_file = self._get_hist_file_name(profile) if sqlite3 is None and self.enabled: - warn("IPython History requires SQLite, your history will not be saved\n") + warn("IPython History requires SQLite, your history will not be saved") self.enabled = False if sqlite3 is not None: diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 67c124f..9e0ee6a 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -336,7 +336,7 @@ class InteractiveShell(SingletonConfigurable): 'prompt_out' : 'out_template', 'prompts_pad_left' : 'justify', } - warn("InteractiveShell.{name} is deprecated, use PromptManager.{newname}\n".format( + warn("InteractiveShell.{name} is deprecated, use PromptManager.{newname}".format( name=name, newname=table[name]) ) # protect against weird cases where self.config may not exist: @@ -721,7 +721,7 @@ class InteractiveShell(SingletonConfigurable): return warn("Attempting to work in a virtualenv. If you encounter problems, please " - "install IPython inside the virtualenv.\n") + "install IPython inside the virtualenv.") if sys.platform == "win32": virtual_env = os.path.join(os.environ['VIRTUAL_ENV'], 'Lib', 'site-packages') else: diff --git a/IPython/frontend/terminal/ipapp.py b/IPython/frontend/terminal/ipapp.py index f6c3f7e..2d2ef09 100755 --- a/IPython/frontend/terminal/ipapp.py +++ b/IPython/frontend/terminal/ipapp.py @@ -351,7 +351,7 @@ class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp): """Replace --pylab='inline' with --pylab='auto'""" if new == 'inline': warn.warn("'inline' not available as pylab backend, " - "using 'auto' instead.\n") + "using 'auto' instead.") self.pylab = 'auto' def start(self): diff --git a/IPython/lib/inputhook.py b/IPython/lib/inputhook.py index b0e9a67..c2dd403 100644 --- a/IPython/lib/inputhook.py +++ b/IPython/lib/inputhook.py @@ -105,7 +105,7 @@ class InputHookManager(object): def __init__(self): if ctypes is None: - warn("IPython GUI event loop requires ctypes, %gui will not be available\n") + warn("IPython GUI event loop requires ctypes, %gui will not be available") return self.PYFUNC = ctypes.PYFUNCTYPE(ctypes.c_int) self._apps = {} diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index 9e37416..c2c4a75 100644 --- a/IPython/testing/iptest.py +++ b/IPython/testing/iptest.py @@ -319,7 +319,7 @@ def make_exclude(): continue fullpath = pjoin(parent, exclusion) if not os.path.exists(fullpath) and not glob.glob(fullpath + '.*'): - warn("Excluding nonexistent file: %r\n" % exclusion) + warn("Excluding nonexistent file: %r" % exclusion) return exclusions diff --git a/IPython/utils/attic.py b/IPython/utils/attic.py index 18d53b0..52fd799 100644 --- a/IPython/utils/attic.py +++ b/IPython/utils/attic.py @@ -130,9 +130,9 @@ def import_fail_info(mod_name,fns=None): """Inform load failure for a module.""" if fns == None: - warn("Loading of %s failed.\n" % (mod_name,)) + warn("Loading of %s failed." % (mod_name,)) else: - warn("Loading of %s from %s failed.\n" % (fns,mod_name)) + warn("Loading of %s from %s failed." % (fns,mod_name)) class NotGiven: pass diff --git a/IPython/utils/warn.py b/IPython/utils/warn.py index 530b70b..693eeb3 100644 --- a/IPython/utils/warn.py +++ b/IPython/utils/warn.py @@ -42,7 +42,7 @@ def warn(msg,level=2,exit_val=1): if level>0: header = ['','','WARNING: ','ERROR: ','FATAL ERROR: '] - io.stderr.write('%s%s' % (header[level],msg)) + print(header[level], msg, sep='', file=io.stderr) if level == 4: print('Exiting.\n', file=io.stderr) sys.exit(exit_val)