Slide 1

Slide 1 text

xonsh Make Python Your Shell Anthony Scopatz HubPy 2015-11-12

Slide 2

Slide 2 text

whoami ● Prof. Anthony Scopatz - Nuclear Engineering Program, Mechanical Eng. Dept. ● Python Software Foundation Fellow ● Former Numfocus Board Member ● ERGS - http://www.ergs.sc.edu

Slide 3

Slide 3 text

what is xonsh Features include: ● Naturally typed environment variables ● Inherits the environment from BASH ● Uses BASH completion for subprocess commands ● Regular expression filename globbing ● Its own PLY-based lexer and parser ● xonsh code parses into a Python AST ● You can do all the normal Python things, like arithmetic and importing ● Captured and uncaptured subprocesses ● Pipes, redirection, and non-blocking subprocess syntax support ● Help and superhelp with ? and ?? ● Command aliasing ● Optional fish-like, prompt-toolkit based interface ● Rich history ● Color prompts ● Low system overhead http://xonsh.org

Slide 4

Slide 4 text

but why

Slide 5

Slide 5 text

stages ● conceptualization, best(python, bash)

Slide 6

Slide 6 text

stages ● conceptualization, best(python, bash) ● investigation into particulars

Slide 7

Slide 7 text

stages ● conceptualization, best(python, bash) ● investigation into particulars ● moral compulsion to act

Slide 8

Slide 8 text

stages ● conceptualization, best(python, bash) ● investigation into particulars ● moral compulsion to act ● anger

Slide 9

Slide 9 text

stages ● conceptualization, best(python, bash) ● investigation into particulars ● moral compulsion to act ● anger ● regret

Slide 10

Slide 10 text

stages ● conceptualization, best(python, bash) ● investigation into particulars ● moral compulsion to act ● anger ● regret ● acceptance

Slide 11

Slide 11 text

quotes “Just stumbled across xonsh by @scopatz -- holy cow it's amazing. I've never been so happy to rewrite a .rc file” - @gilforsyth “I've tweeted about Xonsh before, and finally spent a day using it exclusively. I must have it on ALL PLATFORMS now.” - @wbuthod “@pathogenomenick @btnaughton @lexnederbragt the dark wizardry of @scopatz :-) check out xonsh.org” -@biochemistries

Slide 12

Slide 12 text

syntactical hipstery tour

Slide 13

Slide 13 text

how does it work Traditional language phases ● lexer (ply) ● parser (ply) ● syntax tree transformation (xonsh) ● compiler (python) ● execution (python)

Slide 14

Slide 14 text

lexer This is trickier than you’d think, because Python is not whitespace sensitive inside of expressions, but subprocess commands are: $ ls -l $ ls - l $ ls-l

Slide 15

Slide 15 text

parser Uses yacc to assemble a xonsh AST built out of only Python AST nodes. Let’s xonsh use Python’s exec() & eval(). BASH-isms are translated into calls to functions that are shoved into builtins.

Slide 16

Slide 16 text

syntax tree transformation To help resolve ambiguity, ls -l, xonsh safely attempts a context sensitive parsing.

Slide 17

Slide 17 text

syntax tree transformation To help resolve ambiguity, ls -l, xonsh safely attempts a context sensitive parsing. If the leftmost name is not found in the Python context and the line can be parsed in subprocess mode, the line is wrapped in $[].

Slide 18

Slide 18 text

syntax tree transformation To help resolve ambiguity, ls -l, xonsh safely attempts a context sensitive parsing. If the leftmost name is not found in the Python context and the line can be parsed in subprocess mode, the line is wrapped in $[]. Totally avoidable via $(ls -l) and $[ls -

Slide 19

Slide 19 text

compile & exec These happen through the normal Python builtins. Nothing special.

Slide 20

Slide 20 text

dark wizardry

Slide 21

Slide 21 text

install - http://xonsh.org conda: $ conda install -c scopatz xonsh pip: $ pip install xonsh source: Download the source from github (zip file), then run the following from the source directory, $ python setup.py install and others!

Slide 22

Slide 22 text

questions? contribution welcome!