-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
173 lines (145 loc) · 6.34 KB
/
Makefile
File metadata and controls
173 lines (145 loc) · 6.34 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
VENV := .venv
PYTHON := $(VENV)/bin/python
PYBABEL := $(VENV)/bin/pybabel
PIP := $(VENV)/bin/pip
PIP_SYNC := $(VENV)/bin/pip-sync
PIP_COMPILE := $(VENV)/bin/pip-compile
TOX := $(VENV)/bin/tox
RUFF := $(VENV)/bin/ruff
MYPY := $(VENV)/bin/mypy
PODMAN := /usr/bin/podman
# Frontend paths and commands
FRONTEND_DIR := src/whatsthedamage/view/frontend
NPM := npm
NPM_RUN := $(NPM) run
DOCKER_IMAGE := whatsthedamage
DOCKER_TAG ?= $(shell set -o pipefail; python3 -m setuptools_scm 2>/dev/null | sed 's/\+/_/' || echo "latest")
VERSION ?= $(shell set -o pipefail; python3 -m setuptools_scm 2>/dev/null || echo "v0.0.0")
.PHONY: web test lint lang clean mrproper image compile-deps update-deps compile-deps-secure help docs build frontend
# =============================================================================
# DEVELOPMENT TARGETS
# =============================================================================
# Frontend development
# Unified frontend interface - runs any npm script
# Usage: make frontend ARG=script-name
frontend:
@if ! command -v $(NPM) >/dev/null 2>&1; then \
echo "npm is not installed. Please install Node.js and npm first."; \
exit 1; \
fi
cd $(FRONTEND_DIR) && $(NPM_RUN) $(ARG)
# Combined build
build: dev
$(MAKE) frontend ARG=build
# Ensure build depends on dev being up to date
build: $(VENV)/.deps-synced $(FRONTEND_DIR)/node_modules/.installed
# Create venv and install pip-tools
$(VENV)/pyvenv.cfg:
python3 -m venv $(VENV) || { echo "Failed to create virtual environment"; exit 1; }
$(PIP) install --upgrade pip || { echo "Failed to upgrade pip"; exit 1; }
$(PIP) install pip-tools || { echo "Failed to install pip-tools"; exit 1; }
# Track when dependencies were last synced
$(VENV)/.deps-synced: requirements.txt requirements-dev.txt requirements-web.txt $(VENV)/pyvenv.cfg pyproject.toml
$(PIP_SYNC) requirements.txt requirements-dev.txt requirements-web.txt || { echo "Failed to sync dependencies"; exit 1; }
$(PIP) install -e . || { echo "Failed to install package"; exit 1; }
touch $(VENV)/.deps-synced
# Track when frontend dependencies were last installed
$(FRONTEND_DIR)/node_modules/.installed: $(FRONTEND_DIR)/package.json $(FRONTEND_DIR)/package-lock.json
@if ! command -v $(NPM) >/dev/null 2>&1; then \
echo "npm is not installed. Please install Node.js and npm first."; \
exit 1; \
fi
cd $(FRONTEND_DIR) && $(NPM) install
touch $@
# Set up development environment
dev: $(VENV)/.deps-synced $(FRONTEND_DIR)/node_modules/.installed
# Run Flask development server
web: dev $(FRONTEND_DIR)/node_modules/.installed
$(MAKE) frontend ARG=build
FLASK_APP=src.whatsthedamage.app $(PYTHON) -m flask run
# Run tests using tox
test: dev
$(TOX)
$(MAKE) frontend ARG=test
# Run linter/formatter
lint: dev
$(TOX) -e lint
$(TOX) -e type
lang: dev
$(PYBABEL) extract -F babel.cfg -o src/whatsthedamage/locale/en/LC_MESSAGES/messages.pot src/whatsthedamage/
# Build Sphinx documentation
docs:
$(PYTHON) $(VENV)/bin/sphinx-apidoc -f -M -T -o docs/ src/
SPHINXBUILD=../$(VENV)/bin/sphinx-build $(MAKE) -C docs clean html
# =============================================================================
# PODMAN TARGETS
# =============================================================================
# Build Podman image with version tag
image:
@echo "Building Podman image with version: $(VERSION)"
$(PODMAN) build --build-arg VERSION=$(VERSION) --format docker -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
# =============================================================================
# DEPENDENCY MANAGEMENT
# =============================================================================
# Compile all requirements files from pyproject.toml
compile-deps: $(VENV)/pyvenv.cfg
$(PIP_COMPILE) pyproject.toml
$(PIP_COMPILE) --extra=dev pyproject.toml -o requirements-dev.txt
$(PIP_COMPILE) --extra=web pyproject.toml -o requirements-web.txt
rm -f $(VENV)/.deps-synced
# Update all requirements (allow upgrades)
update-deps: $(VENV)/pyvenv.cfg
$(PIP_COMPILE) --upgrade pyproject.toml
$(PIP_COMPILE) --upgrade --extra=dev pyproject.toml -o requirements-dev.txt
$(PIP_COMPILE) --upgrade --extra=web pyproject.toml -o requirements-web.txt
rm -f $(VENV)/.deps-synced
# Generate with hashes for security
compile-deps-secure: $(VENV)/pyvenv.cfg
$(PIP_COMPILE) --generate-hashes pyproject.toml
$(PIP_COMPILE) --generate-hashes --extra=dev pyproject.toml -o requirements-dev.txt
$(PIP_COMPILE) --generate-hashes --extra=web pyproject.toml -o requirements-web.txt
rm -f $(VENV)/.deps-synced
# =============================================================================
# CLEANUP TARGETS
# =============================================================================
# Clean up generated files
clean:
rm -rf build/
rm -rf dist/
rm -rf *.egg-info/
rm -rf .tox/
rm -rf .pytest_cache/
rm -rf .mypy_cache/
rm -rf .ruff_cache/
rm -rf .coverage*
find . -type f -name "*.pyc" -delete
find . -type d -name __pycache__ -delete
rm -rf $(FRONTEND_DIR)/../static/dist/
# Deep clean including virtual environment
mrproper: clean
rm -rf $(VENV)
rm -rf $(FRONTEND_DIR)/node_modules/
# =============================================================================
# HELP
# =============================================================================
# Help target
help:
@echo "Development workflow:"
@echo " dev - Create venv, install pip-tools, sync all requirements, install frontend dependencies"
@echo " web - Run Flask development server (requires frontend build)"
@echo " test - Run tests using tox"
@echo " lint - Run linter/formatter on Python code"
@echo " image - Build Podman image with version tag"
@echo " lang - Extract translatable strings to English .pot file"
@echo " docs - Build Sphinx documentation"
@echo " frontend ARG=script - Run any npm script (e.g., 'frontend ARG=dev', 'frontend ARG=build')"
@echo " build - Full stack build (Python + JS)"
@echo ""
@echo "Dependency management for Python:"
@echo " compile-deps - Compile requirements files from pyproject.toml"
@echo " update-deps - Update requirements to latest versions"
@echo " compile-deps-secure - Compile requirements with security hashes"
@echo ""
@echo "Cleanup for Python and JavaScript:"
@echo " clean - Clean up build files"
@echo " mrproper - Clean + remove virtual environment, node_modules"