Skip to content

Instantly share code, notes, and snippets.

@vicentereig
Created September 6, 2012 09:54
Show Gist options
  • Save vicentereig/3654113 to your computer and use it in GitHub Desktop.
Save vicentereig/3654113 to your computer and use it in GitHub Desktop.
Simple .pythonbrewrc implementation
export PYTHONBREW_PROJECT_VENV='your_projects_venv'
export PYTHONBREW_PYTHON_VERSION='2.7.3'
# ~/.pythonbrewrc
__pythonbrew_init_project()
{
pythonbrew switch $PYTHONBREW_PYTHON_VERSION;
pythonbrew venv use $PYTHONBREW_PROJECT_VENV;
}
cd ()
{
builtin cd "$@";
local result=$?;
[[ -s ".pbrc" ]] && source ".pbrc" && __pythonbrew_init_project;
return $result
}
# It simply switches to the Python version and venv when cd'ing your project directory.
# This simple implementation is inspired on RVM's .rvmrc file. https://rvm.io/workflow/rvmrc
# 1) Grab a copy of pythonbrew.sh and store it at ~/.pythonbrewrc
echo "Downloading .pythonbrewrc..."
curl https://raw.github.com/gist/3654113/ee7f60f347cc0576001ece7dfa16b35eca8aa6d7/pythonbrew.sh > ~/.pythonbrewrc
# 2) Add the following line to your .bashrc or .bash_profile
# [[ -s "$HOME/.pythonbrewrc" ]] && source $HOME/.pythonbrewrc
# 3) Assuming your project is under $PROJECT_PATH, create $PROJECT_PATH/.pbrc and edit it to match your needs.
echo "Storing .pbrc at $PROJECT_PATH..."
curl https://raw.github.com/gist/3654113/97a1f413f0ae655bc4d9b812a9f3fa935bf98578/.pbrc > $PROJECT_PATH/.pbrc
@vicentereig
Copy link
Author

Installation:

  curl https://raw.github.com/gist/3654113/606cf426a677adf65f4cef9be5c48010a0523de5/sample_pythonbrewrc | PROJECT_PATH=~/path_to_your_project/ bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment