# Buggy code
def setup_readline():
    """Sets up the readline module and completion suppression, if available."""
    global RL_COMPLETION_SUPPRESS_APPEND, RL_LIB, RL_CAN_RESIZE, RL_STATE, readline
    if RL_COMPLETION_SUPPRESS_APPEND is not None:
        return
    try:
        import readline
    except ImportError:
        return
    import ctypes
    import ctypes.util

    readline.set_completer_delims(" \t\n")
    if not readline.__file__.endswith(".py"):
        RL_LIB = lib = ctypes.cdll.LoadLibrary(readline.__file__)
        try:
            RL_COMPLETION_SUPPRESS_APPEND = ctypes.c_int.in_dll(
                lib, "rl_completion_suppress_append"
            )
        except ValueError:
            # not all versions of readline have this symbol, ie Macs sometimes
            RL_COMPLETION_SUPPRESS_APPEND = None
        try:
            RL_STATE = ctypes.c_int.in_dll(lib, "rl_readline_state")
        except:
            pass
        RL_CAN_RESIZE = hasattr(lib, "rl_reset_screen_size")
    env = builtins.__xonsh_env__
    # reads in history
    readline.set_history_length(-1)
    ReadlineHistoryAdder()
    # sets up IPython-like history matching with up and down
    readline.parse_and_bind('"\e[B": history-search-forward')
    readline.parse_and_bind('"\e[A": history-search-backward')
    # Setup Shift-Tab to indent
    readline.parse_and_bind('"\e[Z": "{0}"'.format(env.get("INDENT")))

    # handle tab completion differences found in libedit readline compatibility
    # as discussed at http://stackoverflow.com/a/7116997
    if readline.__doc__ and "libedit" in readline.__doc__:
        readline.parse_and_bind("bind ^I rl_complete")
    else:
        readline.parse_and_bind("tab: complete")
    # load custom user settings
    readline.read_init_file()


# Traceback (ImportError)
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'

# Fixed code
def setup_readline():
    """Sets up the readline module and completion suppression, if available."""
    global RL_COMPLETION_SUPPRESS_APPEND, RL_LIB, RL_CAN_RESIZE, RL_STATE, readline
    if RL_COMPLETION_SUPPRESS_APPEND is not None:
        return
    try:
        import readline
    except ImportError:
        return
    import ctypes
    import ctypes.util

    readline.set_completer_delims(" \t\n")
    if not readline.__file__.endswith(".py"):
        RL_LIB = lib = ctypes.cdll.LoadLibrary(readline.__file__)
        try:
            RL_COMPLETION_SUPPRESS_APPEND = ctypes.c_int.in_dll(
                lib, "rl_completion_suppress_append"
            )
        except ValueError:
            # not all versions of readline have this symbol, ie Macs sometimes
            RL_COMPLETION_SUPPRESS_APPEND = None
        try:
            RL_STATE = ctypes.c_int.in_dll(lib, "rl_readline_state")
        except:
            pass
        RL_CAN_RESIZE = hasattr(lib, "rl_reset_screen_size")
    env = builtins.__xonsh_env__
    # reads in history
    readline.set_history_length(-1)
    ReadlineHistoryAdder()
    # sets up IPython-like history matching with up and down
    readline.parse_and_bind('"\e[B": history-search-forward')
    readline.parse_and_bind('"\e[A": history-search-backward')
    # Setup Shift-Tab to indent
    readline.parse_and_bind('"\e[Z": "{0}"'.format(env.get("INDENT")))

    # handle tab completion differences found in libedit readline compatibility
    # as discussed at http://stackoverflow.com/a/7116997
    if readline.__doc__ and "libedit" in readline.__doc__:
        readline.parse_and_bind("bind ^I rl_complete")
    else:
        readline.parse_and_bind("tab: complete")
    # 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.")