sintonia/tools/python.mk

95 lines
1.9 KiB
Makefile
Raw Normal View History

.ONESHELL:
.DEFAULT_GOAL = install
2021-09-13 14:22:20 +02:00
SHELL = bash
CPU_CORES = $$(( $(shell nproc) > 4 ? 4 : $(shell nproc) ))
2021-09-13 14:22:20 +02:00
# PIP_INSTALL = --editable .
# PYLINT_ARG =
# MYPY_ARG =
# BANDIT_ARG =
2021-09-13 14:22:20 +02:00
# PYTEST_ARG =
2021-09-13 14:22:48 +02:00
SHARED_DEV_REQUIREMENTS = \
bandit \
2021-09-13 14:22:48 +02:00
black \
flake8 \
2021-09-13 14:22:48 +02:00
isort \
mypy \
pylint \
pytest \
pytest-cov \
pytest-xdist
VENV = .venv
$(VENV):
python3 -m venv $(VENV)
source $(VENV)/bin/activate
$(MAKE) install
# SETUPTOOLS_ENABLE_FEATURES=legacy-editable is required to work
# around https://github.com/PyCQA/pylint/issues/7306
install: $(VENV)
source $(VENV)/bin/activate
pip install --upgrade pip setuptools wheel
pip install $(SHARED_DEV_REQUIREMENTS)
[[ -z "$(PIP_INSTALL)" ]] || SETUPTOOLS_ENABLE_FEATURES=legacy-editable pip install $(PIP_INSTALL)
2021-09-13 14:21:19 +02:00
.PHONY: .format
.format: $(VENV)
source $(VENV)/bin/activate
black .
2022-07-27 14:13:55 +02:00
isort . --combine-as --profile black
.PHONY: .format-check
.format-check: $(VENV)
source $(VENV)/bin/activate
black . --check
2022-07-27 14:13:55 +02:00
isort . --combine-as --profile black --check
2021-09-13 14:21:19 +02:00
.PHONY: .pylint
.pylint: $(VENV)
source $(VENV)/bin/activate
pylint --jobs=$(CPU_CORES) --output-format=colorized --recursive=true $(PYLINT_ARG)
2021-09-10 14:41:51 +02:00
.PHONY: .mypy
.mypy: $(VENV)
source $(VENV)/bin/activate
mypy $(MYPY_ARG)
2021-09-10 14:41:51 +02:00
.PHONY: .bandit
.bandit: $(VENV)
source $(VENV)/bin/activate
bandit -r $(BANDIT_ARG)
.PHONY: .pytest
.pytest: $(VENV)
source $(VENV)/bin/activate
2022-06-29 14:40:37 +02:00
pytest -v \
--numprocesses=$(CPU_CORES) \
--color=yes \
--cov-config=pyproject.toml \
--cov-report=term \
--cov-report=xml:./coverage.xml \
$(PYTEST_ARG)
.PHONY: .clean
.clean:
rm -Rf $(VENV)
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