Making textmate virtualenv aware
December 16th, 2008First off, the run script command needs to be aware of the virtualenv stuff. So open up the bundle editor, and replace this:
is_test_script = ENV["TM_FILEPATH"] =~ /(?:\b|_)(?:test)(?:\b|_)/ or File.read(ENV["TM_FILEPATH"]) =~ /\bimport\b.+(?:unittest)/ TextMate::Executor.run(ENV["TM_PYTHON"] || "python", "-u", ENV["TM_FILEPATH"]) do |str, type|
with:
is_test_script = ENV["TM_FILEPATH"] =~ /(?:\b|_)(?:test)(?:\b|_)/ or File.read(ENV["TM_FILEPATH"]) =~ /\bimport\b.+(?:unittest)/ # default python python = ENV["TM_PYTHON"] || "python" # try for virtualenv if it exists if ENV.has_key?("TM_PROJECT_DIRECTORY") virtualenv_python = ENV["TM_PROJECT_DIRECTORY"] + "/bin/python" if FileTest.exists?(virtualenv_python) python = virtualenv_python end end TextMate::Executor.run(python, "-u", ENV["TM_FILEPATH"]) do |str, type|
Now, we also want the unit tests to pick up that environment as well, so you need to do the same with the Run Project Unit Tests command. I am using nose to collect tests, and the nosexml plugin to format the results. You should install them if you need to. Replace:
# Find all files that end with "Test.py" and run # them. find . -name "*Test.py" -exec "${TM_PYTHON:-python}" '{}' \;|pre
with:
cd $TM_PROJECT_DIRECTORY if [ -f bin/activate ] then source bin/activate fi nosetests --xml --xml-formatter=nosexml.TextMateFormatter
PS, it seems like the python bundle needs some love, anyone know the maintainer?
This week’s column is about the Home Office’s alleged new plans to keep a centralised record of the nation’s communications traffic data: