Skip to content

Instantly share code, notes, and snippets.

@mattnorris
Created June 2, 2013 03:17
Show Gist options
  • Save mattnorris/5692504 to your computer and use it in GitHub Desktop.
Save mattnorris/5692504 to your computer and use it in GitHub Desktop.
Hook that executes after virtualenv makes a new virtual environment; this script sets up a directory structure and installs some common packages in the virtual environment.
#!/bin/sh
# This hook is run after a new virtualenv is activated. It resides in the
# WORKON_HOME directory.
SITE_PKGS="lib/python2.5/site-packages" # relative path to site pacakges for easy_install
SEP="################################################################################"
cdvirtualenv
echo "Creating the project's directory structure..."
# The "project" directory is the heart of the app. This is where all
# source code, project documents, and scripts will go.
mkdir -p project/src
cd project
# A "best practice" .gitignore file that ignores tmp files,
# build artifacts, etc.
echo -e "*~\ntmp*\n*.tmp\n*.bak\n*.pyc\n" > .gitignore
echo -e "# Build artifacts\n$SEP" >> .gitignore
echo -e "nosetests.xml\ncoverage.xml\n.coverage\n*.cover" >> .gitignore
echo -e ".figleaf\nreport.html\npyccuracy_report.html\n" >> .gitignore
echo -e "# Sass artifacts\n$SEP" >> .gitignore
echo -e ".sass-cache/\n" >> .gitignore
echo -e "# System artifacts\n$SEP" >> .gitignore
echo -e "PIL.pth\n" >> .gitignore
# Create a directory for project documentation.
mkdir -p docs/api
echo -e "Documentation generated by Sphinx or Epydoc should go here.\n\n" > docs/api/README
echo "DO NOT DELETE. Empty directories are not committed to version control. This README file servers as a placeholder so that your CI tool (e.g., Jenkins) will commit this directory to its repository." >> docs/api/README
# Save continuous integration files here (e.g., Jenkin's config.xml).
mkdir -p scripts/ci
# Any configuration of paths, etc.
mkdir config
# Generate a path to use for any "module not found" PIL errors.
# http://stackoverflow.com/questions/2813742
echo "Generating PIL.pth..."
echo "`pwd`/$SITE_PKGS" > config/PIL.pth
# Create a directory for tests.
mkdir -p test/unit
cd test
mkdir mocks
mkdir fixtures
mkdir functional
mkdir acceptance
echo "Done."
echo "Installing widely-used packages..."
easy_install lxml
easy_install http://dist.repoze.org/PIL-1.1.6.tar.gz
# For testing...
easy_install nose
easy_install coverage
# For documentation...
easy_install pylint
echo "Done."
# Change to the project's source directory.
cdvirtualenv
cd project/src
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment