It's yesterday once more

江山如此多娇 玉人何处教吹箫

Updated At 2025-11-30 Would rather to use justfile instead:

#!/usr/bin/env -S just --justfile
# ^ A shebang isn't required, but allows a justfile to be executed
#   like a script, with `./justfile lint`, for example.

# NOTE: You can run the following command to install `just`:
#   uv tool install rust-just

system-info:
    @echo "This is an {{arch()}} machine running on {{os_family()}}"
    just --list

# Use powershell for Windows so that 'Git Bash' and 'PyCharm Terminal' get the same result
set windows-powershell := true
VENV_CREATE := "pdm venv create"
UV_PIP := "uv pip"
UV_PIP_I := UV_PIP + " install"
UV_PIP_L := UV_PIP + " list"
UV_SYNC := "uv sync --all-extras"
UV_PROD := UV_SYNC + " --no-dev"
UV_DEPS := UV_SYNC + " --all-groups"
PDM_SYNC := "pdm install --frozen"
PDM_PROD := PDM_SYNC + " --prod"
PDM_DEPS := PDM_SYNC + " -G :all"
PROD_DEPS := if os_family() == "windows" { PDM_PROD } else { UV_PROD }
INSTALL_DEPS := if os_family() == "windows" { PDM_DEPS } else { UV_DEPS }
BIN_DIR := if os_family() == "windows" { "Scripts" } else { "bin" }
WARN_OS := "echo 'WARNING: This command only support Linux!'"

[unix]
venv *args:
    @if test ! -e .venv; then {{ VENV_CREATE }} --with uv {{ args }}; fi
[windows]
venv *args:
    @if (-Not (Test-Path '.venv')) { {{ VENV_CREATE }} --with-pip {{ args }} }

venv313:
    {{ VENV_CREATE }} 3.13

deps *args: venv
    {{ INSTALL_DEPS }} {{args}}

_lock *args:
    uv lock {{args}}
    @just deps --frozen

[unix]
lock *args:
    @just _lock {{args}}
[windows]
lock *args:
    @if (-Not (Test-Path 'pdm.lock')) { just _lock {{args}} } else { pdm update -G :all --update-all }

up:
    @just lock --upgrade --verbose

_clear *args:
    uv sync --all-extras --all-groups {{args}}

[unix]
clear *args:
    @just _clear {{args}}
[windows]
clear *args:
    @if (-Not (Test-Path 'pdm.lock')) { just _clear {{args}}  } else { pdm sync -G :all --clean {{args}} }

run *args: venv
    .venv/{{BIN_DIR}}/{{args}}

_lint *args:
    pdm run fast lint {{args}}

lint *args: deps
    @just _lint {{args}}

fmt *args:
    @just _lint --skip-mypy {{args}}

alias _style := fmt

style *args: deps
    @just fmt {{args}}

_check *args:
    pdm run fast check {{args}}

check *args: deps
    @just _check {{args}}

_build *args:
    pdm build {{args}}

build *args: deps
    @just _build {{args}}

_test *args:
    pdm run fast test {{args}}

test *args: deps
    @just _test {{args}}

prod *args: venv
    {{ PROD_DEPS }} {{args}}

[unix]
pipi *args: venv
    {{ UV_PIP_I }} {{args}}
[windows]
pipi *args: venv
    @if (-Not (Test-Path '.venv/Scripts/pip.exe')) { UV_PIP_I {{args}} } else { @just run pip install {{args}} }

install_me:
    @just pipi -e .

start:
    pre-commit install
    @just deps

version part="patch":
    pdm run fast bump {{part}}

bump *args:
    pdm run fast bump patch --commit {{args}}

tag *args:
    pdm run fast tag {{args}}

release: venv bump tag
    git log -1

Before updated:

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  阅读(9)  评论(0)    收藏  举报