So your workflow is to keep separate branches in separate working directories? That's fine, it's a pretty reasonable workflow with Subversion.
Personally I would change whatever Python programs you have in source control to look for their own libraries and modify sys.path
before importing anything; that way they'll work no matter where they've been relocated to.
#!/usr/bin/env python
import os, sys
basedir = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.join(basedir, 'lib'))
If you don't do that, you could put a wrapper executable in your ~/bin
or whatever, somewhere in $PATH
,
#!/bin/bash
dir=$(pwd)
while [[ $dir != / ]]; do
if [[ -d "$dir/lib" ]]; then
export PYTHONPATH="$dir/lib${PYTHONPATH:+:$PYTHONPATH}"
break
fi
dir="${dir%/*}"
done
if (($# > 0)); then exec "$@"; fi
which simply looks around for a lib
directory to prepend to $PYTHONPATH
before running whatever you want. Maybe name it "py
".
$ cd dir1 # dir1/lib exists
$ py ./my-program
$ cd ../dir2 # dir2/lib exists
$ py ./my-program
It's also possible to have a workflow where you stay within a single working directory, using svn sw
to change branches. Since your path never changes, setting PYTHONPATH
once would stay valid even with branch changes.
(This is the common workflow in git, monotone, hg, etc.)