From ceb40ee216381e9cb515e3907808b7a2e854ba62 Mon Sep 17 00:00:00 2001 From: jo Date: Fri, 10 Sep 2021 13:46:47 +0200 Subject: [PATCH] Use shared python makefile and start linting Always update setuptools/wheel/pip Never fail while linting We use github annotations to impove the code incrementally. --- api/Makefile | 9 +++++++++ python_apps/airtime-celery/Makefile | 9 +++++++++ python_apps/airtime_analyzer/Makefile | 20 ++++++++---------- python_apps/api_clients/Makefile | 25 +++++++++-------------- python_apps/pypo/Makefile | 9 +++++++++ tools/Makefile | 26 +++++++----------------- tools/python.mk | 29 +++++++++++++++++++++++++++ 7 files changed, 81 insertions(+), 46 deletions(-) create mode 100644 api/Makefile create mode 100644 python_apps/airtime-celery/Makefile create mode 100644 python_apps/pypo/Makefile create mode 100644 tools/python.mk diff --git a/api/Makefile b/api/Makefile new file mode 100644 index 000000000..6999c6187 --- /dev/null +++ b/api/Makefile @@ -0,0 +1,9 @@ +all: lint + +include ../tools/python.mk + +PIP_INSTALL := --editable .[dev] +PYLINT_ARG := libretimeapi + +lint: .pylint +clean: .clean diff --git a/python_apps/airtime-celery/Makefile b/python_apps/airtime-celery/Makefile new file mode 100644 index 000000000..135a53091 --- /dev/null +++ b/python_apps/airtime-celery/Makefile @@ -0,0 +1,9 @@ +all: lint + +include ../../tools/python.mk + +PIP_INSTALL := --editable .[dev] +PYLINT_ARG := airtime-celery + +lint: .pylint +clean: .clean diff --git a/python_apps/airtime_analyzer/Makefile b/python_apps/airtime_analyzer/Makefile index 9d4260e07..8ea046b30 100644 --- a/python_apps/airtime_analyzer/Makefile +++ b/python_apps/airtime_analyzer/Makefile @@ -1,19 +1,15 @@ -.PHONY: lint test +all: lint test -SHELL := bash -CPU_CORES := $(shell nproc) +include ../../tools/python.mk -MODULE_APP := airtime_analyzer -MODULE_TESTS := tests +PIP_INSTALL := --editable .[dev] +PYLINT_ARG := airtime_analyzer tests +PYTEST_ARG := --cov=airtime_analyzer tests -lint: - pylint ${MODULE_APP} - pylint ${MODULE_TESTS} +lint: .pylint fixtures: bash tests/fixtures/generate.sh -test: fixtures - pytest -n ${CPU_CORES} --color=yes -v --cov=${MODULE_APP} ${MODULE_TESTS} - -all: lint test +test: fixtures .pytest +clean: .clean diff --git a/python_apps/api_clients/Makefile b/python_apps/api_clients/Makefile index 267fb7986..5da67fcae 100644 --- a/python_apps/api_clients/Makefile +++ b/python_apps/api_clients/Makefile @@ -1,16 +1,11 @@ -.PHONY: lint test - -SHELL := bash -CPU_CORES := $(shell nproc) - -MODULE_APP := api_clients -MODULE_TESTS := tests - -lint: - pylint ${MODULE_APP} - pylint ${MODULE_TESTS} - -test: - pytest -n ${CPU_CORES} --color=yes -v --cov=${MODULE_APP} ${MODULE_TESTS} - all: lint test + +include ../../tools/python.mk + +PIP_INSTALL := --editable .[dev] +PYLINT_ARG := api_clients tests +PYTEST_ARG := --cov=api_clients tests + +lint: .pylint +test: .pytest +clean: .clean diff --git a/python_apps/pypo/Makefile b/python_apps/pypo/Makefile new file mode 100644 index 000000000..bd2ee0a9c --- /dev/null +++ b/python_apps/pypo/Makefile @@ -0,0 +1,9 @@ +all: lint + +include ../../tools/python.mk + +PIP_INSTALL := --editable .[dev] +PYLINT_ARG := liquidsoap pypo + +lint: .pylint +clean: .clean diff --git a/tools/Makefile b/tools/Makefile index 511ba08af..a8cdf94c9 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,23 +1,11 @@ -.PHONY: lint test -.ONESHELL: - -SHELL := bash -CPU_CORES := $(shell nproc) - all: lint test -venv: - python3 -m venv venv - source venv/bin/activate - pip install -r requirements-dev.txt +include python.mk -lint: venv - source venv/bin/activate - pylint tools +PIP_INSTALL := -r requirements-dev.txt +PYLINT_ARG := tools +PYTEST_ARG := . -test: venv - source venv/bin/activate - pytest -n ${CPU_CORES} --color=yes -v . - -clean: - rm -Rf venv +lint: .pylint +test: .pytest +clean: .clean diff --git a/tools/python.mk b/tools/python.mk new file mode 100644 index 000000000..46b642ef4 --- /dev/null +++ b/tools/python.mk @@ -0,0 +1,29 @@ +.ONESHELL: + +SHELL := bash +CPU_CORES := $(shell nproc) + +# PIP_INSTALL := --editable .[dev] +# PYLINT_ARG := +# PYTEST_ARG := + +VENV := venv +$(VENV): + python3 -m venv $(VENV) + source $(VENV)/bin/activate + pip install --upgrade pip setuptools wheel + pip install $(PIP_INSTALL) + +.PHONY: .pylint +.pylint: $(VENV) + source $(VENV)/bin/activate + pylint --output-format=colorized $(PYLINT_ARG) || true + +.PHONY: .pytest +.pytest: $(VENV) + source venv/bin/activate + pytest -n $(CPU_CORES) --color=yes -v $(PYTEST_ARG) + +.PHONY: .clean +.clean: + rm -Rf $(VENV)