Last active
April 13, 2020 08:18
-
-
Save ndarville/3625246 to your computer and use it in GitHub Desktop.
Django on Travis CI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A basic database set-up for Travis CI. | |
The set-up uses the 'TRAVIS' (== True) environment variable on Travis | |
to detect the session, and changes the default database accordingly. | |
Be mindful of where you place this code, as you may accidentally | |
assign the default database to another configuration later in your code. | |
""" | |
import os | |
# (...) | |
if 'TRAVIS' in os.environ: | |
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.postgresql_psycopg2', | |
'NAME': 'travisci', | |
'USER': 'postgres', | |
'PASSWORD': '', | |
'HOST': 'localhost', | |
'PORT': '', | |
} | |
} | |
# (...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A basic travis.yml boilerplate for Django projects | |
# | |
# The set-up assumes a postgreSQL database. | |
# | |
# Replace the following variables in the code: | |
# * your_project_settings | |
# * your_github_username | |
# * your_repo | |
language: python | |
python: | |
- 2.6 | |
- 2.7 | |
services: postgresql | |
env: | |
- DJANGO=1.4.1 | |
before_install: | |
- export DJANGO_SETTINGS_MODULE=your_project.settings | |
- export PYTHONPATH=$HOME/builds/your_github_username/your_repo | |
- export PIP_USE_MIRRORS=true | |
install: | |
- pip install -r requirements.txt | |
- pip install django==$DJANGO --quiet | |
- pip install psycopg2 --quiet | |
before_script: | |
- psql -c "CREATE DATABASE mydb;" -U postgres | |
script: | |
- python manage.py syncdb --noinput |
Did any of you have trouble with travis trying to import manage.py instead of running it from a shell command?
I am getting an ImportErrror: no module named py
I had to set:
export PYTHONPATH="/usr/local/lib/python2.7/dist-packages"
to get it to build.
Someone update this gist. All the tools in the setup here have been updated.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had trouble building on travi-ci and this helped a lot. Thanks.