-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
116 lines (89 loc) · 3.99 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#
# File: Makefile
# Description: When run with `make`, this provides tools for using and developing the `TODO` project
# The `.ONESHELL` and setting `SHELL` allows us to run commands that require `conda activate`
.ONESHELL:
SHELL := /bin/bash
# For GNU Make v4 and above, you must include the `-c` in order for `make` to find symbols from `PATH`
.SHELLFLAGS := -c -o pipefail -o errexit
CONDA_ACTIVATE = source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate ; conda activate
# Ensure that we are using the python interpretter provided by the conda environment.
PYTHON3 := "$(CONDA_PREFIX)/bin/python3"
.PHONY: clean clean-cov clean-build clean-env clean-pyc clean-test help pre-commit test test-cov lint format format-docs analyze
.DEFAULT_GOAL := help
CONDA_ENV_NAME ?= TODO
SRC_DIR = TODO
TEST_DIR = tests/
# `BROWSER_PYSCRIPT` and `PRINT_HELP_PYSCRIPT` are used to generate the output
# of `make help` automatically. This requires each `make` directive to be
# followed by a `##` comment with a description.
define BROWSER_PYSCRIPT
import os, webbrowser, sys
from urllib.request import pathname2url
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
export BROWSER_PYSCRIPT
define PRINT_HELP_PYSCRIPT
import re, sys
for line in sys.stdin:
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
print("%-20s %s" % (target, help))
endef
export PRINT_HELP_PYSCRIPT
BROWSER := $(PYTHON3) -c "$$BROWSER_PYSCRIPT"
clean: clean-build clean-cov clean-env clean-pyc clean-test ## remove all build, test, coverage, environment and Python artifacts
clean-cov: ## remove code coverage artifacts
rm -rf .coverage
rm -rf htmlcov
rm -rf reports/{*.html,*.png,*.js,*.css,*.json}
rm -rf pytest.xml
rm -rf pytest-coverage.txt
clean-build: ## remove build artifacts
rm -fr build/
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
clean-env: ## remove conda environment
conda remove -y -n $(CONDA_ENV_NAME) --all
clean-pyc: ## remove Python file artifacts
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
clean-test: ## remove test and coverage artifacts
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache
environment: ## handles environment creation
conda env create -f environment.yaml --name $(CONDA_ENV_NAME) --force
conda run --name $(CONDA_ENV_NAME) pip install .
help:
$(PYTHON3) -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
pre-commit: ## runs pre-commit against files
pre-commit run --all-files
install: clean ## install the package to the active (current environment's) Python's site-packages
pip install .
dev: clean ## install the package's development version to a fresh environment
conda env create -f environment.yaml --name $(CONDA_ENV_NAME) --force
conda run --name $(CONDA_ENV_NAME) pip install -e .
$(CONDA_ACTIVATE) $(CONDA_ENV_NAME) && pre-commit install
test: ## executes unit test cases
$(PYTHON3) -m pytest -n auto --capture=no $(TEST_DIR)
test-debug: ## runs test cases with debugging info enabled
$(PYTHON3) -m pytest -n auto -vv --capture=no $(TEST_DIR)
test-cov: ## checks test coverage requirements
$(PYTHON3) -m pytest -n auto --cov-config=.coveragerc --cov=$(SRC_DIR) \
$(TEST_DIR) --cov-fail-under=80 --cov-report term-missing
lint: ## runs the linter against the project
pylint --rcfile=.pylintrc $(SRC_DIR) $(TEST_DIR)
format: ## runs the code auto-formatter
isort --profile black --line-length=120 $(SRC_DIR) $(TEST_DIR)
black --line-length=120 $(SRC_DIR)
format-docs: ## runs the docstring auto-formatter. Note this requires manually installing `docconvert`
docconvert --in-place --config .docconvert.json $(SRC_DIR) $(TEST_DIR)
analyze: ## runs static analyzer on the project
mypy --config-file=.mypy.ini --cache-dir=/dev/null $(SRC_DIR) $(TEST_DIR)