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

Issue:
Error "$XONSH_TRACEBACK_LOGFILE must be a filepath..."
<!--- Provide a general summary of the issue in the Title above -->

When I set the track back log file I get the error message 

    xonsh: $XONSH_TRACEBACK_LOGFILE must be a filepath pointing to a file that either exists and is writable or that can be created.

despite the fact that I just was able to create that file via `touch` in the calling shell.

## xonfig

```
+------------------+---------------------------------+
| xonsh            | 0.8.1                           |
| Git SHA          | 23246604                        |
| Commit Date      | Oct 18 09:55:19 2018            |
| Python           | 3.6.4                           |
| PLY              | 3.9                             |
| have readline    | True                            |
| prompt toolkit   | 2.0.7                           |
| shell type       | readline                        |
| pygments         | None                            |
| on posix         | True                            |
| on linux         | True                            |
| distro           | Red Hat Enterprise Linux Server |
| on darwin        | False                           |
| on windows       | False                           |
| on cygwin        | False                           |
| on msys2         | False                           |
| is superuser     | False                           |
| default encoding | utf-8                           |
| xonsh encoding   | utf-8                           |
| encoding errors  | surrogateescape                 |
+------------------+---------------------------------+
```

## Expected Behavior

The file path is accepted

<!--- Tell us what should happen -->

## Current Behavior

The file path is not accepted and the error is printed

## Steps to Reproduce

Try the following .xonshrc file:

```
from pathlib import Path

$XONSH_SHOW_TRACEBACK = False
$XONSH_TRACEBACK_LOGFILE = Path($XONSH_DATA_DIR).joinpath('traceback.log')
```


Discussion:
I just tested it on macOS - and I get the same error as on RHEL
The error message is unfortunately misleading. `$XONSH_TRACEBACK_LOGFILE` should be a string. This should work:
```
$XONSH_TRACEBACK_LOGFILE = str(Path($XONSH_DATA_DIR).joinpath('traceback.log'))
```
A PR to make it accept path-like objects would be very welcome. 

