From 28d978696b58b8fd34fa5c402c0d8e1f2c8639ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Kuti?= Date: Fri, 20 Oct 2023 19:02:53 +0200 Subject: [PATCH] Make Makefiles nicer --- Makefile | 39 +++++++++++++++++--------- {{cookiecutter.package_name}}/Makefile | 36 +++++++++++++++--------- 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index b1de109..337b7f0 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,35 @@ +POETRY ?= poetry +PIP ?= poetry run pip3 +PYTEST ?= poetry run pytest +FLAKE8 ?= poetry run flake8 +BLACK ?= poetry run black +PYLINT ?= poetry run pylint +ISORT ?= poetry run isort +MYPY ?= poetry run mypy + +COOKIECUTTER ?= cookiecutter + +TESTS_DIR := tests + .PHONY: install_lint_requirements install_lint_requirements: - poetry install --with lint + $(POETRY) install --with lint .PHONY: lint lint: install_lint_requirements - flake8 tests - black --check --diff tests - pylint tests - isort --check-only tests - mypy tests + $(FLAKE8) $(TESTS_DIR) + $(BLACK) --check --diff $(TESTS_DIR) + $(PYLINT) $(TESTS_DIR) + $(ISORT) --check-only $(TESTS_DIR) + $(MYPY) $(TESTS_DIR) .PHONY: install_test_requirements install_test_requirements: - poetry install --with test + $(POETRY) install --with test .PHONY: test test: install_test_requirements - pytest tests + $(PYTEST) $(TESTS_DIR) .PHONY: clean clean: @@ -30,15 +43,15 @@ clean: .PHONY: format format: - black tests - isort tests + $(BLACK) $(TESTS_DIR) + $(ISORT) $(TESTS_DIR) .PHONY: install install: - pip3 install . + $(PIP) install . -TARGET_DIR := . +TARGET_DIR ?= . .PHONY: generate generate: install - cookiecutter -v . --output-dir="$(TARGET_DIR)" + $(COOKIECUTTER) -v . --output-dir="$(TARGET_DIR)" diff --git a/{{cookiecutter.package_name}}/Makefile b/{{cookiecutter.package_name}}/Makefile index e77ba02..7abbe2b 100644 --- a/{{cookiecutter.package_name}}/Makefile +++ b/{{cookiecutter.package_name}}/Makefile @@ -1,28 +1,38 @@ +POETRY ?= poetry +PYTEST ?= poetry run pytest +FLAKE8 ?= poetry run flake8 +BLACK ?= poetry run black +PYLINT ?= poetry run pylint +ISORT ?= poetry run isort +MYPY ?= poetry run mypy + PACKAGE_NAME := {{cookiecutter.package_name}} +TESTS_DIR := tests +ALL_SOURCE := $(PACKAGE_NAME) $(TESTS_DIR) .PHONY: install_lint_requirements install_lint_requirements: - poetry install --with lint + $(POETRY) install --with lint .PHONY: lint lint: install_lint_requirements - flake8 $(PACKAGE_NAME) tests - black --check --diff $(PACKAGE_NAME) tests - pylint $(PACKAGE_NAME) tests - isort --check-only $(PACKAGE_NAME) tests - mypy --ignore-missing-imports $(PACKAGE_NAME) tests + $(FLAKE8) $(ALL_SOURCE) + $(BLACK) --check --diff $(ALL_SOURCE) + $(PYLINT) $(ALL_SOURCE) + $(ISORT) --check-only $(ALL_SOURCE) + $(MYPY) --ignore-missing-imports $(ALL_SOURCE) .PHONY: install_test_requirements install_test_requirements: - poetry install --with test + $(POETRY) install --with test .PHONY: test test: install_test_requirements - pytest \ + $(PYTEST) \ --cov=$(PACKAGE_NAME) \ - --cov=tests \ + --cov=$(TESTS_DIR) \ --cov-report=term-missing:skip-covered \ - tests + $(TESTS_DIR) .PHONY: clean clean: @@ -38,9 +48,9 @@ clean: .PHONY: build build: - poetry build + $(POETRY) build .PHONY: format format: - black $(PACKAGE_NAME) tests - isort $(PACKAGE_NAME) tests + $(BLACK) $(ALL_SOURCE) + $(ISORT) $(ALL_SOURCE)