Timesavers: Bash kernel for Jupyter notebooks & ctag Vim navigation

(Rob H) #1

I found these two things save me some time while developing,

bash kernel for notebooks

To install,

git clone git@github.com:takluyver/bash_kernel.git
cd bash_kernel
source activate fastai
python -m bash_kernel.install --sys-prefix

This is handy because I often find bash easiest for certain tasks, and building a script in a notebook is easier than running commands in the shell and copying them into an editor

The benefit over python notebook + shell is the syntax becomes simpler when saving or passing variables, and the syntax highlighting is better. Of course, if someone else has a better way, I’m all ears.

ctag vim navigation

Also, unrelated, I found this guide useful for explaining how to do the navigation Jeremy did in Vim with Ctrl+] to move around source code via “tags”

Basically, something like this,

sudo apt-get install exuberant-ctags
ctags -R -o ~/ctags ~/fastai-pytorch/fastai/ ~/anaconda3/envs/fastai/lib/python3.6/
echo --python-kinds=-i > ~/.ctags

Add to crontab (might need to change ~ to full path),

1 * * * * ~/ctags ~/fastai-pytorch/fastai/ ~/anaconda3/envs/fastai/lib/python3.6/ 2>/dev/null


  • -i in the ~/.ctags file means “ignore imports” as discussed here. You might also add -v

  • this doesn’t seem to work for python core libraries, for example, if I put the cursor on join in os.path.join it takes me to the definition of join in asyncio/queues.py instead of ntpath.py (which has the code for os.path), but at least it works for jumping around fastai code. Perhaps better still is to use an IDE like Pycharm

Again, if there is an easier or more correct way to set this up, I’m happy to hear it.

Deep Learning Brasília - Lição 6
Wiki: Lesson 6
(Ravi Sekar Vijayakumar) #2

Thanks! Both look super useful.

(Maureen Metzger) #3

Thanks for sharing this, @rob

(Jeremy Howard) #4

Very helpful - might be worth adding the vim tags notes to @timlee’s notes and/or the lesson wiki…

(Rob H) #5

Alright, done

(David Bressler) #6

One last step in the guide that you didn’t include… You need to add the following to a ~/.vimrc file you create:

:set tags=~/ctags

Thanks for this great info!

(Rahim Shamsy) #7

Thanks for the info. I want to go through the pytorch source code as well. I am interested in accessing code for torch.optim, but when I run vim -t torch.optim, it leads me to source code where torch.optim is imported. Specifically, to the line:

import torch.optim as optim

I run Ctrl-] on torch, but all it does it lead me to the beginning of the same line. How can I access source code for an imported class/module?

Thank you.