forked from aboutcode-org/dejacode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
192 lines (160 loc) · 6.22 KB
/
Copy pathMakefile
File metadata and controls
192 lines (160 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# DejaCode is a trademark of nexB Inc.
# SPDX-License-Identifier: AGPL-3.0-only
# See https://github.com/aboutcode-org/dejacode for support or download.
# See https://aboutcode.org for more information about AboutCode FOSS projects.
#
########################################################################################
# Docker dev commands
########################################################################################
IMAGE_NAME=dejacode:dev
COMPOSE=docker compose -f compose.dev.yml
MANAGE=${COMPOSE} exec web ./manage.py
EXEC=${COMPOSE} exec
run:
@echo "-> Run the Docker compose services in dev mode (hot reload on code changes)"
${COMPOSE} up
start:
@echo "-> Start the Docker compose services in background"
${COMPOSE} up -d
# make logs TAIL=100 SERVICE=db
logs:
${COMPOSE} logs -f --tail=${TAIL:-50} ${SERVICE}
bash:
# Open a bash session in the running web container
${COMPOSE} exec web bash
shell:
# Open a bash session in a standalone container (no stack required)
docker run -it $(IMAGE_NAME) bash
# make test - full suite
# make test k=<pattern> - filter by name, e.g. make test k=test_name
test:
${MANAGE} test --noinput --parallel auto $(if $(k),-k $(k),)
migrations:
@echo "-> Creates new database migrations"
${MANAGE} makemigrations
migrate:
@echo "-> Apply database migrations"
${MANAGE} migrate
build:
@echo "-> Build the dev Docker images"
${COMPOSE} build
superuser:
${MANAGE} createsuperuser
########################################################################################
# Linters / docs
########################################################################################
DOCS_LOCATION=./docs
doc8:
@echo "-> Run documentation .rst validation"
uvx doc8==2.0.0 --max-line-length 100 --ignore-path docs/_build/ --quiet docs/
valid:
@echo "-> Run Ruff format"
uvx ruff format
@echo "-> Run Ruff linter"
uvx ruff check --fix
check:
@echo "-> Run Ruff linter validation (pycodestyle, bandit, isort, and more)"
uvx ruff check
@echo "-> Run Ruff format validation"
uvx ruff format --check
@$(MAKE) doc8
docs:
@echo "-> Builds the documentation"
rm -rf ${DOCS_LOCATION}/_build/
uvx --from sphinx==9.1.0 --with furo==2025.12.19 sphinx-build -b singlehtml ${DOCS_LOCATION} ${DOCS_LOCATION}/_build/singlehtml/
uvx --from sphinx==9.1.0 --with furo==2025.12.19 sphinx-build -b html ${DOCS_LOCATION} ${DOCS_LOCATION}/_build/html/
########################################################################################
# Utilities
########################################################################################
outdated:
@echo "-> Check for outdated packages (with 7 days cooldown)"
uv sync --frozen --quiet
uv pip list --outdated \
--no-config \
--index-url https://pypi.org/simple \
--exclude-newer "7 days"
@echo "-> Audit the project's dependencies for known vulnerabilities"
uv audit
upgrade:
@if [ -z "$(PACKAGE)" ]; then \
echo "Usage: make upgrade PACKAGE=django==x.x.x"; \
exit 1; \
fi
@echo "-> Download $(PACKAGE) wheels for Linux x86_64"
uvx pip download $(PACKAGE) \
--only-binary=:all: \
--platform manylinux_2_28_x86_64 \
--platform manylinux_2_17_x86_64 \
--python-version 3.14 \
--dest ./thirdparty/dist/
@echo "-> Download $(PACKAGE) wheels for macOS ARM64"
uvx pip download $(PACKAGE) \
--only-binary=:all: \
--platform macosx_11_0_arm64 \
--python-version 3.14 \
--dest ./thirdparty/dist/
@echo "-> Update pyproject.toml and uv.lock"
uvx uv add $(PACKAGE)
lock:
@echo "-> Regenerate uv.lock from local wheels"
uv lock
clean:
@echo "-> Clean the Python env"
rm -rf .venv/ .*_cache/ *.egg-info/ build/ dist/
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete
########################################################################################
# Local venv commands (legacy)
########################################################################################
VENV_LOCATION=.venv
ACTIVATE?=. ${VENV_LOCATION}/bin/activate;
#MANAGE=${VENV_LOCATION}/bin/python manage.py
# Do not depend on Python to generate the SECRET_KEY
GET_SECRET_KEY=`head -c50 /dev/urandom | base64 | head -c50`
# Customize with `$ make envfile ENV_FILE=/etc/dejacode/.env`
ENV_FILE=.env
DOCKER_COMPOSE=docker compose -f docker-compose.yml
DOCKER_EXEC=${DOCKER_COMPOSE} exec
DB_NAME=dejacode_db
DB_USERNAME=dejacode
DB_PASSWORD=dejacode
DB_CONTAINER_NAME=db
DB_INIT_FILE=./data/postgresql/initdb.sql.gz
POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8
TIMESTAMP=$(shell date +"%Y-%m-%d_%H%M")
conf: virtualenv
@echo "-> Install dependencies"
uv sync --frozen
@echo "-> Create the var/ directory"
@mkdir -p var
dev: virtualenv
@echo "-> Configure and install development dependencies"
uv sync --frozen --extra dev
envfile:
@echo "-> Create the .env file and generate a secret key"
@if test -f ${ENV_FILE}; then echo "${ENV_FILE} file exists already"; exit 1; fi
@mkdir -p $(shell dirname ${ENV_FILE}) && touch ${ENV_FILE}
@echo SECRET_KEY=\"${GET_SECRET_KEY}\" > ${ENV_FILE}
envfile_dev: envfile
@echo "-> Update the .env file for development"
@echo DATABASE_PASSWORD=\"dejacode\" >> ${ENV_FILE}
initdb:
@echo "-> Stop Docker services that access the database"
${DOCKER_COMPOSE} stop web worker
@echo "-> Ensure the db Docker service is started"
${DOCKER_COMPOSE} start db
@echo "-> Rename the current ${DB_NAME} database as backup"
${DOCKER_EXEC} --no-TTY ${DB_CONTAINER_NAME} psql --username=${DB_USERNAME} postgres \
--command='ALTER DATABASE ${DB_NAME} RENAME TO "${DB_NAME}_${TIMESTAMP}"'
@echo "-> Create the ${DB_NAME} database"
${DOCKER_EXEC} --no-TTY ${DB_CONTAINER_NAME} \
createdb --username=${DB_USERNAME} --encoding=utf-8 --owner=dejacode ${DB_NAME}
echo "-> Loading initial data"
gunzip < ${DB_INIT_FILE} | ${DOCKER_EXEC} --no-TTY ${DB_CONTAINER_NAME} \
psql --username=${DB_USERNAME} ${DB_NAME}
@echo "Starting Docker services"
${DOCKER_COMPOSE} start
psql:
${DOCKER_EXEC} ${DB_CONTAINER_NAME} psql --username=${DB_USERNAME} postgres
.PHONY: virtualenv conf dev lock upgrade envfile envfile_dev check outdated doc8 valid clean initdb postgresdb postgresdb_clean migrate run test docs build psql bash shell logs start superuser