2022-12-07 11:14:40 +01:00
|
|
|
.DEFAULT_GOAL := install
|
|
|
|
SHELL := bash
|
|
|
|
CPU_CORES := $(shell N=$$(nproc); echo $$(( $$N > 4 ? 4 : $$N )))
|
2021-09-10 13:46:47 +02:00
|
|
|
|
2021-09-13 14:22:20 +02:00
|
|
|
# PIP_INSTALL = --editable .
|
|
|
|
# PYLINT_ARG =
|
|
|
|
# MYPY_ARG =
|
2022-02-14 09:35:20 +01:00
|
|
|
# BANDIT_ARG =
|
2021-09-13 14:22:20 +02:00
|
|
|
# PYTEST_ARG =
|
2021-09-10 13:46:47 +02:00
|
|
|
|
2021-09-13 14:22:48 +02:00
|
|
|
SHARED_DEV_REQUIREMENTS = \
|
2022-02-14 09:35:20 +01:00
|
|
|
bandit \
|
2021-09-13 14:22:48 +02:00
|
|
|
black \
|
2022-02-14 09:35:20 +01:00
|
|
|
flake8 \
|
2021-09-13 14:22:48 +02:00
|
|
|
isort \
|
|
|
|
mypy \
|
|
|
|
pylint \
|
|
|
|
pytest \
|
|
|
|
pytest-cov \
|
|
|
|
pytest-xdist
|
|
|
|
|
2022-01-04 12:09:19 +01:00
|
|
|
VENV = .venv
|
2021-09-10 13:46:47 +02:00
|
|
|
$(VENV):
|
|
|
|
python3 -m venv $(VENV)
|
2021-09-15 19:40:58 +02:00
|
|
|
$(MAKE) install
|
|
|
|
|
2022-08-24 20:44:29 +02:00
|
|
|
# SETUPTOOLS_ENABLE_FEATURES=legacy-editable is required to work
|
|
|
|
# around https://github.com/PyCQA/pylint/issues/7306
|
2022-01-04 12:09:19 +01:00
|
|
|
install: $(VENV)
|
2022-12-07 11:29:21 +01:00
|
|
|
$(VENV)/bin/pip install --upgrade pip setuptools wheel
|
|
|
|
$(VENV)/bin/pip install $(SHARED_DEV_REQUIREMENTS)
|
|
|
|
[[ -z "$(PIP_INSTALL)" ]] || SETUPTOOLS_ENABLE_FEATURES=legacy-editable $(VENV)/bin/pip install $(PIP_INSTALL)
|
2021-09-10 13:46:47 +02:00
|
|
|
|
2021-09-13 14:21:19 +02:00
|
|
|
.PHONY: .format
|
|
|
|
.format: $(VENV)
|
2022-12-07 11:29:21 +01:00
|
|
|
$(VENV)/bin/black .
|
2022-12-07 12:57:39 +01:00
|
|
|
$(VENV)/bin/isort .
|
2021-10-17 16:24:37 +02:00
|
|
|
|
|
|
|
.PHONY: .format-check
|
|
|
|
.format-check: $(VENV)
|
2022-12-07 11:29:21 +01:00
|
|
|
$(VENV)/bin/black . --check
|
2022-12-07 12:57:39 +01:00
|
|
|
$(VENV)/bin/isort . --check
|
2021-09-13 14:21:19 +02:00
|
|
|
|
2021-09-10 13:46:47 +02:00
|
|
|
.PHONY: .pylint
|
|
|
|
.pylint: $(VENV)
|
2022-12-07 11:29:21 +01:00
|
|
|
$(VENV)/bin/pylint --jobs=$(CPU_CORES) --output-format=colorized --recursive=true $(PYLINT_ARG)
|
2021-09-10 13:46:47 +02:00
|
|
|
|
2021-09-10 14:41:51 +02:00
|
|
|
.PHONY: .mypy
|
|
|
|
.mypy: $(VENV)
|
2022-12-07 11:29:21 +01:00
|
|
|
$(VENV)/bin/mypy $(MYPY_ARG)
|
2021-09-10 14:41:51 +02:00
|
|
|
|
2022-02-14 09:35:20 +01:00
|
|
|
.PHONY: .bandit
|
|
|
|
.bandit: $(VENV)
|
2022-12-07 11:29:21 +01:00
|
|
|
$(VENV)/bin/bandit -r $(BANDIT_ARG)
|
2022-02-14 09:35:20 +01:00
|
|
|
|
2021-09-10 13:46:47 +02:00
|
|
|
.PHONY: .pytest
|
|
|
|
.pytest: $(VENV)
|
2022-12-07 11:42:16 +01:00
|
|
|
$(VENV)/bin/pytest \
|
2022-06-29 14:40:37 +02:00
|
|
|
--numprocesses=$(CPU_CORES) \
|
2022-12-07 11:42:16 +01:00
|
|
|
--color=yes
|
|
|
|
|
|
|
|
.PHONY: .coverage
|
|
|
|
.coverage: $(VENV)
|
|
|
|
$(VENV)/bin/pytest \
|
|
|
|
--numprocesses=$(CPU_CORES) \
|
|
|
|
--cov \
|
2022-06-29 14:40:37 +02:00
|
|
|
--cov-config=pyproject.toml \
|
|
|
|
--cov-report=term \
|
2022-12-07 11:42:16 +01:00
|
|
|
--cov-report=xml
|
2021-09-10 13:46:47 +02:00
|
|
|
|
|
|
|
.PHONY: .clean
|
|
|
|
.clean:
|
|
|
|
rm -Rf $(VENV)
|
2022-08-16 13:22:09 +02:00
|
|
|
|
|
|
|
DISTRO ?= bullseye
|
|
|
|
DOCKER_RUN = docker run -it --rm \
|
|
|
|
--user $$(id -u):$$(id -g) \
|
|
|
|
--env HOME=/src/.docker/$(DISTRO) \
|
|
|
|
--volume $$(pwd)/..:/src \
|
|
|
|
--workdir /src/$(APP) \
|
|
|
|
ghcr.io/libretime/libretime-dev:$(DISTRO)
|
|
|
|
|
|
|
|
docker-dev:
|
|
|
|
$(MAKE) clean
|
|
|
|
$(DOCKER_RUN) bash
|
|
|
|
|
|
|
|
docker-test:
|
|
|
|
$(MAKE) clean
|
|
|
|
$(DOCKER_RUN) make test
|