internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: ipython/ipython

Issue:
IPython.embed changes color on error
`IPython.embed` does something weird when you raise an error: it changes color!

In your config, set colors to non-default:

```
c.TerminalInteractiveShell.colors = 'Linux' # or 'LightBG' on Linux
```

Then embed IPython anywhere, and raise an exception (just 1/0 is enough).  After the traceback, the color scheme will have reverted to the default (confirmed on both Linux and OS X, with different defaults).

I imagine this is due to lacking a `Singleton.instance()` somewhere, which does not exist when IPython is embedded, but does from a normal entry point.



Discussion:

Resolving patch:
diff --git a/IPython/frontend/terminal/embed.py b/IPython/frontend/terminal/embed.py
--- a/IPython/frontend/terminal/embed.py
+++ b/IPython/frontend/terminal/embed.py
@@ -264,8 +264,6 @@ class DummyMod(object):
         self.user_ns = orig_user_ns
         self.compile.flags = orig_compile_flags
 
-_embedded_shell = None
-
 
 def embed(**kwargs):
     """Call this to embed IPython at the current point in your program.
@@ -284,7 +282,7 @@ def embed(**kwargs):
         d = 40
         embed
 
-    Full customization can be done by passing a :class:`Struct` in as the
+    Full customization can be done by passing a :class:`Config` in as the
     config argument.
     """
     config = kwargs.get('config')
@@ -294,7 +292,5 @@ def embed(**kwargs):
         config = load_default_config()
         config.InteractiveShellEmbed = config.TerminalInteractiveShell
         kwargs['config'] = config
-    global _embedded_shell
-    if _embedded_shell is None:
-        _embedded_shell = InteractiveShellEmbed(**kwargs)
-    _embedded_shell(header=header, stack_depth=2, compile_flags=compile_flags)
+    shell = InteractiveShellEmbed.instance(**kwargs)
+    shell(header=header, stack_depth=2, compile_flags=compile_flags)


Test patch:
Repository: ipython/ipython

Issue:
ipengines fail if clean_logs enabled
in ipython 1.4dev, if I set:

```
# whether to cleanup old logfiles before starting
c.IPEngineApp.clean_logs = True
```

in ipengine_config.py
many engines fail with this sort of error:

```
File "???????/site-packages/IPython/parallel/apps/baseapp.py", line 173, in reinit_logging
os.remove(os.path.join(log_dir, f))
OSError: [Errno 2] No such file or directory: '????zonca/.config/ipython/profile_default/log/ipengine-    21849.log'
```

can you please take a look at this issue?
thanks,
andrea



Discussion:

Resolving patch:
diff --git a/IPython/parallel/apps/baseapp.py b/IPython/parallel/apps/baseapp.py
--- a/IPython/parallel/apps/baseapp.py
+++ b/IPython/parallel/apps/baseapp.py
@@ -169,8 +169,13 @@ def reinit_logging(self):
         log_dir = self.profile_dir.log_dir
         if self.clean_logs:
             for f in os.listdir(log_dir):
-                if re.match(r'%s-\d+\.(log|err|out)'%self.name,f):
-                    os.remove(os.path.join(log_dir, f))
+                if re.match(r'%s-\d+\.(log|err|out)' % self.name, f):
+                    try:
+                        os.remove(os.path.join(log_dir, f))
+                    except (OSError, IOError):
+                        # probably just conflict from sibling process
+                        # already removing it
+                        pass
         if self.log_to_file:
             # Start logging to the new log file
             log_filename = self.name + u'-' + str(os.getpid()) + u'.log'


Test patch:
Repository: ipython/ipython

Issue:
Allow `python -m IPython`
Is there any reason why we don't allow IPython to be run as a module as in `python -m IPython`?

I'd expect the behavior to be the same as running `ipython.py` or the current:

``` sh
$ python -m IPython.frontend.terminal.ipapp
```



Discussion:
Not really - should be 2-3 lines, might as well.


Resolving patch:
diff --git a/IPython/__main__.py b/IPython/__main__.py
new file mode 100644
--- /dev/null
+++ b/IPython/__main__.py
@@ -0,0 +1,14 @@
+# encoding: utf-8
+"""Terminal-based IPython entry point.
+"""
+#-----------------------------------------------------------------------------
+#  Copyright (c) 2012, IPython Development Team.
+#
+#  Distributed under the terms of the Modified BSD License.
+#
+#  The full license is in the file COPYING.txt, distributed with this software.
+#-----------------------------------------------------------------------------
+
+from IPython.frontend.terminal.ipapp import launch_new_instance
+
+launch_new_instance()


Test patch:
Repository: ipython/ipython

Issue:
IPython 0.13.1 python 2 32-bit installer includes 64-bit ipython*.exe launchers in the scripts folder
The launcher exes in the scripts folder (ipython.exe and such) are 64-bit binaries in the Python 2 32-bit installer (possibly also in the Python 3 installer) this means that under 32-bit Windows installations they don't work.



Discussion:
I can not reproduce this problem with the 32-bit installer downloaded from: https://github.com/downloads/ipython/ipython/ipython-0.13.1.py2-win32.exe

The installed ipython.exe runs just fine and gives me 32-bit python.

Did you try to uninstall and then make sure all ipython related files were deleted from Python27\Scripts and then reinstall. Did you install using administrator privileges?

using [EXE Explorer](http://www.mitec.cz/exe.html), I can confirm that the py2-win32 installer gives 32b executables and the py3-64 installer gives 32b executables.  I'm not sure the py3-64 case is a problem, since the 32b executable actually works fine.  The 64b py2-32 executable will work fine _on 64b Windows_, but not an actual 32b Windows system (why does such a thing still exist?!).

The explanation being [here](http://docs.python.org/2/distutils/builtdist.html#cross-compiling-on-windows), that Windows Python cannot cross-compile (though it will not raise any errors, it will just do it wrong), and my default python2 is 64b and my default python3 is 32b.  The answer is to generate each installer with the target Python.

I have updated release_windows.py to do this, and I believe that I now have the right installers.

Regenerated installers currently at [archive.ipython.org](http://archive.ipython.org/testing/0.13.1/) if anyone wants to test/confirm.

Should I upload them, and just clobber the bad installers (py2-32 and/or py3-64)?


Resolving patch:
diff --git a/tools/release_windows.py b/tools/release_windows.py
--- a/tools/release_windows.py
+++ b/tools/release_windows.py
@@ -23,20 +23,34 @@
 
 github = '--github' in sys.argv
 
-cmd_t = "{py} setup.py bdist_wininst --plat-name={plat}"
+cmd_t = "{py} setup.py bdist_wininst"
 
 pypi = '--pypi' in sys.argv
 pypi_cmd_t = "python setup.py upload_wininst -f {fname}"
 
-for py in ['python', 'python3']:
+# Windows Python cannot normally cross-compile,
+# so you must have 4 Pythons to make 4 installers:
+# http://docs.python.org/2/distutils/builtdist.html#cross-compiling-on-windows
+
+pythons = {
+    2: {
+        'win32' : r'C:\\Python27\Python.exe',
+        'win-amd64': r'C:\\Python27_64\Python.exe',
+    },
+    3: {
+        'win32' : r'C:\\Python33\Python.exe',
+        'win-amd64': r'C:\\Python33_64\Python.exe',
+    },
+}
+
+for v,plat_py in pythons.items():
     # deliberately mangle the name,
     # so easy_install doesn't find these and do horrible wrong things
-    v = 3 if py.endswith('3') else 2
     try:
         shutil.rmtree('build')
     except OSError:
         pass
-    for plat in ['win32', 'win-amd64']:
+    for plat,py in plat_py.items():
         cmd = cmd_t.format(**locals())
         sh(cmd)
         orig = glob.glob(os.path.join('dist', 'ipython-*.{plat}.exe'.format(**locals())))[0]


Test patch:
Repository: ipython/ipython

Issue:
List command doesn't work in ipdb debugger the first time
When starting a debug session, if the very first command issued is `l` (`list`), it doesn't work.  Once at least one statement has been executed, then it's OK:

```
In [1]: run -d -b50 ~/scratch/error.py
Breakpoint 1 at /home/fperez/scratch/error.py:50
NOTE: Enter 'c' at the ipdb>  prompt to start your script.
> <string>(1)<module>()

ipdb> l

ipdb> n
> /home/fperez/scratch/error.py(50)main()
     49     size = 6
1--> 50     reps = 5
     51     import pdb; pdb.set_trace()

ipdb> l
     45     result[:] = arange(size)*step + start
     46 
     47 def main():
     48     #print 'hi'
     49     size = 6
1--> 50     reps = 5
     51     import pdb; pdb.set_trace()
     52     print 'reps:',reps
     53     array_normal = [0]*size
     54     t0=time.clock()
     55     for i in xrange(reps):    # <<<<< ERROR (fork instead of for)

ipdb> 
```

There's likely a file cache loading that isn't happening at the start, which we need to do.



Discussion:
It's because the current frame is wrong for the first `l` call.  Note the previous text...  The current frame is `<string>(1)<module>()`, but after we take a step the frame changes to `/home/fperez/scratch/error.py(50)main()`.

I think this is a problem with `pdb` itself, or perhaps our approach to running the file:

```
>>> import pdb
>>> deb = pdb.Pdb()
>>> deb.do_break('setup.py:45')
Breakpoint 1 at /home/bfroehle/src/ipython/setup.py:45
>>> ns = {'execfile': execfile}
>>> deb.run('execfile("setup.py")', ns)
> <string>(1)<module>()
(Pdb) list
[EOF]
(Pdb) n
> /home/bfroehle/src/ipython/setup.py(45)<module>()
-> import os
(Pdb) list
 40     #-------------------------------------------------------------------------------
 41     # Imports
 42     #-------------------------------------------------------------------------------
 43     
 44     # Stdlib imports
 45 B-> import os
 46     import shutil
 47     
 48     from glob import glob
 49     
 50     # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
```


Resolving patch:
diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py
--- a/IPython/core/magics/execution.py
+++ b/IPython/core/magics/execution.py
@@ -563,6 +563,11 @@ def run(self, parameter_s='', runner=None,
                                 return
                         # if we find a good linenumber, set the breakpoint
                         deb.do_break('%s:%s' % (filename, bp))
+
+                        # Mimic Pdb._runscript(...)
+                        deb._wait_for_mainpyfile = True
+                        deb.mainpyfile = deb.canonic(filename)
+
                         # Start file run
                         print "NOTE: Enter 'c' at the",
                         print "%s prompt to start your script." % deb.prompt


Test patch:
Repository: ipython/ipython

Issue:
small issue: wrong printout
The ipython notebook proclaims:
"WARNING: the notebook server is listening on all IP addresses but not using any encryption or authentication"

although it is using authentication (but it doesn't use encryption). 

That should be changed to:
"WARNING: the notebook server is listening on all IP addresses but is not using BOTH encryption and authentication"



Discussion:
Perhaps this should be split into two error messages?
`WARNING: ... no authentication`
`WARNING: ... not encrypted, ... blah blah insecure.`

That works as well (is even better, but is slightly more work). It really is a small thing, but I thought I mention it. 


Resolving patch:
diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py
--- a/IPython/frontend/html/notebook/notebookapp.py
+++ b/IPython/frontend/html/notebook/notebookapp.py
@@ -470,11 +470,14 @@ def init_webapp(self):
             ssl_options = None
         self.web_app.password = self.password
         self.http_server = httpserver.HTTPServer(self.web_app, ssl_options=ssl_options)
-        if ssl_options is None and not self.ip and not (self.read_only and not self.password):
-            self.log.critical('WARNING: the notebook server is listening on all IP addresses '
-                              'but not using any encryption or authentication. This is highly '
-                              'insecure and not recommended.')
-
+        if not self.ip:
+            warning = "WARNING: The notebook server is listening on all IP addresses"
+            if ssl_options is None:
+                self.log.critical(warning + " and not using encryption. This"
+                    "is not recommended.")
+            if not self.password and not self.read_only:
+                self.log.critical(warning + "and not using authentication."
+                    "This is highly insecure and not recommended.")
         success = None
         for port in random_ports(self.port, self.port_retries+1):
             try:


Test patch:
Repository: ipython/ipython

Issue:
Qtconsole tooltip is too wide when the function has many arguments



Discussion:

Resolving patch:
diff --git a/IPython/frontend/qt/console/call_tip_widget.py b/IPython/frontend/qt/console/call_tip_widget.py
--- a/IPython/frontend/qt/console/call_tip_widget.py
+++ b/IPython/frontend/qt/console/call_tip_widget.py
@@ -137,7 +137,7 @@ def show_call_info(self, call_line=None, doc=None, maxlines=20):
 
         if call_line:
             doc = '\n\n'.join([call_line, doc])
-        return self.show_tip(doc)
+        return self.show_tip(self._format_tooltip(doc))
 
     def show_tip(self, tip):
         """ Attempts to show the specified tip at the current cursor location.
@@ -248,6 +248,17 @@ def _leave_event_hide(self):
             QtGui.qApp.topLevelAt(QtGui.QCursor.pos()) != self):
             self._hide_timer.start(300, self)
 
+    def _format_tooltip(self,doc):
+        import textwrap
+
+        # make sure a long argument list does not make
+        # the first row overflow the width of the actual tip body
+        rows = doc.split("\n")
+        max_text_width = max(80, max([len(x) for x in rows[1:]]))
+        rows= textwrap.wrap(rows[0],max_text_width) + rows[1:]
+        doc = "\n".join(rows)
+        return doc
+
     #------ Signal handlers ----------------------------------------------------
 
     def _cursor_position_changed(self):


Test patch:
Repository: ipython/ipython

Issue:
Fix: Rpush magic doesn't find local variables and doesn't support comma separated lists of variables
Described in issue #2550. This is a simple fix. It has tests.

Note. I submitted this PR a while ago, but then messed up my `git`. I did a hard reset and tried again. The old PR was #2552.



Discussion:

Resolving patch:
diff --git a/IPython/extensions/rmagic.py b/IPython/extensions/rmagic.py
--- a/IPython/extensions/rmagic.py
+++ b/IPython/extensions/rmagic.py
@@ -178,8 +178,9 @@ def flush(self):
         return value
 
     @skip_doctest
+    @needs_local_scope
     @line_magic
-    def Rpush(self, line):
+    def Rpush(self, line, local_ns=None):
         '''
         A line-level magic for R that pushes
         variables from python to rpy2. The line should be made up
@@ -199,10 +200,16 @@ def Rpush(self, line):
             Out[11]: array([ 6.23333333])
 
         '''
+        if local_ns is None:
+            local_ns = {}
 
         inputs = line.split(' ')
         for input in inputs:
-            self.r.assign(input, self.pyconverter(self.shell.user_ns[input]))
+            try:
+                val = local_ns[input]
+            except KeyError:
+                val = self.shell.user_ns[input]
+            self.r.assign(input, self.pyconverter(val))
 
     @skip_doctest
     @magic_arguments()


Test patch:
diff --git a/IPython/extensions/tests/test_rmagic.py b/IPython/extensions/tests/test_rmagic.py
--- a/IPython/extensions/tests/test_rmagic.py
+++ b/IPython/extensions/tests/test_rmagic.py
@@ -14,6 +14,20 @@ def test_push():
     np.testing.assert_almost_equal(np.asarray(rm.r('X')), ip.user_ns['X'])
     np.testing.assert_almost_equal(np.asarray(rm.r('Y')), ip.user_ns['Y'])
 
+def test_push_localscope():
+    """Test that Rpush looks for variables in the local scope first."""
+    ip.run_cell('''
+def rmagic_addone(u):
+    %Rpush u
+    %R result = u+1
+    %Rpull result
+    return result[0]
+u = 0
+result = rmagic_addone(12344)
+    ''')
+    result = ip.user_ns['result']
+    np.testing.assert_equal(result, 12345)
+
 def test_pull():
     rm = rmagic.RMagics(ip)
     rm.r('Z=c(11:20)')
Repository: ipython/ipython

Issue:
AttributeError: 'Client' object has no attribute 'kill'
The kill method on a DirectView throws an attribute error. The following code demonstrates the problem:

``` python
import time
from IPython.utils.path import locate_profile
from IPython.parallel.apps.launcher import LocalControllerLauncher, LocalEngineLauncher
from IPython.parallel import Client
controller = LocalControllerLauncher(profile_dir=locate_profile())
controller.start()
e = LocalEngineLauncher(profile_dir=locate_profile())
e.start()
time.sleep(1)
rc = Client()
time.sleep(5)
dv = rc[:]
dv.kill()
rc.shutdown(hub=True)
```



Discussion:
kill should be removed.


Resolving patch:
diff --git a/IPython/parallel/client/view.py b/IPython/parallel/client/view.py
--- a/IPython/parallel/client/view.py
+++ b/IPython/parallel/client/view.py
@@ -784,12 +784,6 @@ def clear(self, targets=None, block=False):
         targets = targets if targets is not None else self.targets
         return self.client.clear(targets=targets, block=block)
 
-    def kill(self, targets=None, block=True):
-        """Kill my engines."""
-        block = block if block is not None else self.block
-        targets = targets if targets is not None else self.targets
-        return self.client.kill(targets=targets, block=block)
-
     #----------------------------------------
     # activate for %px, %autopx, etc. magics
     #----------------------------------------


Test patch:
Repository: ipython/ipython

Issue:
Cython -la doesn't work
It's parsed as -l instead.

``` python
    @magic_arguments.argument(
        '-la', '--link-args', action='append', default=[],
        help="Extra flags to pass to linker via the `extra_link_args` "
             "Extension flag (can be specified  multiple times)."
    )
    @magic_arguments.argument(
        '-l', '--lib', action='append', default=[],
        help="Add a library to link the extension against (can be specified "
             "multiple times)."
    )
```



Discussion:
Can we just get rid of `-la` and use `--link-args` always?  Or would you suggest a different short argument?

I use link-args.. lets see
a b c d e f g h i j k l m n o p q r s t u v w x y z...
No good letter. Just get rid of them I think.


Resolving patch:
diff --git a/IPython/extensions/cythonmagic.py b/IPython/extensions/cythonmagic.py
--- a/IPython/extensions/cythonmagic.py
+++ b/IPython/extensions/cythonmagic.py
@@ -132,7 +132,7 @@ def f(x):
              "Extension flag (can be specified  multiple times)."
     )
     @magic_arguments.argument(
-        '-la', '--link-args', action='append', default=[],
+        '--link-args', action='append', default=[],
         help="Extra flags to pass to linker via the `extra_link_args` "
              "Extension flag (can be specified  multiple times)."
     )


Test patch:
Repository: ipython/ipython

Issue:
History navigation breaks in qtconsole
I observe that, under some particular conditions, the behavior of the history navigation in the qtconsole breaks.

Typically, if I type a letter, say 'a', and then press the up arrow key, IPython only shows the items in the history that start with that letter. However, under some conditions this behavior stop working.

The phenomenon can be observed by typing the following in a qtconsole instance. (I am just showing what I type, not the IPython output):

```
a=1 'Enter'
b=2 'Enter'
b C-p C-a C-k a C-p
```

Here 'Enter' corresponds to pressing the enter key, and C-x corresponds to pressing Ctrl and the 'x' key.

In this example, I expect that, after pressing C-p the last time, I should see 'a=1' in the prompt (that's what I see after doing this in a terminal IPython instance), however, I see 'b=2' in the prompt.



Discussion:
I have the same issue, when I do ctrl-k on part of line, prefix history navigating no longer works


Resolving patch:
diff --git a/IPython/frontend/qt/console/history_console_widget.py b/IPython/frontend/qt/console/history_console_widget.py
--- a/IPython/frontend/qt/console/history_console_widget.py
+++ b/IPython/frontend/qt/console/history_console_widget.py
@@ -76,9 +76,22 @@ def _up_pressed(self, shift_modifier):
             # Set a search prefix based on the cursor position.
             col = self._get_input_buffer_cursor_column()
             input_buffer = self.input_buffer
-            if self._history_index == len(self._history) or \
-                    (self._history_prefix and col != len(self._history_prefix)):
+            # use the *shortest* of the cursor column and the history prefix
+            # to determine if the prefix has changed
+            n = min(col, len(self._history_prefix))
+            
+            # prefix changed, restart search from the beginning
+            if (self._history_prefix[:n] != input_buffer[:n]):
                 self._history_index = len(self._history)
+            
+            # the only time we shouldn't set the history prefix
+            # to the line up to the cursor is if we are already
+            # in a simple scroll (no prefix),
+            # and the cursor is at the end of the first line
+            first_line = input_buffer.split('\n', 1)[0]
+            if self._history_index == len(self._history) or \
+                not (self._history_prefix == '' and col == len(first_line)) or \
+                not (self._get_edited_history(self._history_index)[:col] == input_buffer[:col]):
                 self._history_prefix = input_buffer[:col]
 
             # Perform the search.
@@ -179,7 +192,7 @@ def history_next(self, substring='', as_prefix=True):
         """
         index = self._history_index
         replace = False
-        while self._history_index < len(self._history):
+        while index < len(self._history):
             index += 1
             history = self._get_edited_history(index)
             if (as_prefix and history.startswith(substring)) \


Test patch:
Repository: ipython/ipython

Issue:
tab auto-completion fails if there is no space
``` python
In [1]: import numpy as np

In [2]: x=np.[tab]
--> no auto-completion

In [2]: x= np.[tab]
--> ok
```



Discussion:
This is because you've set the `--enforce-pep8` flag.

Without kidding, which frontend ? Both works for me in terminal and qtconsole.
Which IPython version ?

:) yeah, I always try to follow PEP8, but was in a hurry and then I noticed this (although working example also violates PEP8 ;)

Noticed in latest stable (0.13.1), in both qtconsole and terminal console, on Windows XP with Python27

`ipython_config.py` in my profile folder is all commented except: `c.IPCompleter.greedy = True`

I think greedy is the issue. Without the greedy completer it works fine but for me but with it I can confirm this behaviour 
i.e. no tab completion after `a =np.a` @klonuo  does it work for you if you change greedy to false?

yep, that's the offender

This is quick fix:

``` diff
index 83f9f5b..45c8413 100644
--- "a/IPython\\core\\completer.py"
+++ "b/IPython\\core\\completer.py"
@@ -182,7 +182,7 @@ class Bunch(object): pass


 DELIMS = ' \t\n`!@#$^&*()=+[{]}\\|;:\'",<>?'
-GREEDY_DELIMS = ' \r\n'
+GREEDY_DELIMS = ' =\r\n'


 class CompletionSplitter(object):
```

But I think some more experienced should look at it.

That does sound reasonable - it shouldn't have to look to the left of an =
to do the completion.


Resolving patch:
diff --git a/IPython/core/completer.py b/IPython/core/completer.py
--- a/IPython/core/completer.py
+++ b/IPython/core/completer.py
@@ -182,7 +182,7 @@ class Bunch(object): pass
 
 
 DELIMS = ' \t\n`!@#$^&*()=+[{]}\\|;:\'",<>?'
-GREEDY_DELIMS = ' \r\n'
+GREEDY_DELIMS = ' =\r\n'
 
 
 class CompletionSplitter(object):


Test patch: