-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathMakefile
186 lines (153 loc) · 5.52 KB
/
Makefile
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
### Defensive settings for make:
# https://tech.davis-hansson.com/p/make/
SHELL:=bash
.ONESHELL:
.SHELLFLAGS:=-xeu -o pipefail -O inherit_errexit -c
.SILENT:
.DELETE_ON_ERROR:
MAKEFLAGS+=--warn-undefined-variables
MAKEFLAGS+=--no-builtin-rules
# We like colors
# From: https://coderwall.com/p/izxssa/colored-makefile-for-golang-projects
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`
# Python checks
UV?=uv
# installed?
ifeq (, $(shell which $(UV) ))
$(error "UV=$(UV) not found in $(PATH)")
endif
BACKEND_FOLDER=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
ifdef PLONE_VERSION
PLONE_VERSION := $(PLONE_VERSION)
else
PLONE_VERSION := 6.1.1
endif
ifdef KEYCLOAK_VERSION
KEYCLOAK_VERSION := $(KEYCLOAK_VERSION)
else
KEYCLOAK_VERSION := 22.0.0
endif
VENV_FOLDER=$(BACKEND_FOLDER)/.venv
BIN_FOLDER=$(VENV_FOLDER)/bin
TESTS_FOLDER=$(BACKEND_FOLDER)/tests
# Environment variables to be exported
export PYTHONWARNINGS := ignore
export DOCKER_BUILDKIT := 1
export KEYCLOAK_VERSION := $(KEYCLOAK_VERSION)
all: build
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
.PHONY: help
help: ## This help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
############################################
# Config
############################################
instance/etc/zope.ini instance/etc/zope.conf: ## Create instance configuration
@echo "$(GREEN)==> Create instance configuration$(RESET)"
@uvx cookiecutter -f --no-input -c 2.1.1 --config-file instance.yaml gh:plone/cookiecutter-zope-instance
.PHONY: config
config: instance/etc/zope.ini
############################################
# Installation
############################################
requirements-mxdev.txt: ## Generate constraints file
@echo "$(GREEN)==> Generate constraints file$(RESET)"
@echo '-c https://dist.plone.org/release/$(PLONE_VERSION)/constraints.txt' > requirements.txt
@uvx mxdev -c mx.ini
$(VENV_FOLDER): requirements-mxdev.txt ## Install dependencies
@echo "$(GREEN)==> Install environment$(RESET)"
@uv venv $(VENV_FOLDER)
@uv pip install -r requirements-mxdev.txt
.PHONY: sync
sync: $(VENV_FOLDER) ## Sync project dependencies
@echo "$(GREEN)==> Sync project dependencies$(RESET)"
@uv pip install -r requirements-mxdev.txt
.PHONY: install
install: $(VENV_FOLDER) config ## Install Plone and dependencies
.PHONY: clean
clean: ## Clean installation and instance
@echo "$(RED)==> Cleaning environment and build$(RESET)"
@rm -rf $(VENV_FOLDER) pyvenv.cfg .installed.cfg instance .venv .pytest_cache .ruff_cache constraints* requirements*
$(MAKE) -C "./docs" clean
############################################
# Instance
############################################
.PHONY: remove-data
remove-data: ## Remove all content
@echo "$(RED)==> Removing all content$(RESET)"
rm -rf $(VENV_FOLDER) instance/var
.PHONY: start
start: $(VENV_FOLDER) instance/etc/zope.ini ## Start a Plone instance on localhost:8080
@uv run runwsgi instance/etc/zope.ini
.PHONY: console
console: $(VENV_FOLDER) instance/etc/zope.ini ## Start a console into a Plone instance
@uv run zconsole debug instance/etc/zope.conf
.PHONY: create-site
create-site: $(VENV_FOLDER) instance/etc/zope.ini ## Create a new site from scratch
@uv run zconsole run instance/etc/zope.conf ./scripts/create_site.py
###########################################
# Docs
###########################################
.PHONY: docs-install
docs-install: ## Install documentation dependencies
$(MAKE) -C "./docs/" install
.PHONY: docs-build
docs-build: ## Build documentation
$(MAKE) -C "./docs/" html
.PHONY: docs-live
docs-live: ## Rebuild documentation on changes, with live-reload in the browser
$(MAKE) -C "./docs/" livehtml
############################################
# QA
############################################
.PHONY: lint
lint: ## Check and fix code base according to Plone standards
@echo "$(GREEN)==> Lint codebase$(RESET)"
@uvx ruff@latest check --fix --config $(BACKEND_FOLDER)/pyproject.toml
@uvx pyroma@latest -d .
@uvx check-python-versions@latest .
@uvx zpretty@latest --check src
.PHONY: format
format: ## Check and fix code base according to Plone standards
@echo "$(GREEN)==> Format codebase$(RESET)"
@uvx ruff@latest check --select I --fix --config $(BACKEND_FOLDER)/pyproject.toml
@uvx ruff@latest format --config $(BACKEND_FOLDER)/pyproject.toml
@uvx zpretty@latest -i src
.PHONY: check
check: format lint ## Check and fix code base according to Plone standards
############################################
# i18n
############################################
.PHONY: i18n
i18n: $(VENV_FOLDER) ## Update locales
@echo "$(GREEN)==> Updating locales$(RESET)"
@uv run python -m pas.plugins.authomatic.locales
############################################
# Tests
############################################
.PHONY: test
test: $(VENV_FOLDER) ## run tests
@uv run pytest
.PHONY: test-coverage
test-coverage: $(VENV_FOLDER) ## run tests with coverage
@uv run pytest --cov=pas.plugins.authomatic --cov-report term-missing
############################################
# Release
############################################
.PHONY: changelog
changelog: ## Release the package to pypi.org
@echo "🚀 Display the draft for the changelog"
@uv run towncrier --draft
.PHONY: release
release: ## Release the package to pypi.org
@echo "🚀 Release package"
@uv run prerelease
@uv run release
@rm -Rf dist
@uv build
@uv publish
@uv run postrelease