-
Notifications
You must be signed in to change notification settings - Fork 422
/
Makefile
155 lines (122 loc) · 5.88 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
SERVER_CONFIG = config/kinto.ini
SPHINX_BUILDDIR = docs/_build
VENV := $(shell echo $${VIRTUAL_ENV-.venv})
PYTHON = $(VENV)/bin/python3
DEV_STAMP = $(VENV)/.dev_env_installed.stamp
DOC_STAMP = $(VENV)/.doc_env_installed.stamp
INSTALL_STAMP = $(VENV)/.install.stamp
TEMPDIR := $(shell mktemp -du)
.IGNORE: clean distclean maintainer-clean
.PHONY: all install tests
OBJECTS = .venv .coverage
help:
@echo "Please use 'make <target>' where <target> is one of"
@echo " format reformat code"
@echo " install install dependencies and prepare environment"
@echo " install-monitoring enable monitoring features like StatsD and Newrelic"
@echo " install-postgres install postgresql support"
@echo " install-dev install dependencies and everything needed to run tests"
@echo " pull-kinto-admin pull the Kinto admin UI plugin (requires npm)"
@echo " serve start the kinto server on default port"
@echo " migrate run the kinto migrations"
@echo " lint run the code linters"
@echo " tests run all the tests with all the supported python interpreters (same as CI)"
@echo " test-deps pulls and runs docker postgres and memcached containers for tests"
@echo " tdd run pytest-watch to rerun tests automatically on changes for tdd"
@echo " tests-once only run the tests once with the default python interpreter"
@echo " functional run functional test against a real kinto"
@echo " browser-test run browser test against a real kinto"
@echo " clean remove *.pyc files and __pycache__ directory"
@echo " distclean remove *.egg-info files and *.egg, build and dist directories"
@echo " maintainer-clean remove the .venv directory"
@echo " docs build the docs"
@echo "Check the Makefile to know exactly what each target is doing."
all: install
install: $(INSTALL_STAMP)
$(INSTALL_STAMP): $(PYTHON) constraints.txt pyproject.toml
$(VENV)/bin/pip install -U pip
$(VENV)/bin/pip install -Ue . -c constraints.txt
touch $(INSTALL_STAMP)
$(PYTHON):
python3 -m venv $(VENV)
install-monitoring: $(INSTALL_STAMP) $(DEV_STAMP)
$(VENV)/bin/pip install -Ue ".[monitoring]" -c constraints.txt
install-postgres: $(INSTALL_STAMP) $(DEV_STAMP)
$(VENV)/bin/pip install -Ue ".[postgresql]" -c constraints.txt
install-memcached: $(INSTALL_STAMP) $(DEV_STAMP)
$(VENV)/bin/pip install -Ue ".[memcached]" -c constraints.txt
install-dev: $(INSTALL_STAMP) $(DEV_STAMP)
$(DEV_STAMP): $(PYTHON) constraints.txt
$(VENV)/bin/pip install -Ue ".[dev,test]" -c constraints.txt
touch $(DEV_STAMP)
install-docs: $(DOC_STAMP)
$(DOC_STAMP): $(PYTHON) docs/requirements.txt
$(VENV)/bin/pip install -r docs/requirements.txt
touch $(DOC_STAMP)
constraints.txt: constraints.in
pip-compile -o constraints.txt constraints.in
pull-kinto-admin:
scripts/pull-kinto-admin.sh
$(SERVER_CONFIG):
$(VENV)/bin/kinto init --ini $(SERVER_CONFIG)
NAME := kinto
SOURCE := $(shell git config remote.origin.url | sed -e 's|git@|https://|g' | sed -e 's|github.com:|github.com/|g')
VERSION := $(shell git describe --always --tag)
COMMIT := $(shell git log --pretty=format:'%H' -n 1)
version-file:
echo '{"name":"$(NAME)","version":"$(VERSION)","source":"$(SOURCE)","commit":"$(COMMIT)"}' > version.json
serve: install-dev $(SERVER_CONFIG) migrate version-file
$(VENV)/bin/kinto start --ini $(SERVER_CONFIG) --reload
migrate: install $(SERVER_CONFIG)
$(VENV)/bin/kinto migrate --ini $(SERVER_CONFIG)
test: tests
tests-once: tests
tests: install-postgres install-monitoring install-memcached version-file install-dev
$(VENV)/bin/py.test --cov-config pyproject.toml --cov-report term-missing --cov-fail-under 100 --cov kinto
tests-raw: version-file install-dev
$(VENV)/bin/py.test
test-deps:
docker pull memcached
docker pull postgres
docker run -p 11211:11211 --name kinto-memcached -d memcached || echo "cannot start memcached, already exists?"
docker run -p 5432:5432 --name kinto-postgres -e POSTGRES_PASSWORD=postgres -d postgres || echo "cannot start postgres, already exists?"
sleep 2
PGPASSWORD=postgres psql -c "CREATE DATABASE testdb ENCODING 'UTF8' TEMPLATE template0;" -U postgres -h localhost
lint: install-dev
$(VENV)/bin/ruff check kinto tests docs/conf.py
$(VENV)/bin/ruff format --check kinto tests docs/conf.py
format: install-dev
$(VENV)/bin/ruff check --fix kinto tests docs/conf.py
$(VENV)/bin/ruff format kinto tests docs/conf.py
tdd: install-dev
$(VENV)/bin/ptw --runner $(VENV)/bin/py.test
need-kinto-running:
@curl http://localhost:8888/v0/ 2>/dev/null 1>&2 || (echo "Run 'make runkinto' before starting tests." && exit 1)
runkinto: install-dev
$(VENV)/bin/kinto migrate --ini tests/functional.ini
$(VENV)/bin/kinto start --ini tests/functional.ini
functional: install-dev need-kinto-running
$(VENV)/bin/py.test tests/functional.py
browser-test: need-kinto-running
$(VENV)/bin/playwright install firefox
$(VENV)/bin/py.test tests/browser.py
clean:
find . -name '*.pyc' -delete
find . -name '__pycache__' -type d | xargs rm -fr
rm -fr docs/_build/
docker rm -f kinto-memcached || echo ""
docker rm -f kinto-postgres || echo ""
distclean: clean
rm -fr *.egg *.egg-info/ dist/ build/
maintainer-clean: distclean
rm -fr .venv/ kinto/plugins/admin/build/ kinto/plugins/admin/node_modules/
docs: install-docs
$(VENV)/bin/sphinx-build -a -W -n -b html -d $(SPHINX_BUILDDIR)/doctrees docs $(SPHINX_BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(SPHINX_BUILDDIR)/html/index.html"
.PHONY: build
build:
docker build --build-arg="KINTO_VERSION=$(shell git describe --abbrev=0)" --pull -t kinto/kinto-server:latest .
test-description: install-dev
$(VENV)/bin/python -m build
$(VENV)/bin/twine check dist/*.whl