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

Issue:
 _margv  for macros seems to be missing
At one point in time, arguments to macro's could be obtained from _margv , but this seems to be missing now ( https://github.com/ipython/ipython/wiki/Cookbook:-Macro-arguments ).  

I searched the entire ipython folder and only found _margv in the documentation in the macro.py file. 

Just wondering if this is still supported.  



Discussion:
You're right, that doesn't seem to exist any more. At one point we deliberately dropped some features of macros on the grounds that for more complex use cases, you should be writing real functions. I forget if arguments were one of those.

Sorry for slow reply... Been out of town...  Macros sometimes work better in the notebook than .py files do.  For example, using %run to load "DetachableViews" in the notebook 

http://nbviewer.ipython.org/5922309

was problematic, but with %macro it works great -- students can just "load and go".   

When you say 'problematic', what problem did you encounter? You might want
to try it with %run -i to run it in the interactive namespace.

On 3 July 2013 22:57, Jeff Knisley notifications@github.com wrote:

> Sorry for slow reply... Been out of town... Macros sometimes work better
> in the notebook than .py files do. For example, using %run to load
> "DetachableViews" in the notebook
> 
> http://nbviewer.ipython.org/5922309
> 
> was problematic, but with %macro it works great -- students can just "load
> and go".
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/issues/3476#issuecomment-20447514
> .

Thanks. I typically do use %run -i, but the %macro approach is still often better.  For example, the notebook at 

 http://nbviewer.ipython.org/5922309

was developed this spring while I was teaching a class via Wakari.io.  There was a long stretch when the notebook couldn't access local folders.  The ability to run the macro on a remote url saved the day.  

We also had to reload the page on a regular basis, and using a one word macro was nice.  

Wakari provides good file access now, but there are still online installs -- e.g., some EC2 images -- where local folder access is not supported. 


Resolving patch:
diff --git a/IPython/core/macro.py b/IPython/core/macro.py
--- a/IPython/core/macro.py
+++ b/IPython/core/macro.py
@@ -19,8 +19,6 @@ class Macro(object):
 
     Macro is just a callable that executes a string of IPython
     input when called.
-    
-    Args to macro are available in _margv list if you need them.
     """
 
     def __init__(self,code):


Test patch:
Repository: ipython/ipython

Issue:
[notebook]user needs to press ctrl-c twice to stop notebook server should be put into terminal window
See attached screenshot, "Use Control-C to stop this server" should be changed to "Press Control-C twice to stop this server".

The document for this new feature was hidden in release notes of 3.0. It's not noticeable.

![Image 1](https://f.cloud.github.com/assets/3401968/186510/33101b98-7d2f-11e2-9d63-03161d660115.png)



Discussion:
Which version are you using ? (there are not 3.0 do you mean 0.13.x ? ) 

I got : 

```
$ ipython notebook
[NotebookApp] Using existing profile dir: u'/Users/bussonniermatthias/.ipython/profile_default'
[NotebookApp] Serving notebooks from local directory: /Users/bussonniermatthias/ipython/IPython/frontend/html/notebook/static/js
[NotebookApp] The IPython Notebook is running at: http://127.0.0.1:8888/
[NotebookApp] Use Control-C to stop this server and shut down all kernels.
^CShutdown Notebook Server (y/[n])? y
[NotebookApp] Shutdown confirmed
[NotebookApp] Shutting down kernels
```

Seem explicit enough to me, and I don't have to press Ctrl+C twice. 

Sorry. Typo. Should be 0.13.1. It was tested on Window 7 64bit. 

Here is the doc. http://ipython.org/ipython-doc/rel-0.13/whatsnew/version0.13.html

Search for ctrl-c to find it.

I also use this on Mac OS X, it works fine. I got same response like what you got.

This issue is on my Windows 7 64.

On my windows 7 64 machine I do not have to press ctrl-c twice. But 
there is a delay of 5s - 10s before anything happens, even the printing 
of the message "Interrupted..."


Resolving patch:
diff --git a/IPython/html/notebookapp.py b/IPython/html/notebookapp.py
--- a/IPython/html/notebookapp.py
+++ b/IPython/html/notebookapp.py
@@ -714,7 +714,7 @@ def start(self):
                                       self.base_project_url)
         for line in self.notebook_info().split("\n"):
             info(line)
-        info("Use Control-C to stop this server and shut down all kernels.")
+        info("Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).")
 
         if self.open_browser or self.file_to_run:
             ip = self.ip or LOCALHOST


Test patch:
Repository: ipython/ipython

Issue:
IPython 0.13.1 ignoring $PYTHONSTARTUP
IPython is ignoring the `$PYTHONSTARTUP` environment variable.

`$HOME/.pythonrc.py`:

``` python
print 'hello?'
```

```
$ PYTHONSTARTUP=$HOME/.pythonrc.py ipython
Python 2.7.3 (default, Nov 29 2012, 15:33:55) 
Type "copyright", "credits" or "license" for more information.

IPython 0.13.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: 
```

```
$ PYTHONSTARTUP=$HOME/.pythonrc.py python
Python 2.7.3 (default, Nov 29 2012, 15:33:55) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
hello?
>>> 
```



Discussion:
See also discussion on #2655, which was about tests.

IPython has its own methods for running things at startup - see `IPYTHONDIR/profile_default/startup/`. I'm not sure whether we should also support `$PYTHONSTARTUP`. If you want to make a pull request - which would speed up the question, but not guarantee we'd agree - a good place to start looking is here: https://github.com/ipython/ipython/blob/master/IPython/core/shellapp.py#L231

`IPYTHONDIR/profile_default/startup/` works fine for me. Are there any potential downsides to just executing `$PYTHONSTARTUP` from there?

``` python
import os

if os.environ['PYTHONSTARTUP']:
    execfile(os.environ['PYTHONSTARTUP'])
```

This seems to work, and if there aren't any problems with that, I'm perfectly content.

That should be fine (although if you try to use IPython on Python 3, you'll probably see an error as it fails to find execfile, but that's easily worked around). It's just a question of whether we build something like that in by default.

This looks resolved, shall we close?

@minrk : The only question is whether we should run $PYTHONSTARTUP by default. It might be least-surprise if someone uses it for e.g. `from __future__ import division`.


Resolving patch:
diff --git a/IPython/core/shellapp.py b/IPython/core/shellapp.py
--- a/IPython/core/shellapp.py
+++ b/IPython/core/shellapp.py
@@ -300,7 +300,10 @@ def _exec_file(self, fname):
     def _run_startup_files(self):
         """Run files from profile startup directory"""
         startup_dir = self.profile_dir.startup_dir
-        startup_files = glob.glob(os.path.join(startup_dir, '*.py'))
+        startup_files = []
+        if os.environ.get('PYTHONSTARTUP', False):
+            startup_files.append(os.environ['PYTHONSTARTUP'])
+        startup_files += glob.glob(os.path.join(startup_dir, '*.py'))
         startup_files += glob.glob(os.path.join(startup_dir, '*.ipy'))
         if not startup_files:
             return


Test patch:
Repository: ipython/ipython

Issue:
If you don't have markdown, python setup.py install says no pygments
When installing ipython 1.0dev without markdown installed, you get an error message that pygments cannot be found. This is due to a typo in setupext/setupext.py line 100. 

``` python
def check_for_markdown():
    try:
        import markdown
    except ImportError:
        print_status('pygments', "Not found (required for nbconvert)")
        return False
    else:
        print_status('markdown', markdown.version)
        return True
```

Note the error says pygments instead of markdown. This is quite confusing when you are installing with pygments but not markdown. Please fix the typo. 



Discussion:
thanks for the report @lyonsquark. @minrk recently committed a change which removes the markdown dependency, so we'll just remove that check altogether


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -278,7 +278,7 @@ def run(self):
         doc = 'Sphinx>=0.3',
         test = 'nose>=0.10.1',
         notebook = ['tornado>=2.0', 'pyzmq>=2.1.11', 'jinja2'],
-        nbconvert = ['pygments', 'markdown', 'jinja2', 'Sphinx>=0.3']
+        nbconvert = ['pygments', 'jinja2', 'Sphinx>=0.3']
     )
     requires = setup_args.setdefault('install_requires', [])
     setupext.display_status = False
diff --git a/setupbase.py b/setupbase.py
--- a/setupbase.py
+++ b/setupbase.py
@@ -355,7 +355,7 @@ def check_for_dependencies():
         check_for_sphinx, check_for_pygments,
         check_for_nose, check_for_pexpect,
         check_for_pyzmq, check_for_readline,
-        check_for_jinja2, check_for_markdown
+        check_for_jinja2
     )
     print_line()
     print_raw("BUILDING IPYTHON")
@@ -374,7 +374,6 @@ def check_for_dependencies():
     check_for_pyzmq()
     check_for_readline()
     check_for_jinja2()
-    check_for_markdown()
 
 #---------------------------------------------------------------------------
 # VCS related
diff --git a/setupext/setupext.py b/setupext/setupext.py
--- a/setupext/setupext.py
+++ b/setupext/setupext.py
@@ -93,16 +93,6 @@ def check_for_jinja2():
         print_status('jinja2', jinja2.__version__)
         return True
 
-def check_for_markdown():
-    try:
-        import markdown
-    except ImportError:
-        print_status('pygments', "Not found (required for nbconvert)")
-        return False
-    else:
-        print_status('markdown', markdown.version)
-        return True
-
 def check_for_nose():
     try:
         import nose


Test patch:
Repository: ipython/ipython

Issue:
setp() issue in ipython notebook with figure references
In IPython notebook, when I run `setp()` to change parameters of a figure created in another cell and accessed with its reference, an exception occurs

``` python
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-82-54a641ac28e1> in <module>()
----> 1 setp(axis.lines[0], linewidth=2)

/home/amir/virtualenv/cr/local/lib/python2.7/site-packages/matplotlib/pyplot.pyc in setp(*args, **kwargs)
    238 def setp(*args, **kwargs):
    239     ret = _setp(*args, **kwargs)
--> 240     draw_if_interactive()
    241     return ret
    242 

/home/amir/virtualenv/cr/local/lib/python2.7/site-packages/IPython/zmq/pylab/backend_inline.py in draw_if_interactive()
    123     # flush_figures() will act upon these values
    124 
--> 125     fig = Gcf.get_active().canvas.figure
    126 
    127     # Hack: matplotlib FigureManager objects in interacive backends (at least

AttributeError: 'NoneType' object has no attribute 'canvas'
```

Nevertheless, `setp()` successfully does its job but since IPython notebook by default closes the figures of previous cells the exception occurs.



Discussion:
can you provide an example notebook of this behavior?

also, how what do you mean by "set() successfully does its job"?

Here's a notebook which demonstrates what I said. I am not sure how to send a file here so I uploaded it elsewhere and here's the link http://goo.gl/HQf5e

> also, how what do you mean by "set() successfully does its job"?

I mean `setp()` does in fact change the figure parameters and the exception happens during the redrawing of the figure


Resolving patch:
diff --git a/IPython/kernel/zmq/pylab/backend_inline.py b/IPython/kernel/zmq/pylab/backend_inline.py
--- a/IPython/kernel/zmq/pylab/backend_inline.py
+++ b/IPython/kernel/zmq/pylab/backend_inline.py
@@ -122,8 +122,10 @@ def draw_if_interactive():
     # execution.  Also sets the _draw_called flag, signaling that there will be
     # something to send.  At the end of the code execution, a separate call to
     # flush_figures() will act upon these values
-
-    fig = Gcf.get_active().canvas.figure
+    manager = Gcf.get_active()
+    if manager is None:
+        return
+    fig = manager.canvas.figure
 
     # Hack: matplotlib FigureManager objects in interacive backends (at least
     # in some of them) monkeypatch the figure object and add a .show() method


Test patch:
Repository: ipython/ipython

Issue:
get_dict() error
get_dict() doesn't return the expected {engine_id: result} dictionary when the AsyncResult is associated with a single engine.

``` python
from IPython.parallel import Client

rc = Client()
rc.ids # [0]

r = rc.load_balanced_view().apply_async(eval, '(1, 2, 3)')

r.get() # (1, 2, 3)
r.get_dict() # {0: 1}
# {0: (1, 2, 3)} was expected
```



Discussion:
can you add more details? this is pretty cryptic

Wow, I didn't expect you to read this so fast! Here are the details.

pinging @minrk since this involves parallel


Resolving patch:
diff --git a/IPython/parallel/client/asyncresult.py b/IPython/parallel/client/asyncresult.py
--- a/IPython/parallel/client/asyncresult.py
+++ b/IPython/parallel/client/asyncresult.py
@@ -191,14 +191,21 @@ def get_dict(self, timeout=-1):
         """
 
         results = self.get(timeout)
+        if self._single_result:
+            results = [results]
         engine_ids = [ md['engine_id'] for md in self._metadata ]
-        bycount = sorted(engine_ids, key=lambda k: engine_ids.count(k))
-        maxcount = bycount.count(bycount[-1])
-        if maxcount > 1:
-            raise ValueError("Cannot build dict, %i jobs ran on engine #%i"%(
-                    maxcount, bycount[-1]))
+        
+        
+        rdict = {}
+        for engine_id, result in zip(engine_ids, results):
+            if engine_id in rdict:
+                raise ValueError("Cannot build dict, %i jobs ran on engine #%i" % (
+                    engine_ids.count(engine_id), engine_id)
+                )
+            else:
+                rdict[engine_id] = result
 
-        return dict(zip(engine_ids,results))
+        return rdict
 
     @property
     def result(self):


Test patch:
diff --git a/IPython/parallel/tests/test_asyncresult.py b/IPython/parallel/tests/test_asyncresult.py
--- a/IPython/parallel/tests/test_asyncresult.py
+++ b/IPython/parallel/tests/test_asyncresult.py
@@ -35,6 +35,9 @@ def wait(n):
     time.sleep(n)
     return n
 
+def echo(x):
+    return x
+
 class AsyncResultTest(ClusterTestCase):
 
     def test_single_result_view(self):
@@ -77,6 +80,20 @@ def test_get_dict(self):
         for eid,r in d.iteritems():
             self.assertEqual(r, 5)
     
+    def test_get_dict_single(self):
+        view = self.client[-1]
+        for v in (range(5), 5, ('abc', 'def'), 'string'):
+            ar = view.apply_async(echo, v)
+            self.assertEqual(ar.get(), v)
+            d = ar.get_dict()
+            self.assertEqual(d, {view.targets : v})
+    
+    def test_get_dict_bad(self):
+        ar = self.client[:].apply_async(lambda : 5)
+        ar2 = self.client[:].apply_async(lambda : 5)
+        ar = self.client.get_result(ar.msg_ids + ar2.msg_ids)
+        self.assertRaises(ValueError, ar.get_dict)
+    
     def test_list_amr(self):
         ar = self.client.load_balanced_view().map_async(wait, [0.1]*5)
         rlist = list(ar)
Repository: ipython/ipython

Issue:
AttributeError: 'BlockingKernelClient' object has no attribute 'started_channels'
I have an app that is centered around IPython running in qt (https://github.com/neuropy/neuropy/blob/master/neuropy/main.py). Yesterday I updated IPython from git, and have had to change a few things since the refactoring about 3 months ago, which split a kernel client off of the kernel manager (see #3011). In the process, I came across the error in the title. This error only happens when I try to create a normal two-process app, but not when creating an inprocess app, ie, it happens with QtKernelManager, but not with QtInProcessKernelManager. I think a BlockingKernelClient happens to be the default for QtKernelClient, which may be due to #3222. Not sure how to fix this in IPython, but to get around it, I set the client_factory to QtKernelClient, and then calling QtKernelManager.client() works fine. My minimalist example is in this gist: https://gist.github.com/mspacek/6018206

Can this be fixed so that setting up the 2-process app doesn't require the extra step of changing the client_factory?



Discussion:
pinging @minrk who did the refactor


Resolving patch:
diff --git a/IPython/qt/manager.py b/IPython/qt/manager.py
--- a/IPython/qt/manager.py
+++ b/IPython/qt/manager.py
@@ -4,7 +4,7 @@
 from IPython.external.qt import QtCore
 
 # Local imports
-from IPython.utils.traitlets import Bool
+from IPython.utils.traitlets import Bool, DottedObjectName
 
 from IPython.kernel import KernelManager
 from IPython.kernel.restarter import KernelRestarter
@@ -30,6 +30,7 @@ def poll(self):
 class QtKernelManager(KernelManager, QtKernelManagerMixin):
     """A KernelManager with Qt signals for restart"""
 
+    client_class = DottedObjectName('IPython.qt.client.QtKernelClient')
     autorestart = Bool(True, config=True)
 
     def start_restarter(self):


Test patch:
Repository: ipython/ipython

Issue:
note new dependencies in docs / setup.py
nbconvert introduces a bunch of new optional dependencies.
- ~~markdown~~
- pandoc
- sphinx
- pygments (already needed for qtconsole, but should be on the nbconvert list as well)

And make sure everything else is up to date as well.



Discussion:
We should probably include a listing of the javascript components in the docs, even though they need not be installed separately.

you took care of markdown, so i updated the summary to reflect that


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -280,6 +280,14 @@ def run(self):
         notebook = ['tornado>=2.0', 'pyzmq>=2.1.11', 'jinja2'],
         nbconvert = ['pygments', 'jinja2', 'Sphinx>=0.3']
     )
+    everything = set()
+    for deps in setup_args['extras_require'].values():
+        if not isinstance(deps, list):
+            deps = [deps]
+        for dep in deps:
+            everything.add(dep)
+    setup_args['extras_require']['all'] = everything
+    
     requires = setup_args.setdefault('install_requires', [])
     setupext.display_status = False
     if not setupext.check_for_readline():


Test patch:
Repository: ipython/ipython

Issue:
nbconvert: unhelpful error when pandoc isn't installed
When running `ipy nbconvert foo.ipynb` without pandoc installed, the exception is:

```
  File "/Users/wolever/code/sandbox/env/sandbox/lib/python2.7/site-packages/IPython/nbconvert/filters/markdown.py", line 50, in markdown2latex
    return pandoc(source, 'markdown', 'latex')
  File "/Users/wolever/code/sandbox/env/sandbox/lib/python2.7/site-packages/IPython/nbconvert/utils/pandoc.py", line 51, in pandoc
    stdin=subprocess.PIPE, stdout=subprocess.PIPE
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1228, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@scipy.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    c.Application.verbose_crash=True
```

It would be useful if that included some hint that the error was being caused by the lack of pandoc.



Discussion:

Resolving patch:
diff --git a/IPython/nbconvert/utils/pandoc.py b/IPython/nbconvert/utils/pandoc.py
--- a/IPython/nbconvert/utils/pandoc.py
+++ b/IPython/nbconvert/utils/pandoc.py
@@ -47,9 +47,13 @@ def pandoc(source, fmt, to, extra_args=None, encoding='utf-8'):
     command = ['pandoc', '-f', fmt, '-t', to]
     if extra_args:
         command.extend(extra_args)
-    p = subprocess.Popen(command,
-                         stdin=subprocess.PIPE, stdout=subprocess.PIPE
-    )
+    try:
+        p = subprocess.Popen(command,
+                            stdin=subprocess.PIPE, stdout=subprocess.PIPE
+        )
+    except OSError:
+        sys.exit("ERROR: Unable to launch pandoc. Please install pandoc:\n"
+                 "(http://johnmacfarlane.net/pandoc/installing.html)")
     out, _ = p.communicate(cast_bytes(source, encoding))
     out = out.decode(encoding, 'replace')
     return out[:-1]


Test patch:
Repository: ipython/ipython

Issue:
Can not stop "ipython kernel" on windows
when running the "ipython kernel" command on windows I can not stop the kernel process. Ctrl-c does not stop the process like it does when using "ipython notebook". I have to kill the process manually using the process explorer.



Discussion:
Not windows specific, and also not so much a bug as an annoying feature.  If we allowed sigint to terminate a kernel, then interrupting it from the notebook or qtconsole would occasionally appear as a crash.

I am not sure if this is the same problem I have. I started a kernel with IPython.embed_kernel(),  and I cannot kill it. I'm using linux and ctrl + c does not work.

^C should not terminate the process, because ^C must be interpreted as a regular sigint and raise KeyboardInterrupt in user code.  We don't want ^C to kill the kernel, because then if a user tries to interrupt their own code, the kernel will die.  We used to allow ^C to kill the kernel while user code was not running, but this still allowed accidental kernel shutdown if you tried to interrupt your own code, but ended up sending the signal after your code finished.  The only sensible answer is for kernels to not be killed by ^C.

We could, however, change the `ipython kernel` entry point to, instead of launching the kernel directly, start a minimal KernelManager, which in turn starts the actual Kernel.  If we did this, then you could interrupt the KernelManager directly with ^C, which would in turn cleanup the kernel.

Is the only way to kill `ipython kernel` to send it a sigterm?

@pydave or ask it to shutdown from a frontend.

arg! i just spent a half hour trying to figure out where i should make some changes to make this work... :\


Resolving patch:
diff --git a/IPython/kernel/zmq/kernelapp.py b/IPython/kernel/zmq/kernelapp.py
--- a/IPython/kernel/zmq/kernelapp.py
+++ b/IPython/kernel/zmq/kernelapp.py
@@ -99,6 +99,16 @@
 kernel_aliases.update(session_aliases)
 kernel_flags.update(session_flags)
 
+_ctrl_c_message = """\
+NOTE: When using the `ipython kernel` entry point, Ctrl-C will not work.
+
+To exit, you will have to explicitly quit this process, by either sending
+"quit" from a client, or using Ctrl-\\ in UNIX-like environments.
+
+To read more about this, see https://github.com/ipython/ipython/issues/2049
+
+"""
+
 #-----------------------------------------------------------------------------
 # Application class for starting an IPython Kernel
 #-----------------------------------------------------------------------------
@@ -335,6 +345,7 @@ def log_connection_info(self):
             self.log.info(line)
         # also raw print to the terminal if no parent_handle (`ipython kernel`)
         if not self.parent_handle:
+            io.rprint(_ctrl_c_message)
             for line in lines:
                 io.rprint(line)
 


Test patch: