Skip to content

Instantly share code, notes, and snippets.

@tkanmae
Last active August 29, 2015 14:01
Show Gist options
  • Save tkanmae/9650a44bccc859113cd0 to your computer and use it in GitHub Desktop.
Save tkanmae/9650a44bccc859113cd0 to your computer and use it in GitHub Desktop.
IPython startup scripts
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Add the top directory of a git-managed project to `sys.path`."""
import os
import shlex
import subprocess
import sys
cmd = 'git rev-parse --show-toplevel'
with open(os.devnull, 'wb') as DEVNULL:
proc = subprocess.Popen(shlex.split(cmd), stderr=DEVNULL,
stdout=subprocess.PIPE)
stdout, _ = proc.communicate()
if proc.returncode == 0:
sys.path.insert(0, stdout.strip())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment