It's yesterday once more

This is a Makefile for fastapi backend:

help:
	@echo  "Mech3D development makefile"
	@echo
	@echo  "Usage: make <target>"
	@echo  "Targets:"
	@echo  "    up      Updates dev/test dependencies"
	@echo  "    deps    Ensure dev/test dependencies are installed"
	@echo  "    check   Checks that build is sane"
	@echo  "    test    Runs all tests"
	@echo  "    style   Auto-formats the code"
	@echo  "    lint    Auto-formats the code and check type hints"
	@echo  "    venv    Create virtual environment with user friendly prompt"
	@echo  "    playboy git pull&&uv sync --no-dev&&supervisorctl restart"
	@echo  "    deploy  Use playboy to deploy and show latest git log"
	@echo  "    makemigrations  Similar like Django's python manage.py makemigrations"
	@echo  "    migrate         Similar like Django's python manage.py migrate"
	@echo  "    showmigrations  Similar like Django's python manage.py showmigrations"

up:
	uv lock --upgrade --verbose

lock:
	uv lock

sync:
	uv sync --frozen --no-python-downloads --inexact --no-install-project $(options)

prod:
	$(MAKE) sync options=--no-dev

deps:
	@echo "Installing deps by uv ..."
	$(MAKE) sync options="--all-extras --all-groups"

_check:
	@echo "--> fast check"
	@uv run fast check
check: deps _build _check

_lint:
	uv run fast lint
lint: deps _build _lint

_test:
	uv run fast test
test: deps _test

_style:
	uv run fast lint --skip-mypy
style: deps _style

_build:
	# uv build
	@echo Skip as not distribution.
build: deps _build

dev:
	uv run python app/main.py

venv:
ifeq ($(wildcard .venv),)
	uv venv --prompt Mech3D-3.12
	$(MAKE) deps
else
	@echo './.venv' exists, skip virtual environment creating.
	uv pip list
	@echo '---------------------------------'
	pdm list --tree
	pdm run python -V
endif

message = Update
# Usage::
# 	make migrations message="Add phone to User"
makemigrations:
	uv run alembic revision --autogenerate -m "$(message)"

migrate:
	uv run alembic upgrade heads

showmigrations:
	uv run alembic history
	@echo -----------------------------------------
	ls app/alembic/versions

status:
	supervisorctl status

backend_services = mech

restart:
	supervisorctl restart $(backend_services)

stop:
	supervisorctl stop $(backend_services)

inspect:
	$(MAKE) stop
	uv run python app/main.py --prod

playboy:
	git pull
	$(MAKE) prod
	$(MAKE) restart
	$(MAKE) status

deploy:
	git log -1|grep ''
	$(MAKE) playboy
	git log -1|grep ''
posted @ 2025-08-04 22:59  waketzheng  阅读(8)  评论(0)    收藏  举报