Last active
August 29, 2015 14:01
-
-
Save tkanmae/9650a44bccc859113cd0 to your computer and use it in GitHub Desktop.
IPython startup scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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