-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
207 lines (179 loc) Β· 6.62 KB
/
Makefile
File metadata and controls
207 lines (179 loc) Β· 6.62 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Variables
VENV_PATH := .venv/bin
SYSTEM_PYTHON := python3
PYTHON := $(VENV_PATH)/python3
PIP := $(VENV_PATH)/pip
PIP_COMPILE := $(VENV_PATH)/pip-compile
RUFF := $(VENV_PATH)/ruff
PYTEST := $(VENV_PATH)/pytest
TWINE := $(VENV_PATH)/twine
BANDIT := $(VENV_PATH)/bandit
PRECOMMIT := $(VENV_PATH)/pre-commit
PCU := $(VENV_PATH)/pcu
DOCKER := docker
VERSION := $(strip $(shell cat VERSION))
# Default target (runs when you just type "make")
.PHONY: all
all: lock install upgrade lint test build
# --- Dependency Management ---
.PHONY: venv
venv:
@echo "π Creating virtual environment..."
$(SYSTEM_PYTHON) -m venv .venv
@. ./.venv/bin/activate
@echo "β
virtual environment created."
# Lock: Generates requirements.txt from pyproject.toml
.PHONY: lock
lock:
@echo "π Locking dependencies..."
$(PIP_COMPILE) -o requirements.txt pyproject.toml --resolver=backtracking
@echo "β
requirements.txt generated."
# Upgrade: Updates all packages to the latest allowed versions
.PHONY: upgrade
upgrade:
@echo "β¬οΈ Upgrading dependencies..."
$(PIP_COMPILE) --upgrade -o requirements.txt pyproject.toml --resolver=backtracking
@echo "β
requirements.txt upgraded."
# Install: Syncs environment with locked deps and installs the app
.PHONY: install
install:
@echo "π¦ Installing dependencies..."
$(PIP) install -r requirements.txt
$(PIP) install -e ".[dev]"
@echo "β
Environment synced."
# Setup: Installs dependencies and sets up git hooks
.PHONY: setup
setup: install
@echo "πͺ Installing Git hooks..."
$(PRECOMMIT) install
@echo "β
Setup complete."
# Outdated: Checks for newer versions of dependencies
.PHONY: outdated
outdated:
@echo "π Checking for newer versions of dependencies..."
$(PCU) pyproject.toml -t latest --extra dev --fail_on_update
@echo "β
Dependency outdated check passed."
# compatibility: Checks each dependencies for python version compatibility
.PHONY: compatibility
compatibility:
@echo "π Checking dependencies for python version compatibility..."
ifdef py_version
$(PYTHON) check_compatibility.py $(py_version)
else
$(PYTHON) check_compatibility.py
endif
@echo "β
Compatibility check done."
# PIP Upgrade: upgrade PIP to its latest version
.PHONY: pip-upgrade
pip-upgrade:
@echo "β¬οΈ Upgrading pip..."
$(PIP) install --upgrade pip
@echo "β
pip upgraded."
# --- Quality Assurance (Linting & Testing) ---
# Lint: Checks code style without modifying files
.PHONY: lint
lint:
@echo "π Linting code..."
$(RUFF) check .
$(RUFF) format --check .
@echo "β
Lint check passed."
# Format: Automatically fixes code style issues
.PHONY: format
format:
@echo "π
Formatting code..."
$(RUFF) check --fix .
$(RUFF) format .
@echo "β
Code formatted."
# Security: Runs bandit to check for vulnerabilities
.PHONY: security
security:
@echo "π‘οΈ Running security scan..."
# -c: configuration file, -r: recursive
$(BANDIT) -c pyproject.toml -r .
@echo "β
Security scan passed."
# Test: Runs the unit/integration tests
.PHONY: test
test: security
@echo "π§ͺ Running tests..."
$(PYTEST)
# SBOM: Generates Software Bill of Materials in CycloneDX JSON format
.PHONY: sbom
sbom: install
@echo "π Generating SBOM..."
$(VENV_PATH)/cyclonedx-py requirements requirements.txt -o sbom.json
@echo "β
SBOM generated as sbom.json"
# Audit: Generates security audit report in JSON format
.PHONY: audit
audit: install
@echo "π Running security audit..."
$(VENV_PATH)/pip-audit -r requirements.txt --format=cyclonedx-json --output=audit.json
@echo "β
Security audit saved as audit.json"
# --- Packaging & Publishing ---
# Build: Creates the distribution files (Wheel & Tarball)
.PHONY: build
build: clean install
@echo "ποΈ Building package..."
$(PIP) install build
$(PYTHON) -m build
@echo "β
Build complete. Artifacts in dist/"
# Docker Build: Creates the Docker image
.PHONY: docker-build
docker-build: build
@echo "ποΈ Building the Docker image..."
$(DOCKER) build -t my-lib-client:$(VERSION) .
@echo "β
Docker build complete."
# Docker Run: Runs the Docker container
.PHONY: docker-run
docker-run:
@echo "π Running the Docker container..."
$(DOCKER) run --rm my-lib-client:$(VERSION)
@echo "β
Docker container stopped."
# Docker Build Lambda: Creates the Lambda Docker image
.PHONY: docker-build-lambda
docker-build-lambda: build
@echo "ποΈ Building the Lambda Docker image..."
$(DOCKER) build -f Dockerfile.lambda -t my-lib-lambda:$(VERSION) .
@echo "β
Docker build complete."
# Docker Run Lambda: Runs the Lambda Docker container
.PHONY: docker-run-lambda
docker-run-lambda:
@echo "π Running the Lambda Docker container..."
$(DOCKER) run --rm -p 9000:8080 my-lib-lambda:$(VERSION)
@echo "β
Docker container stopped."
# Docker Run Lambda: Runs the Lambda Docker container
.PHONY: lambda-invoke
lambda-invoke:
@echo "βΆ Invoking the Lambda function..."
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"body": "{\"operation\": \"add\", \"a\": \"2\", \"b\": \"3\"}"}' | jq
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"body": "{\"operation\": \"add\", \"a\": \"2\"}"}' | jq
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"body": "{\"operation\": \"divide\", \"a\": \"3\", \"b\": \"2\"}"}' | jq
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"body": "{\"operation\": \"divide\", \"b\": \"2\"}"}' | jq
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"body": "{\"operation\": \"divide\", \"a\": \"3\", \"b\": \"0\"}"}' | jq
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"body": "{\"a\": \"3\", \"b\": \"2\"}"}' | jq
@echo "β
Done."
# Publish: Uploads artifacts to the repository
# Usage: make publish repo=nexus
.PHONY: publish
publish: build
@echo "π Publishing to repository..."
# If 'repo' arg is provided, use it; otherwise default to standard upload
ifdef repo
$(TWINE) upload --repository $(repo) dist/* --verbose > twine-publish.log 2>&1
else
$(TWINE) upload dist/* --verbose > twine-publish.log 2>&1
endif
@echo "β
Published successfully."
# --- Utilities ---
Docs: Generates documentation from docstrings in Markdown format
.PHONY: docs
docs: install
@echo "π Generating documentation..."
$(VENV_PATH)/pdoc -o docs src/my_lib src/my_lib/config
@echo "β
Documentation generated in docs/ directory"
# Clean: Removes build artifacts and caches
.PHONY: clean
clean:
@echo "π§Ή Cleaning up..."
rm -rf docs/ dist/ build/ *.egg-info src/*.egg-info .pytest_cache .coverage test/.coverage .ruff_cache
find . -type d -name __pycache__ -exec rm -r {} +
@echo "β
Clean complete."