Skip to content

Instantly share code, notes, and snippets.

Created May 12, 2012 14:46
Show Gist options
  • Save urschrei/2666927 to your computer and use it in GitHub Desktop.
Save urschrei/2666927 to your computer and use it in GitHub Desktop.
Bootstrap a Flask project
#!/bin/bash -e
# opinionated Flask bootstrap script
# assumes you'll be using MySQL/PG, Fabric, Webassets, WTForms and Blueprints
# creates a virtualenv and an Alembic migrations system
# The script will halt on any error, and remove the project dir, if it created one
# accepts a single argument: a new directory name under which to create the project
# check that Python is installed
type python >/dev/null 2>&1 || { echo >&2 "Python doesn't appear to be installed. Aborting."; exit 1; }
# check that there's a system-wide virtualenv package installed
type virtualenv >/dev/null 2>&1 || { echo >&2 "This script requires a system-wide install of Virtualenv. Aborting."; exit 1; }
if [ ! -d $1 ]; then
# error handler removes the created project dir if there's a problem
trap 'echo "Cleaning up"; cd $dir; rm -rf $1' INT TERM EXIT
mkdir -p $1/$1/config
mkdir -p $1/$1/templates/errors
mkdir -p $1/$1/static/{css,js,img,gen}
mkdir -p $1/apps
mkdir -p $1/fabfile
touch $1/requirements.txt
virtualenv $1/venv
source $1/venv/bin/activate
if type pg_config >/dev/null 2>&1; then
pip install psycopg2
echo "Skipping psycopg2 installation: couldn't find pg_config"
for package in flask fabric yolk flask-sqlalchemy flask-assets pyyaml yuicompressor flask-wtf mysql-python alembic ipython
pip install $package
pip freeze >> $1/requirements.txt
$1/venv/bin/easy_install readline
cd $1
alembic init db
cd ..
touch $1/
touch $1/$1/
touch $1/apps/
touch $1/fabfile/
touch $1/$1/config/
touch $1/$1/config/
trap 'echo "Finished creating project skeleton"' INT TERM EXIT
{ echo >&2 "That directory already exists. Aborting."; exit 1; }
Copy link


Copy link

urschrei commented May 13, 2012 via email

Copy link

I changed it to use requirements.txt instead of pip install, as you'll likely be using that again later.

Copy link

Oh nice. I could just check that type pg_config succeeds (same as for Python and Virtualenv), because that seems to be the biggest stumbling block for PG installation from pip.

Copy link

Line 21 contains a redundant blank. The line should be: "mkdir -p $1/app/static/{css,js,img,gen}".

Copy link


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