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

Issue:
notebook kernel dies if started with invalid parameter
current git head

ipython notebook --no-brow

after executing any cell in a notebook the kernel dies with

```
[IPKernelApp] Bad config encountered during initialization:
[IPKernelApp] Unrecognized flag: ' --no-brow'
```

seems to be related to that the parameter is the start of a valid one, completely wrong parameters (correctly) prevent the notebook from starting at all.



Discussion:
This is because argparse accepts any leading fraction of a flag to be specified, so `--no-brow` actually successfully specifed `--no-browser`, but the code that scrubs flags from the args to be relayed down to the Kernel does not do this, so `--no-brow` doesn't get scrubbed.  I don't know if there's a flag in argparse to disable this behavior. Anyone aware of one?


Resolving patch:
diff --git a/IPython/kernel/launcher.py b/IPython/kernel/launcher.py
--- a/IPython/kernel/launcher.py
+++ b/IPython/kernel/launcher.py
@@ -61,6 +61,8 @@ def swallow_argv(argv, aliases=None, flags=None):
     swallow_next = False
     was_flag = False
     for a in argv:
+        if a == '--':
+            break
         if swallow_next:
             swallow_next = False
             # last arg was an alias, remove the next one
@@ -71,16 +73,19 @@ def swallow_argv(argv, aliases=None, flags=None):
                 continue
         if a.startswith('-'):
             split = a.lstrip('-').split('=')
-            alias = split[0]
-            if alias in aliases:
+            name = split[0]
+            # we use startswith because argparse accepts any arg to be specified
+            # by any leading section, as long as it is unique,
+            # so `--no-br` means `--no-browser` in the notebook, etc.
+            if any(alias.startswith(name) for alias in aliases):
                 stripped.remove(a)
                 if len(split) == 1:
                     # alias passed with arg via space
                     swallow_next = True
                     # could have been a flag that matches an alias, e.g. `existing`
                     # in which case, we might not swallow the next arg
-                    was_flag = alias in flags
-            elif alias in flags and len(split) == 1:
+                    was_flag = name in flags
+            elif len(split) == 1 and any(flag.startswith(name) for flag in flags):
                 # strip flag, but don't swallow next, as flags don't take args
                 stripped.remove(a)
     


Test patch:
diff --git a/IPython/kernel/tests/test_launcher.py b/IPython/kernel/tests/test_launcher.py
--- a/IPython/kernel/tests/test_launcher.py
+++ b/IPython/kernel/tests/test_launcher.py
@@ -39,7 +39,7 @@ def test_swallow_argv():
         ([], ['-a', '5'], ['a'], None),
         ([], ['-a', '5'], ['a'], ['a']),
         ([], ['--foo'], None, ['foo']),
-        (['--foo'], ['--foo'], ['foobar'], []),
+        ([], ['--foo'], ['foobar'], []),
         ([], ['--foo', '5'], ['foo'], []),
         ([], ['--foo=5'], ['foo'], []),
         (['--foo=5'], ['--foo=5'], [], ['foo']),
Repository: ipython/ipython

Issue:
find_cmd test failure on Windows
I think this is caused by #3301. The [Windows implementation of find_cmd](https://github.com/ipython/ipython/blob/master/IPython/utils/_process_win32.py#L74) expects a command name without an extension, but the test now uses 'python.exe'.

I think that 'python.exe' is a valid command on Windows, so I think we should modify `find_cmd` to allow passing a command with an extension. Alternatively, we could modify the test to strip the extension.

```
======================================================================
ERROR: Make sure we find sys.exectable for python.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "S:\Users\slave\Jenkins\shiningpanda\jobs\d5f643a2\virtualenvs\ff035a1d\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "S:\Users\slave\Jenkins\shiningpanda\jobs\d5f643a2\virtualenvs\ff035a1d\lib\site-packages\ipython-1.0.dev-py2.7.egg\IPython\utils\tests\test_process.py", line 36, in test_find_cmd_python
    nt.assert_equal(find_cmd(python), sys.executable)
  File "S:\Users\slave\Jenkins\shiningpanda\jobs\d5f643a2\virtualenvs\ff035a1d\lib\site-packages\ipython-1.0.dev-py2.7.egg\IPython\utils\process.py", line 67, in find_cmd
    raise FindCmdError('command could not be found: %s' % cmd)
FindCmdError: command could not be found: python.exe
```



Discussion:

Resolving patch:
diff --git a/IPython/utils/_process_win32.py b/IPython/utils/_process_win32.py
--- a/IPython/utils/_process_win32.py
+++ b/IPython/utils/_process_win32.py
@@ -83,7 +83,7 @@ def _find_cmd(cmd):
         path = None
         for ext in extensions:
             try:
-                path = SearchPath(PATH, cmd + ext)[0]
+                path = SearchPath(PATH, cmd, ext)[0]
             except:
                 pass
         if path is None:


Test patch:
Repository: ipython/ipython

Issue:
ipcluster --version
Display:

```
0.0
```

While ipengine and ipcontroller display the right version (0.13.2 and master).



Discussion:

Resolving patch:
diff --git a/IPython/parallel/apps/ipclusterapp.py b/IPython/parallel/apps/ipclusterapp.py
--- a/IPython/parallel/apps/ipclusterapp.py
+++ b/IPython/parallel/apps/ipclusterapp.py
@@ -581,7 +581,7 @@ def start(self):
 
 base='IPython.parallel.apps.ipclusterapp.IPCluster'
 
-class IPClusterApp(Application):
+class IPClusterApp(BaseIPythonApplication):
     name = u'ipcluster'
     description = _description
     examples = _main_examples


Test patch:
Repository: ipython/ipython

Issue:
Setting log_format in config file results in error (and no format changes)
Setting c.NotebookApp.log_format results in an error. The culprit is line 168 in config/application.py:

``` python
_log_formatter = LevelFormatter(new, datefmt=self._log_datefmt)
```

Which should be:

``` python
_log_formatter = LevelFormatter(new, datefmt=self.log_datefmt)
```

with no underscore before "log_datefmt."



Discussion:

Resolving patch:
diff --git a/IPython/config/application.py b/IPython/config/application.py
--- a/IPython/config/application.py
+++ b/IPython/config/application.py
@@ -165,7 +165,7 @@ def _log_datefmt_changed(self, name, old, new):
     def _log_format_changed(self, name, old, new):
         """Change the log formatter when log_format is set."""
         _log_handler = self.log.handlers[0]
-        _log_formatter = LevelFormatter(new, datefmt=self._log_datefmt)
+        _log_formatter = LevelFormatter(new, datefmt=self.log_datefmt)
         _log_handler.setFormatter(_log_formatter)
 
     log = Instance(logging.Logger)


Test patch:
Repository: ipython/ipython

Issue:
Config not passed down to subcommands
Debugging a complex issue at Scipy, we ran into the fact that config manually passed in to `TerminalIPythonApp` doesn't get passed down to subcommands. The use case was overriding KernelManager.kernel_cmd to start notebook kernels in a Python interpreter running under Mono.

Adding a `config=self.config` to [this call](https://github.com/ipython/ipython/blob/master/IPython/config/application.py#L398) solved it for us - is that the right way to do it?



Discussion:
Seem like the correct fix for me as `subapp` seem to alway be of `Application` class ...


Resolving patch:
diff --git a/IPython/config/application.py b/IPython/config/application.py
--- a/IPython/config/application.py
+++ b/IPython/config/application.py
@@ -395,7 +395,7 @@ def initialize_subcommand(self, subc, argv=None):
         # clear existing instances
         self.__class__.clear_instance()
         # instantiate
-        self.subapp = subapp.instance()
+        self.subapp = subapp.instance(config=self.config)
         # and initialize subapp
         self.subapp.initialize(argv)
     


Test patch:
Repository: ipython/ipython

Issue:
%paste and %cpaste not removing "..." lines
Pasting doctest code that contains "..." lines raises a syntax error. Adding a space to replace such lines with "... " fixes the problem.

This makes pasting some code snippets very cumbersome (e.g. http://docs.sqlalchemy.org/en/rel_0_8/orm/tutorial.html#declare-a-mapping), as they have to be fixed before being pasted.

It would be nice if this were fixed.

(Observed with version 0.13.1 on Mac OS X).



Discussion:
try #2809 


Resolving patch:
diff --git a/IPython/core/inputtransformer.py b/IPython/core/inputtransformer.py
--- a/IPython/core/inputtransformer.py
+++ b/IPython/core/inputtransformer.py
@@ -381,7 +381,7 @@ def _strip_prompts(prompt_re):
 @CoroutineInputTransformer.wrap
 def classic_prompt():
     """Strip the >>>/... prompts of the Python interactive shell."""
-    prompt_re = re.compile(r'^(>>> |^\.\.\. )')
+    prompt_re = re.compile(r'^(>>> ?|^\.\.\. ?)')
     return _strip_prompts(prompt_re)
 
 @CoroutineInputTransformer.wrap


Test patch:
diff --git a/IPython/core/tests/test_inputtransformer.py b/IPython/core/tests/test_inputtransformer.py
--- a/IPython/core/tests/test_inputtransformer.py
+++ b/IPython/core/tests/test_inputtransformer.py
@@ -180,6 +180,10 @@ def transform_checker(tests, transformer, **kwargs):
           ('123','123'),
           ('... 456"""','... 456"""'),
           ],
+         [('>>> def f(x):', 'def f(x):'),
+          ('...', ''),
+          ('...     return x', '    return x'),
+          ],
         ],
 
        ipy_prompt =
Repository: ipython/ipython

Issue:
Remove pyreadline workarounds, we now require pyreadline >= 1.7.1
After #1301, on Windows we explicitly require pyreadline >= 1.7.1, so we can clean things up and remove workarounds we had in a few places that only mattered for 1.5 or 1.6.



Discussion:

Resolving patch:
diff --git a/IPython/utils/rlineimpl.py b/IPython/utils/rlineimpl.py
--- a/IPython/utils/rlineimpl.py
+++ b/IPython/utils/rlineimpl.py
@@ -56,18 +56,6 @@
     # cleanup dirty trick vars
     del dynload_idx, lib_dynload
 
-if have_readline and hasattr(_rl, 'rlmain'):
-    # patch add_history to allow for strings in pyreadline <= 1.5:
-    # fix copied from pyreadline 1.6
-    import pyreadline
-    if pyreadline.release.version <= '1.5':
-        def add_history(line):
-            """add a line to the history buffer."""
-            from pyreadline import lineobj
-            if not isinstance(line, lineobj.TextLine):
-                line = lineobj.TextLine(line)
-            return _rl.add_history(line)
-
 if (sys.platform == 'win32' or sys.platform == 'cli') and have_readline:
     try:
         _outputfile=_rl.GetOutputFile()


Test patch:
Repository: ipython/ipython

Issue:
unexpected keyword argument to remove_kernel
Another minor error we ran into while debugging, when a kernel crashed:

```
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/IPython/kernel/restarter.py", line 85, in _fire_callbacks
    callback()
  File "/usr/local/lib/python2.7/dist-packages/IPython/frontend/html/notebook/services/kernels/kernelmanager.py", line 92, in <lambda>
    lambda : self._handle_kernel_died(kernel_id),
  File "/usr/local/lib/python2.7/dist-packages/IPython/frontend/html/notebook/services/kernels/kernelmanager.py", line 71, in _handle_kernel_died
    self.remove_kernel(kernel_id, now=True)
TypeError: remove_kernel() got an unexpected keyword argument 'now'
```



Discussion:

Resolving patch:
diff --git a/IPython/html/services/kernels/kernelmanager.py b/IPython/html/services/kernels/kernelmanager.py
--- a/IPython/html/services/kernels/kernelmanager.py
+++ b/IPython/html/services/kernels/kernelmanager.py
@@ -68,7 +68,7 @@ def _handle_kernel_died(self, kernel_id):
         """notice that a kernel died"""
         self.log.warn("Kernel %s died, removing from map.", kernel_id)
         self.delete_mapping_for_kernel(kernel_id)
-        self.remove_kernel(kernel_id, now=True)
+        self.remove_kernel(kernel_id)
 
     def start_kernel(self, notebook_id=None, **kwargs):
         """Start a kernel for a notebook an return its kernel_id.


Test patch:
Repository: ipython/ipython

Issue:
documentation build broken in head
commit 0c0c1a161c84109 broke the documentation build:

```
HOME=$PWD/build PYTHONPATH=$PWD make -C docs html
...
  File "/usr/lib/python2.7/dist-packages/sphinx/util/__init__.py", line 201, in get_module_source
    loader = getattr(mod, '__loader__', None)
  File "/home/jtaylor/Packages/ipython/ipython/IPython/frontend.py", line 68, in __getattr__
    raise ImportError('No module named %s' % obj)
ImportError: No module named __loader__
```



Discussion:
@ivanov, you were looking at improving the frontend.py shim. Did that get anywhere?


Resolving patch:
diff --git a/docs/autogen_api.py b/docs/autogen_api.py
--- a/docs/autogen_api.py
+++ b/docs/autogen_api.py
@@ -45,6 +45,7 @@
                                         r'\.ipdoctest',
                                         r'\.Gnuplot',
                                         r'\.frontend\.process\.winprocess',
+                                        r'\.frontend',
                                         r'\.Shell',
                                         ]
     


Test patch:
Repository: ipython/ipython

Issue:
base_url and static path
Static path in template does not use the base_project_url.

Which seem to work, but tornado is still serving static resources in `/static/` instead of `/$base_url/static`

I will promote this to high as this prevent running ipython in parallel with other webapp. 



Discussion:
So if I understand it correctly, one should add `$base_project_url` to all paths of files which are included in `/static/` directory, right?

Yes, pr #2723 should fix it i forgot to mension the issue.
I'm still wondering if we shouln't have even a possible different prefix for static resoures...


Resolving patch:
diff --git a/IPython/html/notebookapp.py b/IPython/html/notebookapp.py
--- a/IPython/html/notebookapp.py
+++ b/IPython/html/notebookapp.py
@@ -466,7 +466,8 @@ def _mathjax_url_default(self):
         if not self.enable_mathjax:
             return u''
         static_url_prefix = self.webapp_settings.get("static_url_prefix",
-                                                     "/static/")
+                         url_path_join(self.base_project_url, "static")
+        )
         try:
             mathjax = filefind(os.path.join('mathjax', 'MathJax.js'), self.static_file_path)
         except IOError:
@@ -481,7 +482,7 @@ def _mathjax_url_default(self):
             return url
         else:
             self.log.info("Using local MathJax from %s" % mathjax)
-            return static_url_prefix+u"mathjax/MathJax.js"
+            return url_path_join(static_url_prefix, u"mathjax/MathJax.js")
     
     def _mathjax_url_changed(self, name, old, new):
         if new and not self.enable_mathjax:


Test patch:
Repository: ipython/ipython

Issue:
Online help utility broken in QtConsole
Whatever I type in online help utility (started in QtConsole), I get help on unicode object,

```
Python 2.7.2 (default, Nov 21 2011, 17:25:27) 
Type "copyright", "credits" or "license" for more information.

IPython 0.12.beta -- 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.
%guiref   -> A brief reference about the graphical user interface.

In [1]: help()

Welcome to Python 2.7!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".


help> topics
Help on unicode object:

class unicode(basestring)
 |  unicode(string [, encoding[, errors]]) -> object
 |  
 |  Create a new Unicode object from the given encoded string.
 |  encoding defaults to the current default string encoding.
 |  errors can be 'strict', 'replace' or 'ignore' and defaults to 'strict'.
 |  
 |  Method resolution order:
 |      unicode
 |      basestring
 |      object
 |  
 |  Methods defined here:
 |  
 |  __add__(...)
 |      x.__add__(y) <==> x+y
 |  
 |  __contains__(...)
 |      x.__contains__(y) <==> y in x

etc ...
```



Discussion:
Presumably due to the fact that our raw_input wrapper that forwards the request to the qtconsole returns unicode instead of a bytestring, like the builtin one.  We should probably fix this.

This is precisely the difference between doing `help('topics')` and `help(u'topics')`.


Resolving patch:
diff --git a/IPython/kernel/zmq/ipkernel.py b/IPython/kernel/zmq/ipkernel.py
--- a/IPython/kernel/zmq/ipkernel.py
+++ b/IPython/kernel/zmq/ipkernel.py
@@ -770,7 +770,7 @@ def _raw_input(self, prompt, ident, parent):
             else:
                 break
         try:
-            value = reply['content']['value']
+            value = py3compat.unicode_to_str(reply['content']['value'])
         except:
             self.log.error("Got bad raw_input reply: ")
             self.log.error("%s", parent)


Test patch:
Repository: ipython/ipython

Issue:
nbconvert incompatible with Windows?
This is just speculation, but the way pathnames are defined in `IPython/nbconvert/exporters/exporter.py` looks like it will cause problems on windows systems.  `os.path.join` should be used in favor of hard-coded paths.

I don't have a windows machine to test this out on, though.



Discussion:

Resolving patch:
diff --git a/IPython/nbconvert/exporters/exporter.py b/IPython/nbconvert/exporters/exporter.py
--- a/IPython/nbconvert/exporters/exporter.py
+++ b/IPython/nbconvert/exporters/exporter.py
@@ -93,11 +93,11 @@ class Exporter(Configurable):
         )
 
     template_path = Unicode(
-        "/../templates/", config=True,
+        os.path.join("..", "templates"), config=True,
         help="Path where the template files are located.")
 
     template_skeleton_path = Unicode(
-        "/../templates/skeleton/", config=True,
+        os.path.join("..", "templates", "skeleton"), config=True,
         help="Path where the template skeleton files are located.") 
 
     #Jinja block definitions
@@ -288,11 +288,11 @@ def _init_environment(self):
         """
         Create the Jinja templating environment.
         """
-        
+        here = os.path.realpath(__file__)
         self.environment = Environment(
             loader=FileSystemLoader([
-                os.path.dirname(os.path.realpath(__file__)) + self.template_path,
-                os.path.dirname(os.path.realpath(__file__)) + self.template_skeleton_path,
+                os.path.join(here, self.template_path),
+                os.path.join(here, self.template_skeleton_path),
                 ]),
             extensions=JINJA_EXTENSIONS
             )


Test patch:
Repository: ipython/ipython

Issue:
cython magic fail if cache dir is deleted while in session
```
In [1]: %load_ext cythonmagic

In [2]: %%cython
cimport cython
   ...: 

In [3]: rm -rf /home/jtaylor/.config/ipython/cython/

In [4]: %%cython                                    
cimport cython

CompileError: command 'x86_64-linux-gnu-gcc' failed with exit status 1
```

the command issued is:

```
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7 -c /home/jtaylor/.config/ipython/cython/_cython_magic_d37c0b24f28dfb69270e82105a4c2e8e.c -o /home/jtaylor/.config/ipython/cython/home/jtaylor/.config/ipython/cython/_cython_magic_d37c0b24f28dfb69270e82105a4c2e8e.o
Fatal error: can't create /home/jtaylor/.config/ipython/cython/home/jtaylor/.config/ipython/cython/_cython_magic_d37c0b24f28dfb69270e82105a4c2e8e.o: No such file or directory

```

the problematic part is this long path which is not recreated before trying to compile into it:

```
/home/jtaylor/.config/ipython/cython/home/jtaylor/.config/ipython/cython/
```



Discussion:
closed by e9458887e39eb82db7dec8a61eac91cae417d0bc

I can still reproduce it with current git head, note that with that commit you have to delete ~/.cache/ipython/cython/

Gotcha, I must have done something wrong in testing.  Thanks for checking.

I tracked this down to a bug  in distutils, where its `mkpath` utility will only ever create a particular path once,
and assume that it still exists forever after for the lifetime of the process.  I can make a workaround, but it might be gross.


Resolving patch:
diff --git a/IPython/extensions/cythonmagic.py b/IPython/extensions/cythonmagic.py
--- a/IPython/extensions/cythonmagic.py
+++ b/IPython/extensions/cythonmagic.py
@@ -278,7 +278,20 @@ def so_ext(self):
             self._so_ext = self._get_build_extension().get_ext_filename('')
             return self._so_ext
 
+    def _clear_distutils_mkpath_cache(self):
+        """clear distutils mkpath cache
+        
+        prevents distutils from skipping re-creation of dirs that have been removed
+        """
+        try:
+            from distutils.dir_util import _path_created
+        except ImportError:
+            pass
+        else:
+            _path_created.clear()
+    
     def _get_build_extension(self):
+        self._clear_distutils_mkpath_cache()
         dist = Distribution()
         config_files = dist.find_config_files()
         try:


Test patch: