- Python + Django
- Versions (as of 10/11/22):
- Python version: 3.11.0
- Django version: 4.1.3
- Postgres version: 14.1
- Built with Docker and docker compose
- Scripts executable in the bin directory along with
just
- CI built for Github and Github Actions
- Reference file:
.github/workflows/ci.yml
- Reference file:
- Clone the repo
git clone git@github.com:vigetlabs/meal_planner.git
- Run the setup script to install pre-commit and set up the git hooks
bin/setup
- At any time, you can manually execute the hooks like this:
bin/lint
- If you want to skip the hooks, you can use the
--no-verify
flaggit commit --no-verify
- Run the project-specific commands (as needed)
just makemigrations just reset # etc.
- If the setup script did not correctly create an
.env
file, create one:cp .env.example .env
- Replace the variables in your
.env
file with the ones you got in the steps above.
If dependencies have changed, rebuild the containers with:
just rebuild
This should fix errors like, "No module named 'Some newly added package.'"
- To run the tests without coverage:
bin/test
- To run a single test file, just pass in the path, for example:
bin/test apps/core/tests/test_admin.py
- If you want to run the tests and open the coverage report in your browser, run:
bin/cov
bin/server
- You can now access the app at
localhost:8000
We need to create a superuser in order to access the admin.
just createsuperuser
- Use the CLI from above to create your user
- Go to
localhost:8000/admin
- Log in using that user to access the admin
This project contains some standard executables in the bin
directory. These are intended to be used in the development environment. They are not intended to be used in production.
bin/bootstrap
will install the python version and pip.bin/setup
will run the bootstrap script, create the.env
file from.env.example
, and set up the git hooks.bin/update
will rerun the boostrap script. Used mostly by other scripts, you will rarely run this.bin/server
will run the server.bin/lint
will lint all of the files using pre-commit.bin/test
will run the pytest test suite.bin/cov
will run the pytest test suite with coverage enabled and open the coverage file.bin/ci
will be used in CI to run the test suite, check for coverage, and fail if below 100%.
To make development a little easier, some common commands are set up as executables. The current available options are below. To view the commands in your terminal, run just -l
.
just shell
will open a shell_plus instance in your terminal.just makemigrations
will call the django makemigrations command, creating migrations file from changes to models.just migrate
will call unapplied migrations.just reset
will reset the database and rerun migrations.just rebuild
will rebuild the docker containers.just createsuperuser
will open a CLI for creating a django superuser.just bash
will open a bash shell into the docker container itself.
Since this project is run and built through Docker, there is a certain workflow for adding a dependency.
-
Open the particular requirement file
base.txt
,local.txt
,production.txt
depending on what your package does- For a package that will be used in all environments, add to
base.txt
. For things just used locally (debugging, testing), add tolocal.txt
. For production-only add toproduction.txt
- For a package that will be used in all environments, add to
-
Add the package name where it makes sense in the file
-
i.e. add a new line with
pytest-django==4.0.4
in the section of other django or pytest packages
-
-
Close any running backend containers
-
Rebuild the backend container
- This can be done in its own step
just rebuild
- This can be done in its own step
-
OPTIONAL: Bash into the container
just bash
-
and check that the package is installed
pip list --format=freeze
if you did not provide a package version, you should see the version number in the output. Please put this version number in the requirements file.