Resolving patch:
diff --git a/xonsh/tools.py b/xonsh/tools.py
--- a/xonsh/tools.py
+++ b/xonsh/tools.py
@@ -1169,6 +1169,11 @@ def to_logfile_opt(x):
     the filepath if it is a writable file or None if the filepath is not
     valid, informing the user on stderr about the invalid choice.
     """
+    superclass = pathlib.PurePath
+    if PYTHON_VERSION_INFO >= (3, 6, 0):
+        superclass = os.PathLike
+    if isinstance(x, superclass):
+        x = str(x)
     if is_logfile_opt(x):
         return x
     else:


Test patch:
Repository: xonsh/xonsh

Issue:
An extra newline character gets printed in Python mode
## xonfig
```
+------------------+----------------------+
| xonsh            | 0.8.2                |
| Git SHA          | 6159f449             |
| Commit Date      | Sep 21 02:39:43 2018 |
| Python           | 3.7.1                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 2.0.4                |
| shell type       | prompt_toolkit2      |
| pygments         | 2.2.0                |
| on posix         | True                 |
| on linux         | True                 |
| distro           | arch                 |
| on darwin        | False                |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
+------------------+----------------------+
```
## Expected Behavior
Prompt should be rendered immediately after the last command's output.

## Current Behavior
PTK2 shell adds an extra newline to the output of commands executed in Python mode.

## Steps to Reproduce
```
laloch@uriel ~ $ echo @(1+1)
2
laloch@uriel ~ $ 1+1
2

laloch@uriel ~ $
```


Discussion:
If I understood him right, @scopatz suggested that the extra newline gets there from
https://github.com/xonsh/xonsh/blob/dca4a477150b55a7011078daba9da8bb0e95ceae/xonsh/base_shell.py#L382, but no, unfortunately that's not the case.
The extra EOL seems to be printed from within `exec()` call in codecache.py:run_compiled_code(). If I replace the call at [line 67](https://github.com/xonsh/xonsh/blob/f409a020387c6e73a58fbac5191675f0d519591e/xonsh/codecache.py#L67) by
```
    print("<")
    func(code, glb, loc)
    print(">")
```
I get
from `xonsh --shell-type=rl --no-rc`:
```
$ 1+1
<
2
>
$
```
from `xonsh --shell-type=ptk2 --no-rc`:
```
$ 1+1
<
2

>
$
```

Resolving patch:
diff --git a/xonsh/main.py b/xonsh/main.py
--- a/xonsh/main.py
+++ b/xonsh/main.py
@@ -257,7 +257,8 @@ def _pprint_displayhook(value):
         printed_val = repr(value)
     if HAS_PYGMENTS and env.get("COLOR_RESULTS"):
         tokens = list(pygments.lex(printed_val, lexer=pyghooks.XonshLexer()))
-        print_color(tokens)
+        end = "" if env.get("SHELL_TYPE") == "prompt_toolkit2" else "\n"
+        print_color(tokens, end=end)
     else:
         print(printed_val)  # black & white case
     builtins._ = value


Test patch:
Repository: xonsh/xonsh

Issue:
No exception raised when using cd to change dir to a non existent directory 
I have this xonsh script:

```
$RAISE_SUBPROC_ERROR = True

try:
    cd blaat

    r = !(cd blaat)
    print(r.returncode)

    r = !(cd /home)
    print(r.returncode)


except:
    print("cd failed")

```

The folder 'blaat' does not exist so it should print "cd failed". However the output is:

> cd: no such file or directory: blaat
> cd: no such file or directory: blaat
> 1
> 0

## xonfig
+------------------+---------------------+
| xonsh            | 0.8.4               |
| Git SHA          | 8405b8dd            |
| Commit Date      | Dec 7 10:39:36 2018 |
| Python           | 3.6.2               |
| PLY              | 3.11                |
| have readline    | True                |
| prompt toolkit   | 1.0.15              |
| shell type       | prompt_toolkit1     |
| pygments         | 2.2.0               |
| on posix         | True                |
| on linux         | True                |
| distro           | debian              |
| on darwin        | False               |
| on windows       | False               |
| on cygwin        | False               |
| on msys2         | False               |
| is superuser     | False               |
| default encoding | utf-8               |
| xonsh encoding   | utf-8               |
| encoding errors  | surrogateescape     |
+------------------+---------------------+



Discussion:
Thanks for reporting! This should be an easy fix!

Resolving patch:
diff --git a/xonsh/proc.py b/xonsh/proc.py
--- a/xonsh/proc.py
+++ b/xonsh/proc.py
@@ -2247,13 +2247,12 @@ def _raise_subproc_error(self):
         spec = self.spec
         rtn = self.returncode
         if (
-            not spec.is_proxy
-            and rtn is not None
+            rtn is not None
             and rtn > 0
             and builtins.__xonsh__.env.get("RAISE_SUBPROC_ERROR")
         ):
             try:
-                raise subprocess.CalledProcessError(rtn, spec.cmd, output=self.output)
+                raise subprocess.CalledProcessError(rtn, spec.args, output=self.output)
             finally:
                 # this is need to get a working terminal in interactive mode
                 self._return_terminal()


Test patch:
diff --git a/tests/test_integrations.py b/tests/test_integrations.py
--- a/tests/test_integrations.py
+++ b/tests/test_integrations.py
@@ -52,7 +52,7 @@ def run_xonsh(cmd, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.STDOUT):
     env["PATH"] = PATH
     env["XONSH_DEBUG"] = "1"
     env["XONSH_SHOW_TRACEBACK"] = "1"
-    env["RAISE_SUBPROC_ERROR"] = "1"
+    env["RAISE_SUBPROC_ERROR"] = "0"
     env["PROMPT"] = ""
     xonsh = "xonsh.bat" if ON_WINDOWS else "xon.sh"
     xonsh = shutil.which(xonsh, path=PATH)
Repository: xonsh/xonsh

Issue:
XONSH_STORE_STDOUT=True causes some commands to hang

## xonfig
```
+------------------+----------------------+
| xonsh            | 0.8.8                |
| Git SHA          | 47585920             |
| Commit Date      | Jan 30 12:30:54 2019 |
| Python           | 3.7.2                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 2.0.7                |
| shell type       | prompt_toolkit2      |
| pygments         | 2.3.1                |
| on posix         | True                 |
| on linux         | True                 |
| distro           | arch                 |
| on darwin        | False                |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
+------------------+----------------------+
```

## Expected Behavior
Xonsh shouldn't hang

## Current Behavior
xonsh hangs

## Steps to Reproduce
1. Put this in `rc.xsh`:
```
$XONSH_STORE_STDOUT = True
```
2. run `xonsh`
3. run `cat` command

Might be related to #2965 and some other issues.


Discussion:

Resolving patch:
diff --git a/xonsh/built_ins.py b/xonsh/built_ins.py
--- a/xonsh/built_ins.py
+++ b/xonsh/built_ins.py
@@ -905,6 +905,12 @@ def run_subproc(cmds, captured=False):
     if _should_set_title(captured=captured):
         # set title here to get currently executing command
         pause_call_resume(proc, builtins.__xonsh__.shell.settitle)
+    else:
+        # for some reason, some programs are in a stopped state when the flow
+        # reaches this point, hence a SIGCONT should be sent to `proc` to make
+        # sure that the shell doesn't hang. This `pause_call_resume` invocation
+        # does this
+        pause_call_resume(proc, int)
     # create command or return if backgrounding.
     if background:
         return


Test patch:
Repository: xonsh/xonsh

Issue:
Exception on startup (pygments_cache)
<!--- Provide a general summary of the issue in the Title above -->
<!--- If you have a question along the lines of "How do I do this Bash command in xonsh"
please first look over the Bash to Xonsh translation guide: http://xon.sh/bash_to_xsh.html
If you don't find an answer there, please do open an issue! -->

## xonfig
<!--- Please post the output of the `xonfig` command (run from inside xonsh) so we know more about your current setup -->

## Expected Behavior
<!--- Tell us what should happen -->

## Current Behavior
<!--- Tell us what happens instead of the expected behavior -->
<!--- If part of your bug report is a traceback, please first enter debug mode before triggering the error
To enter debug mode, set the environment variable `XONSH_DEBUG=1` _before_ starting `xonsh`.  
On Linux and OSX, an easy way to to do this is to run `env XONSH_DEBUG=1 xonsh` -->

## Steps to Reproduce
<!--- Please try to write out a minimal reproducible snippet to trigger the bug, it will help us fix it! -->



Discussion:
I ran into the issue #2692 (which has been closed) on Fedora 29 with Xonsh 0.8.3
I don't have the problem on Manjaro nor on Ubuntu.
@dugres 

There was a reversion.
Manually opening ```"PATH/TO/PYTHON/site-packages/xonsh/ptk2/__init__.py"```
and commenting averything in the file fixed it for me. (I basically read what was in the PR that solved the issue previously and looked at what was done).

@matheus2740 

That worked for me too. Thanks

That brings up 2 questions though:
 - Why #2692 hasn't been merged ?
 - Why the issue only appears on Fedora ?

I think it was merged, but the PR I read only changed the ```(..)/ptk/__init__.py``` file, while the ```(..)/ptk2/__init__.py``` (note the 2) still remained problematic (or it was added after the PR fix was merged).

Resolving patch:
diff --git a/xonsh/ptk2/__init__.py b/xonsh/ptk2/__init__.py
--- a/xonsh/ptk2/__init__.py
+++ b/xonsh/ptk2/__init__.py
@@ -1,8 +0,0 @@
-# must come before ptk / pygments imports
-from xonsh.lazyasd import load_module_in_background
-
-load_module_in_background(
-    "pkg_resources",
-    debug="XONSH_DEBUG",
-    replacements={"pygments.plugin": "pkg_resources"},
-)


Test patch:
Repository: xonsh/xonsh

Issue:
Garbage collection command fails because of msising `gc_units_to_rmfiles`
Here is my shell session:
```
┌─18-12:44[confus@confusion6 ~]                                                    
└$ xonfig info                                                                  
+------------------+----------------------+
| xonsh            | 0.9.3                |
| Git SHA          | 679d4e06             |
| Commit Date      | May 14 17:45:24 2019 |
| Python           | 3.6.7                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 2.0.9                |
| shell type       | prompt_toolkit2      |
| pygments         | 2.4.0                |
| on posix         | True                 |
| on linux         | True                 |
| distro           | ubuntu               |
| on darwin        | False                |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
+------------------+----------------------+

┌─18-12:46[confus@confusion6 ~]                                                    
└$ history gc                                                                   
Exception in thread Thread-451:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/jan/.local/lib/python3.6/site-packages/xonsh/history/__amalgam__.py", line 352, in run
    rmfiles_fn = self.gc_units_to_rmfiles.get(units)
AttributeError: 'JsonHistoryGC' object has no attribute 'gc_units_to_rmfiles'
```
I'm not nearly deep enough into xonsh to make sense of it.


Discussion:
Oh interesting.  Thanks for bringing this up.  This seems like a bug. I can reproduce.

Resolving patch:
diff --git a/xonsh/history/json.py b/xonsh/history/json.py
--- a/xonsh/history/json.py
+++ b/xonsh/history/json.py
@@ -97,13 +97,13 @@ def __init__(self, wait_for_shell=True, size=None, *args, **kwargs):
         self.daemon = True
         self.size = size
         self.wait_for_shell = wait_for_shell
-        self.start()
         self.gc_units_to_rmfiles = {
             "commands": _xhj_gc_commands_to_rmfiles,
             "files": _xhj_gc_files_to_rmfiles,
             "s": _xhj_gc_seconds_to_rmfiles,
             "b": _xhj_gc_bytes_to_rmfiles,
         }
+        self.start()
 
     def run(self):
         while self.wait_for_shell:


Test patch:
Repository: xonsh/xonsh

Issue:
Pip completer sneaks into cd when directory name contains 'pip'
## Expected Behavior
When triggering autocompletion in a `cd` command to enter a subdirectory of a directory containing 'pip', it should complete the subdirectory name. 

## Current Behavior
Instead, I get suggestions for `pip` subcommands like freeze, config, download, etc.

## Steps to Reproduce
Starting from a clean directory and an empty .xonshrc:
```
mkdir bagpipes
mkdir bagpipes/subdir
cd bagpipes/su[press tab here]
```
When tab is pressed in the above command, xonsh will not complete 'su' to 'subdir', but instead suggest pip subdommands.

## Workaround
Transposing the completers for `cd` and `pip` in the completer list fixes this specific issue, but it would not fix the similar issue of trying to complete another bash command, such as `ls bagpipes/su[press tab here]`. I haven't tried but assume that placing the pip completer after the bash completer would fix that too, although the proper fix seems to be making the pip completer not trigger when it shouldn't.

(For newbies like myself, you can transpose the completers by:

 ```
pip_completer = __xonsh__.completers['pip']
completer remove pip
completer add pip pip_completer ">cd"



Discussion:
Thanks for reporting this @presheaf! What a strange little bug. We should be able to avoid this with some smarter checks in the pip completer about when to fire.

Resolving patch:
diff --git a/xonsh/completers/pip.py b/xonsh/completers/pip.py
--- a/xonsh/completers/pip.py
+++ b/xonsh/completers/pip.py
@@ -9,12 +9,12 @@
 
 @xl.lazyobject
 def PIP_RE():
-    return re.compile(r"pip(?:\d|\.)*")
+    return re.compile(r"\bx?pip(?:\d|\.)*")
 
 
 @xl.lazyobject
 def PIP_LIST_RE():
-    return re.compile(r"pip(?:\d|\.)* (?:uninstall|show)")
+    return re.compile(r"\bx?pip(?:\d|\.)* (?:uninstall|show)")
 
 
 @xl.lazyobject


Test patch:
diff --git a/tests/completers/test_pip_completer.py b/tests/completers/test_pip_completer.py
new file mode 100644
--- /dev/null
+++ b/tests/completers/test_pip_completer.py
@@ -0,0 +1,39 @@
+import pytest
+from xonsh.completers.pip import PIP_RE, PIP_LIST_RE
+
+
+@pytest.mark.parametrize(
+    "line", ["pip", "xpip search", "$(pip", "![pip", "$[pip", "!(xpip"]
+)
+def test_pip_re(line):
+    assert PIP_RE.search(line)
+
+
+@pytest.mark.parametrize(
+    "line",
+    [
+        "pip show",
+        "xpip uninstall",
+        "$(pip show",
+        "![pip uninstall",
+        "$[pip show",
+        "!(xpip uninstall",
+    ],
+)
+def test_pip_list_re(line):
+    assert PIP_LIST_RE.search(line)
+
+
+@pytest.mark.parametrize(
+    "line",
+    [
+        "bagpipes show",
+        "toxbagpip uninstall",
+        "$(tompippery show",
+        "![thewholepipandpaboodle uninstall",
+        "$[littlebopip show",
+        "!(boxpip uninstall",
+    ],
+)
+def test_pip_list_re(line):
+    assert PIP_RE.search(line) is None
Repository: xonsh/xonsh

Issue:
In PTK shell, `Enter` should execute line in command mode
We override the Enter key to handle multi-line blocks without requiring users to "shift enter" -- this should have an extra filter on it to check if user is in VI Mode -- if they are, then `enter` should execute the current block.


Discussion:

Resolving patch:
diff --git a/xonsh/ptk2/key_bindings.py b/xonsh/ptk2/key_bindings.py
--- a/xonsh/ptk2/key_bindings.py
+++ b/xonsh/ptk2/key_bindings.py
@@ -304,8 +304,8 @@ def call_exit_alias(event):
         b.validate_and_handle()
         xonsh_exit([])
 
-    @handle(Keys.ControlJ, filter=IsMultiline())
-    @handle(Keys.ControlM, filter=IsMultiline())
+    @handle(Keys.ControlJ, filter=IsMultiline() & insert_mode)
+    @handle(Keys.ControlM, filter=IsMultiline() & insert_mode)
     def multiline_carriage_return(event):
         """ Wrapper around carriage_return multiline parser """
         b = event.cli.current_buffer


Test patch:
Repository: xonsh/xonsh

Issue:
[Feature request] Superhelp `?` should open man pages for subprocess commands
Currently, trying to run superhelp on a subprocess command just fails:

```
gil@badcatredux ~ $ ls?                                                                       
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
xonsh: subprocess mode: command not found: ls?
Did you mean one of the following?
    ls:  Alias
    ss:  Command (/usr/bin/ss)
    gs:  Alias
    sh:  Command (/usr/bin/sh)
    as:  Command (/usr/bin/as)
```

but it would be great if it first checked if there's a `man` page available and then display that if there is.


Discussion:

Resolving patch:
diff --git a/xonsh/built_ins.py b/xonsh/built_ins.py
--- a/xonsh/built_ins.py
+++ b/xonsh/built_ins.py
@@ -563,6 +563,11 @@ def _run_binary(self, kwargs):
             raise XonshError(e.format(self.cmd[0]))
         except FileNotFoundError:
             cmd0 = self.cmd[0]
+            if len(self.cmd) == 1 and cmd0.endswith("?"):
+                with contextlib.suppress(OSError):
+                    return self.cls(
+                        ["man", cmd0.rstrip("?")], bufsize=bufsize, **kwargs
+                    )
             e = "xonsh: subprocess mode: command not found: {0}".format(cmd0)
             env = builtins.__xonsh__.env
             sug = suggest_commands(cmd0, env, builtins.aliases)


Test patch:
Repository: xonsh/xonsh

Issue:
xonsh should return a non-zero exit code when a script cannot be found
Currently xonsh returns a zero exit code when the script cannot be found:
```
$ xonsh xx.xsh && echo "OK"
xonsh: xx.xsh: No such file or directory.
OK
```
That seems like a bug. Compared to bash, which returns a non-zero exit code:
```
$ bash xx.xsh && echo "OK"
bash: xx.xsh: No such file or directory
```


Discussion:
Hey @certik -- thanks for reporting!  I agree that xonsh in script mode should return a non-zero exit code in this case.
I got burned by this several times already, when I change the path of the script that Xonsh should execute and the CI "succeeds" and I didn't notice until much later (after the PR that broke it got merged into master).

Resolving patch:
diff --git a/xonsh/main.py b/xonsh/main.py
--- a/xonsh/main.py
+++ b/xonsh/main.py
@@ -447,6 +447,8 @@ def func_sig_ttin_ttou(n, f):
                 )
             else:
                 print("xonsh: {0}: No such file or directory.".format(args.file))
+                events.on_exit.fire()
+                sys.exit(1)
         elif args.mode == XonshMode.script_from_stdin:
             # run a script given on stdin
             code = sys.stdin.read()


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -186,3 +186,9 @@ def mocked_execlp(f, *args):
     with pytest.raises(Exception):
         xonsh.main.main()
     assert len(checker) == 0
+
+
+def test_xonsh_no_file_returncode(shell, monkeypatch, monkeypatch_stderr):
+    monkeypatch.setattr(sys, "argv", ["xonsh", "foobazbarzzznotafileatall.xsh"])
+    with pytest.raises(SystemExit):
+        xonsh.main.main()