Skip to content

Commit

Permalink
Make Makefiles nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
matyaskuti committed Nov 10, 2023
1 parent 93acf63 commit eb28934
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 26 deletions.
38 changes: 25 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
POETRY ?= poetry
PYTEST ?= pytest
FLAKE8 ?= flake8
BLACK ?= black
PYLINT ?= pylint
ISORT ?= isort
MYPY ?= mypy
PIP ?= pip3
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:
Expand All @@ -30,15 +42,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)"
36 changes: 23 additions & 13 deletions {{cookiecutter.package_name}}/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
POETRY ?= poetry
PYTEST ?= pytest
FLAKE8 ?= flake8
BLACK ?= black
PYLINT ?= pylint
ISORT ?= isort
MYPY ?= 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:
Expand All @@ -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)

0 comments on commit eb28934

Please sign in to comment.