Thanks for contributing to this repo! This is a short guide to set you up for running Ballsdex in a development environment, with some tips on the code structure.
Using Docker:
- Install Docker.
- Run
docker compose up -d postgres-db. This will start the database. It doesn't need the rest of the images to be built first.
Without docker, check how to install and setup PostgreSQL on your OS. Export the appropriate environment variables as described in the no-docker installation guide.
- Get Python 3.14.
- Install uv with
pip install uv(or see uv installation). - Run
uv sync --extra dev. Thedevextra pulls inruff,pyright,pre-commitand the admin panel's debug tools (django-debug-toolbar,pyinstrument), all used later in this guide. - You may run commands inside the virtualenv with
uv run ....
Before running any command, make sure the following environment variables are configured in your shell:
export BALLSDEXBOT_DB_URL="postgres://ballsdex:defaultballsdexpassword@localhost:5432/ballsdex"If needed, feel free to change the host, port, or user/password of the database.
uv run python -m ballsdex --dev --debugYou can do python3 -m ballsdex -h to see the available options.
cd admin_panel
export DJANGO_SETTINGS_MODULE=admin_panel.settings.dev
uv run python manage.py migrate
uv run python manage.py collectstatic --no-input
uv run uvicorn --reload --reload-include "*.html" admin_panel.asgi:applicationYou will be running the admin panel with additional debug tools. There is the django debug
toolbar to inspect SQL queries, loading times, template loading and other tools. You also get
pyinstrument, allowing you to profile a page by appending ?profile at the end.
Tip
uv run python manage.py contains a lot of commands, feel free to explore them! To name a few:
shelllaunches a Python REPL ready to interact with models and databasedbshellwill launchpsqlwith the right settings for the databasecheckperforms general system checks to ensure everything workscreatesuperusercreates a superuser accountshowmigrationsshows the applied/missing migrations
Warning
Do not use python3 manage.py runserver to run the server, since the bot relies on async code.
Django must be started with an ASGI server, not the default WSGI.
As an alternative to the native setup above, you can run the whole stack (bot, admin panel, migrations, proxy) through Docker Compose instead:
docker compose build
docker compose up -ddocker-compose.override.yml is loaded automatically if present, and is dedicated to local
development: it points the admin panel at admin_panel.settings.dev, and sets the
INSTALL_DEV_DEPS build argument so the Dockerfile installs the dev extra (ruff, pyright,
pre-commit, django-debug-toolbar, pyinstrument) inside the image. Production builds don't
set this argument, so deployed images stay lean.
This file is gitignored, so it won't be created for you — you need to add it yourself, with the following contents:
services:
bot:
command: python3 -m ballsdex --dev --debug
environment:
- "DJANGO_SETTINGS_MODULE=admin_panel.settings.dev"
build:
args:
- "INSTALL_DEV_DEPS=1"
admin-panel:
environment:
- "DJANGO_SETTINGS_MODULE=admin_panel.settings.dev"
build:
args:
- "INSTALL_DEV_DEPS=1"
migration:
build:
args:
- "INSTALL_DEV_DEPS=1"You can then run tooling inside the containers, for example:
docker compose exec bot ruff check .
docker compose exec bot pyright .To have proper autocompletion and type checking, your IDE must be aware of your uv virtualenv.
You can configure your editor to use the uv virtual environment. Some editors like VS code may detect it automatically when picking versions.
You can also install extensions to work with ruff and pyright (Pylance for VS code).
Their configurations are already written in pyproject.toml, so it should work as-is.
If you are modifying model definitions in admin_panel/bd_models/models.py, you need migrations
to update the database schema.
From the admin_panel directory, run uv run python manage.py makemigrations bd_models to
generate a migration file. Re-read its contents to ensure there is only what you modified, and
commit it.
You can read more about migrations here, the engine is very extensive!
The code is formatted and linted by ruff, and static checked by pyright.
They can be setup as a pre-commit hook to make them run before committing files:
pre-commit installYou can also run them manually:
pre-commit run -aAll rules are defined in pyproject.toml, meaning your editor will pick them up if you install
the right tools.