Repository: xonsh/xonsh

Issue:
Can't run xonsh File Not Found Error
I noticed [#8](https://github.com/scopatz/xonsh/issues/8), [#1000](https://github.com/scopatz/xonsh/issues/1000) and [#1](https://github.com/scopatz/xonsh/issues/1). I think  [#1000](https://github.com/scopatz/xonsh/issues/1000) is the closest issue to what I'm having.

When I first installed xonsh, it sort of worked.  Then it stopped working and kept giving me this error:

```
Collecting xonsh
  Using cached xonsh-0.3.0.tar.gz
Installing collected packages: xonsh
  Running setup.py install for xonsh ... error
    Complete output from command /Users/AlexCory/.pyenv/versions/3.4.0/bin/python3.4 -u -c "import setuptools, tokenize;__file__='/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-v801xh9z-record/install-record.txt --single-version-externally-managed --compile:
                               ╓██▄
                              ╙██▀██╕
                             ▐██4Φ█▀█▌
                           ²██▄███▀██^██
                         -███╩▀ " ╒▄█████▀█
                          ║██▀▀W╤▄▀ ▐║█╘ ╝█
                     ▄m▀%Φ▀▀  ╝*"    ,α█████▓▄,▄▀Γ"▀╕
                     "▀██¼"     ▄═╦█╟║█▀ ╓ `^`   ,▄ ╢╕
                      ,▀╫M█▐j╓╟▀ ╔▓▄█▀  '║ ╔    ╣║▌  ▀▄
                   ▄m▀▀███╬█╝▀  █▀^      "ÜM  j▐╟╫╨▒   ╙▀≡═╤═m▀╗
                   █æsæ╓  ╕, ,▄Ä   ▐'╕H   LU  ║║╠╫Å^2=⌐         █
                ▄æ%Å███╠█ª╙▄█▀      $1╙       ║║╟╫╩*T▄           ▌
               ╙╗%▄,╦██▌█▌█╢M         ╕      M║║║║█═⌐ⁿ"^         ╫
                 ╙╣▀████@█░█    ▌╕╕   `      ▌║▐▐║█D═≈⌐¬ⁿ      s ║⌐
                   ╙╬███▓║█`     ▌╚     ╕   ╕▌║▐▐╣▌⌐*▒▒Dù`       ▐▌
                    ╙╬██╨U█      ╟      $ ▌ ▌▌▐▐▐M█▄═≤⌐%       ╓⌐ ▌
                     ║║█▄▌║             ╟ ▌ ▌M▐▐▐M█▀▒▒▒22,       ▐▌
                      ███╙^▌            ║ ▌ ⌐M▐▐▐M█≤⌐⌐¬──        ▐M
                      ║██ ▌╙   ╓       H║ ▌╒ M║▐▐M█"^^^^^"ⁿ      ║
                       ██╕╙@▓   ╕      ▌║ H'  ║▐▐▐█══=.,,,       █
                       ╙█▓╔╚╚█     ╠   ▌└╒ ▌▐ ╚║║║▀****ⁿ -      ╓▌
                        ╙█▌¼V╚▌   ▌  ╕ ▌ ║╒ ║ ▌▒╠█▀≤≤≤≤≤⌐       █
                         ╙█▌╔█╚▌     ┘ M ▌║ ╫ UUM██J^^"        ▐▌
                          ╙██╙█╙▌  ╕$j  ▐⌐▌ ▌║╝╟█Å%%%≈═        █
                           ╙╣█╣█^▌ ╠║▐  ║ ▌▐.DU██^[""ⁿ       -╒▌
                             ▀█▄█`▌ ░M▀ ▌▐ Å£╝╝█╜%≈═╓""w   ⁿ⌐ █
                              `▀▄▀`▌ ▌█▐⌐║▐UW╖██%≤═░*─    =z ▄Γ
                                ╙██╙▄▌█  ▌Å╛╣██╨%╤ƒⁿ=    -` ▄┘
                                  █▌╢▓▌▌ W £6█╤,"ⁿ `   ▄≡▀▀▀
                                   █"█▌▌╟Å╓█╓█▀%`    ▄▀
                                   ╙▌██`▒U▓U█%╗*     █
                                    ▌╫║ ▌ÅÅ║▀╛¬`      `"█
                                    ▌╫  ╫╟ █▄     ~╦%▒╥4^
                                    ▌▌  "M█ `▀╕ X╕"╗▄▀^
                                    █▌   ╓M   ╙▀e▀▀^
                                    ╙██▄▄▀
                                      ^^

    running install
    Remove xonsh/parser_table.py
    Building lexer and parser tables.
    Traceback (most recent call last):
      File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/xonsh/parsers/base.py", line 6, in <module>
        from ply import yacc
    ImportError: No module named 'ply'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/setup.py", line 182, in <module>
        main()
      File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/setup.py", line 178, in main
        setup(**skw)
      File "/Users/AlexCory/.pyenv/versions/3.4.0/lib/python3.4/distutils/core.py", line 149, in setup
        dist.run_commands()
      File "/Users/AlexCory/.pyenv/versions/3.4.0/lib/python3.4/distutils/dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "/Users/AlexCory/.pyenv/versions/3.4.0/lib/python3.4/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/setup.py", line 92, in run
        build_tables()
      File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/setup.py", line 53, in build_tables
        from xonsh.parser import Parser
      File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/xonsh/parser.py", line 6, in <module>
        from xonsh.parsers.v34 import Parser
      File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/xonsh/parsers/v34.py", line 4, in <module>
        from xonsh.parsers.base import BaseParser
      File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/xonsh/parsers/base.py", line 8, in <module>
        from xonsh.ply import yacc
    ImportError: No module named 'xonsh.ply'
```

I installed ply separately, and then everything installed correctly.  The problem now happens when I try to run xonsh.  I get this error:

```
Traceback (most recent call last):
  File "/Users/AlexCory/.pyenv/versions/3.4.0/bin/xonsh", line 9, in <module>
    load_entry_point('xonsh==0.3.0', 'console_scripts', 'xonsh')()
  File "/Users/AlexCory/.pyenv/versions/3.4.0/lib/python3.4/site-packages/xonsh/main.py", line 229, in main
    args = premain(argv)
  File "/Users/AlexCory/.pyenv/versions/3.4.0/lib/python3.4/site-packages/xonsh/main.py", line 216, in premain
    shell = builtins.__xonsh_shell__ = Shell(**shell_kwargs)
  File "/Users/AlexCory/.pyenv/versions/3.4.0/lib/python3.4/site-packages/xonsh/shell.py", line 74, in __init__
    ctx=self.ctx, **kwargs)
  File "/Users/AlexCory/.pyenv/versions/3.4.0/lib/python3.4/site-packages/xonsh/readline_shell.py", line 157, in __init__
    setup_readline()
  File "/Users/AlexCory/.pyenv/versions/3.4.0/lib/python3.4/site-packages/xonsh/readline_shell.py", line 73, in setup_readline
    readline.read_init_file()
FileNotFoundError: [Errno 2] No such file or directory
```

I really want to use this because it's so sick, but I can't even get it to run properly. :(



Discussion:
Hi @alex-cory, thanks for reporting! 

I believe that the import issue this is the same as #1001, which was fixed in #1002. All apologies about that. This was our first release without a hard ply dependency and so we has a slightly mistaken setup.py.  We plan on doing a v0.3.1 release on Friday that will have this fix in it.  Again, all apologies.

The second issue that you mention is legitimately a new issue.  This actually seems to be a bug is CPython. It looks like you are on a Mac, which means that you are probably using libedit rather than readline, which probably doesn't support default file loading (even though the docs say it should - https://docs.python.org/3/library/readline.html#readline.read_init_file).  Readline - in general - is a mess.  I'll implement a workaround because the likelihood of CPython fixing this is low.

In the meantime, would you mind installing prompt-toolkit.  You should then automatically get the prompt-toolkit shell and avoid these readline issues?


Resolving patch:
diff --git a/xonsh/readline_shell.py b/xonsh/readline_shell.py
--- a/xonsh/readline_shell.py
+++ b/xonsh/readline_shell.py
@@ -69,8 +69,12 @@ def setup_readline():
         readline.parse_and_bind("bind ^I rl_complete")
     else:
         readline.parse_and_bind("tab: complete")
-    # load custom user settings
-    readline.read_init_file()
+    # try to load custom user settings
+    try:
+        readline.read_init_file()
+    except Exception:
+        # this seems to fail with libedit
+        print_exception('xonsh: could not load readline default init file.')
 
 
 def teardown_readline():
diff --git a/xonsh/tools.py b/xonsh/tools.py
--- a/xonsh/tools.py
+++ b/xonsh/tools.py
@@ -344,7 +344,7 @@ def suggest_commands(cmd, env, aliases):
     return rtn
 
 
-def print_exception():
+def print_exception(msg=None):
     """Print exceptions with/without traceback."""
     env = getattr(builtins, '__xonsh_env__', os.environ)
     if 'XONSH_SHOW_TRACEBACK' not in env:
@@ -356,6 +356,9 @@ def print_exception():
         exc_type, exc_value, exc_traceback = sys.exc_info()
         exception_only = traceback.format_exception_only(exc_type, exc_value)
         sys.stderr.write(''.join(exception_only))
+    if msg:
+        msg = msg if msg.endswith('\n') else msg + '\n'
+        sys.stderr.write(msg)
 
 
 # Modified from Public Domain code, by Magnus Lie Hetland


Test patch: