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 a233de4 commit efa06a5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:
make lint
- name: Test
run: |
make test
make test PYTEST_OPTS="-vvv"
40 changes: 27 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
POETRY ?= poetry
_RUN ?= $(POETRY) run
PIP ?= pip3
PYTEST ?= $(_RUN) pytest
FLAKE8 ?= $(_RUN) flake8
BLACK ?= $(_RUN) black
PYLINT ?= $(_RUN) pylint
ISORT ?= $(_RUN) isort
MYPY ?= $(_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) $(PYTEST_OPTS) $(TESTS_DIR)

.PHONY: clean
clean:
Expand All @@ -30,15 +44,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 ?= 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) $(PYTEST_OPTS) \
--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 efa06a5

Please sign in to comment.