forked from links-ads/template-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
58 lines (49 loc) · 1.77 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
.ONESHELL:
PY_ENV=.venv
PY_BIN=$(shell python -c "print('$(PY_ENV)/bin') if __import__('pathlib').Path('$(PY_ENV)/bin/pip').exists() else print('')")
.PHONY: help
help: ## This help screen
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
.PHONY: init
init: ## Initialize the project template
@$(PY_BIN)/python init.py
.PHONY: show
show: ## Show the current environment.
@echo "Current environment:"
@echo "Running using $(PY_BIN)"
@$(PY_BIN)/python -V
@$(PY_BIN)/python -m site
.PHONY: check-venv
check-venv: ## Check if the virtualenv exists.
@if [ "$(PY_BIN)" = "" ]; then echo "No virtualenv detected, create one first."; exit 1; fi
.PHONY: install
install: check-venv ## Install the project in dev mode.
@$(PY_BIN)/pip install -e .[dev,docs,test]
.PHONY: fmt
fmt: check-venv ## Format code using black & isort.
$(PY_BIN)/ruff format -v .
.PHONY: lint
lint: check-venv ## Run ruff, black, mypy (optional).
@$(PY_BIN)/ruff check .
@$(PY_BIN)/ruff format --check .
@if [ -x "$(PY_BIN)/mypy" ]; then $(PY_BIN)/mypy project_name/; else echo "mypy not installed, skipping"; fi
.PHONY: test
test: lint ## Run tests and generate coverage report.
$(PY_BIN)/pytest --cov-report=xml -o console_output_style=progress
.PHONY: clean
clean: ## Clean unused files (VENV=true to also remove the virtualenv).
@find ./ -name '*.pyc' -exec rm -f {} \;
@find ./ -name '__pycache__' -exec rm -rf {} \;
@find ./ -name 'Thumbs.db' -exec rm -f {} \;
@find ./ -name '*~' -exec rm -f {} \;
@rm -rf .cache
@rm -rf .pytest_cache
@rm -rf .mypy_cache
@rm -rf .ruff_cache
@rm -rf build
@rm -rf dist
@rm -rf *.egg-info
@rm -rf htmlcov
@rm -rf .tox/
@rm -rf docs/_build
@if [ "$(VENV)" != "" ]; then echo "Removing virtualenv..."; rm -rf $(PY_ENV); fi