Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Latest commit

 

History

History
82 lines (58 loc) · 2.23 KB

running-python-locally.md

File metadata and controls

82 lines (58 loc) · 2.23 KB

Running python locally

Foreword

Lets start with us saying that docker is a great tool. But in all this greatness there is a performance penalty. In some cases the penalty is big enough that you want to eject docker and use a local python interpreter instead - this tutorial will show you how.

Setup

Begin with changing the PYTHON_HOST environment variable in docker-compose.yml for the container web so we use a local running python interpreter instead of the docker version.

web:
    ...
    environment:
        - PYTHON_HOST=http://host.docker.internal

If you have a existing web container, remove it docker-compose rm web

Create a custom .env file for your local db instance

touch wagtail/.env.local

And supply your env configuration, you can usually just copy paste the values you would have from /docker/config/python.env and only replace DATABASE_HOST.

DJANGO_SETTINGS_MODULE=pipit.settings.local
ALLOWED_HOSTS=*
INTERNAL_IPS=0.0.0.0
SECRET_KEY=generatesecretkeyhere
MEDIA_PATH=./media
STATIC_PATH=./static
DATABASE_USER=postgres
DATABASE_PASSWORD=postgres
DATABASE_NAME=postgres
DATABASE_HOST=localhost
DATABASE_PORT=8083

Setup virtualenv (but please note that there are many different ways of doing package management in python (pyenv, poetry etc), if you have a preffered way of doing things - do it :)

cd wagtail
python3 -m venv venv
source venv/bin/activate

Install local packages. We use test.txt here because it include both requirements for running the app with dev tools and testing requirements.

pip install -r requirements/test.txt

Tip: If you are having issues installing psycopg2 because your are lacking postgres, replace psycopg2 with psycopg2-binary

Running website

Start docker (without the python container)

docker-compose up db web

And then finally start your python server

cd wagtail
python manage.py runserver 8000

Now open http://blog.acme.com.test:8081/wt/cms in your favorite browser and you should see the Wagtail CMS login page.

Running tests

Because we use a different set of configuration while connecting to the db, we keep a custom pytest config around for running python locally.

cd wagtail
pytest -c pytest.local.ini