| 1 |
--- |
| 2 |
title: Makefile Commands |
| 3 |
description: How to use the Makefile commands for building, testing, and development tasks. |
| 4 |
--- |
| 5 |
|
| 6 |
# Makefile Commands |
| 7 |
|
| 8 |
Django Guardian includes a Makefile that wraps the repository's standard `uv`-based workflow. The targets are convenience aliases for the commands documented in `CONTRIBUTING.md`, `pyproject.toml`, and `tox.ini`. |
| 9 |
|
| 10 |
## Prerequisites |
| 11 |
|
| 12 |
Before using the Makefile commands, ensure you have: |
| 13 |
|
| 14 |
- `uv` package manager installed |
| 15 |
- Synced the development environment (`uv sync --group dev`) |
| 16 |
|
| 17 |
Because the Makefile uses `uv run`, you do **not** need to activate a virtual environment manually. |
| 18 |
|
| 19 |
## Available Commands |
| 20 |
|
| 21 |
To see all available commands with descriptions: |
| 22 |
|
| 23 |
```shell |
| 24 |
make help |
| 25 |
``` |
| 26 |
|
| 27 |
This will display: |
| 28 |
|
| 29 |
``` |
| 30 |
Available commands: |
| 31 |
build - Build the package |
| 32 |
pytest - Run tests with pytest |
| 33 |
test - Alias for pytest |
| 34 |
test-all - Run the full tox matrix |
| 35 |
clean - Clean build artifacts |
| 36 |
install - Sync project dependencies |
| 37 |
dev-install - Sync project with development dependencies |
| 38 |
lint - Run linting checks |
| 39 |
format - Apply Ruff fixes and format code |
| 40 |
docs - Build documentation |
| 41 |
docs-serve - Serve documentation locally |
| 42 |
check - Run lint, tests, and docs build |
| 43 |
``` |
| 44 |
|
| 45 |
## Core Commands |
| 46 |
|
| 47 |
### Building the Package |
| 48 |
|
| 49 |
To build the django-guardian package (creates both source distribution and wheel): |
| 50 |
|
| 51 |
```shell |
| 52 |
make build |
| 53 |
``` |
| 54 |
|
| 55 |
This command uses `uv build` to create distribution files in the `dist/` directory. |
| 56 |
|
| 57 |
### Running Tests |
| 58 |
|
| 59 |
To run the test suite with pytest and coverage reporting: |
| 60 |
|
| 61 |
```shell |
| 62 |
make pytest |
| 63 |
``` |
| 64 |
|
| 65 |
Or use the alias: |
| 66 |
|
| 67 |
```shell |
| 68 |
make test |
| 69 |
``` |
| 70 |
|
| 71 |
This command runs pytest with coverage for the guardian module and generates both XML and terminal coverage reports. |
| 72 |
|
| 73 |
### Running the Full Matrix |
| 74 |
|
| 75 |
To run the full tox matrix defined in `tox.ini`: |
| 76 |
|
| 77 |
```shell |
| 78 |
make test-all |
| 79 |
``` |
| 80 |
|
| 81 |
This is equivalent to `uv run tox run`. |
| 82 |
|
| 83 |
## Development Commands |
| 84 |
|
| 85 |
### Installing Dependencies |
| 86 |
|
| 87 |
To install the package in development mode with all development dependencies: |
| 88 |
|
| 89 |
```shell |
| 90 |
make dev-install |
| 91 |
``` |
| 92 |
|
| 93 |
This target runs: |
| 94 |
|
| 95 |
```shell |
| 96 |
uv sync --group dev |
| 97 |
``` |
| 98 |
|
| 99 |
For a regular installation: |
| 100 |
|
| 101 |
```shell |
| 102 |
make install |
| 103 |
``` |
| 104 |
|
| 105 |
This target runs: |
| 106 |
|
| 107 |
```shell |
| 108 |
uv sync |
| 109 |
``` |
| 110 |
|
| 111 |
### Code Quality |
| 112 |
|
| 113 |
To run linting checks (ruff and mypy): |
| 114 |
|
| 115 |
```shell |
| 116 |
make lint |
| 117 |
``` |
| 118 |
|
| 119 |
To apply Ruff auto-fixes and then format the code: |
| 120 |
|
| 121 |
```shell |
| 122 |
make format |
| 123 |
``` |
| 124 |
|
| 125 |
### Documentation |
| 126 |
|
| 127 |
To build the documentation using mkdocs: |
| 128 |
|
| 129 |
```shell |
| 130 |
make docs |
| 131 |
``` |
| 132 |
|
| 133 |
To preview the documentation locally: |
| 134 |
|
| 135 |
```shell |
| 136 |
make docs-serve |
| 137 |
``` |
| 138 |
|
| 139 |
To run the most common local verification steps in sequence: |
| 140 |
|
| 141 |
```shell |
| 142 |
make check |
| 143 |
``` |
| 144 |
|
| 145 |
### Cleaning Build Artifacts |
| 146 |
|
| 147 |
To clean up build artifacts, distribution files, and cache: |
| 148 |
|
| 149 |
```shell |
| 150 |
make clean |
| 151 |
``` |
| 152 |
|
| 153 |
This removes: |
| 154 |
- `build/` directory |
| 155 |
- `dist/` directory |
| 156 |
- `*.egg-info/` directories |
| 157 |
- `.coverage` |
| 158 |
- `.mypy_cache/` |
| 159 |
- `.pytest_cache/` |
| 160 |
- `.ruff_cache/` |
| 161 |
- `.tox/` |
| 162 |
- `htmlcov/` |
| 163 |
- `__pycache__` directories |
| 164 |
- `.pyc` files |
| 165 |
|
| 166 |
## Usage Examples |
| 167 |
|
| 168 |
Here are some common development workflows using the Makefile: |
| 169 |
|
| 170 |
### Setting up for development: |
| 171 |
|
| 172 |
```shell |
| 173 |
make dev-install |
| 174 |
make test |
| 175 |
``` |
| 176 |
|
| 177 |
### Before committing changes: |
| 178 |
|
| 179 |
```shell |
| 180 |
make format |
| 181 |
make lint |
| 182 |
make test |
| 183 |
``` |
| 184 |
|
| 185 |
### Creating a release: |
| 186 |
|
| 187 |
```shell |
| 188 |
make clean |
| 189 |
make build |
| 190 |
``` |
| 191 |
|
| 192 |
### Full development cycle: |
| 193 |
|
| 194 |
```shell |
| 195 |
# Setup |
| 196 |
make dev-install |
| 197 |
|
| 198 |
# Development |
| 199 |
make format |
| 200 |
make lint |
| 201 |
make test |
| 202 |
|
| 203 |
# Build and documentation |
| 204 |
make build |
| 205 |
make docs |
| 206 |
|
| 207 |
# Cleanup |
| 208 |
make clean |
| 209 |
``` |
| 210 |
|
| 211 |
## Notes |
| 212 |
|
| 213 |
- All executable targets use the repository's managed `uv` environment. |
| 214 |
- `Makefile` is a convenience layer; `CONTRIBUTING.md`, `pyproject.toml`, and `tox.ini` remain the canonical sources of truth. |
| 215 |
- Coverage reports are generated automatically when running `make pytest` or `make test`. |