-
Notifications
You must be signed in to change notification settings - Fork 27
/
Makefile
134 lines (107 loc) · 5.31 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
.DEFAULT_GOAL := help
VENV_DIR ?= venv
TESTS_DIR=$(PWD)/tests
NOTEBOOKS_DIR=./notebooks
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
.PHONY: help
help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
all: $(VENV_DIR)
# to turn on in future:
# echo "\n\n=== pydocstyle ==="; $(VENV_DIR)/bin/pydocstyle pymagicc || echo "--- pydocstyle failed ---" >&2; \
# echo "\n\n=== pylint ==="; $(VENV_DIR)/bin/pylint pymagicc || echo "--- pylint failed ---" >&2; \
checks: $(VENV_DIR) ## run all the checks
@echo "=== bandit ==="; $(VENV_DIR)/bin/bandit -c .bandit.yml -r pymagicc || echo "--- bandit failed ---" >&2; \
echo "\n\n=== black ==="; $(VENV_DIR)/bin/black --check pymagicc tests setup.py docs/conf.py --exclude pymagicc/_version.py || echo "--- black failed ---" >&2; \
echo "\n\n=== flake8 ==="; $(VENV_DIR)/bin/flake8 pymagicc tests setup.py || echo "--- flake8 failed ---" >&2; \
echo "\n\n=== isort ==="; $(VENV_DIR)/bin/isort --check-only --quiet pymagicc tests setup.py || echo "--- isort failed ---" >&2; \
echo "\n\n=== notebook tests ==="; $(VENV_DIR)/bin/pytest notebooks -r a --nbval --sanitize-with tests/notebook-tests.cfg || echo "--- notebook tests failed ---" >&2; \
echo "\n\n=== tests ==="; $(VENV_DIR)/bin/pytest tests --cov -r a -v --cov-report term-missing || echo "--- tests failed ---" >&2; \
echo "\n\n=== docs ==="; $(VENV_DIR)/bin/sphinx-build -M html docs docs/build || echo "--- docs failed ---" >&2; \
echo
black: $(VENV_DIR) ## reformat the code with black
@status=$$(git status --porcelain pymagicc tests); \
if test "x$${status}" = x; then \
$(VENV_DIR)/bin/black --exclude _version.py setup.py pymagicc tests; \
else \
echo Not trying any formatting. Working directory is dirty ... >&2; \
fi;
isort: $(VENV_DIR) ## sort the imports in the code
@status=$$(git status --porcelain pymagicc tests); \
if test "x$${status}" = x; then \
$(VENV_DIR)/bin/isort pymagicc tests setup.py; \
else \
echo Not trying any formatting. Working directory is dirty ... >&2; \
fi;
flake8: $(VENV_DIR) ## apply the flake8 linter
$(VENV_DIR)/bin/flake8 pymagicc tests setup.py
test: $(VENV_DIR) ## run the tests
@[ ! -z "`which wine`" ] || echo 'If you want to test pymagicc fully on a non-windows system, install wine now'
$(VENV_DIR)/bin/pytest -r a tests --durations=10
test-parallel: $(VENV_DIR) ## run the tests
@[ ! -z "`which wine`" ] || echo 'If you want to test pymagicc fully on a non-windows system, install wine now'
$(VENV_DIR)/bin/pytest -n auto -r a tests --durations=10
test-notebooks: $(VENV_DIR) notebooks/*.ipynb scripts/test_notebooks.sh ## run the notebook tests
./scripts/test_notebooks.sh
$(VENV_DIR): setup.py
[ -d $(VENV_DIR) ] || python3 -m venv $(VENV_DIR)
$(VENV_DIR)/bin/pip install --upgrade pip wheel versioneer
$(VENV_DIR)/bin/pip install -e .[dev]
touch $(VENV_DIR)
update-example-plot: ## update the example plot
$(VENV_DIR)/bin/python scripts/plot_example.py
# first time setup, follow the 'Register for PyPI' section in this
# https://blog.jetbrains.com/pycharm/2017/05/how-to-publish-your-package-on-pypi/
# then this works
publish-on-testpypi: $(VENV_DIR) ## release this version on test PyPI
-rm -rf build dist
@status=$$(git status --porcelain); \
if test "x$${status}" = x; then \
$(VENV_DIR)/bin/python setup.py bdist_wheel --universal; \
$(VENV_DIR)/bin/twine upload -r testpypi dist/*; \
else \
echo Working directory is dirty >&2; \
fi;
test-testpypi-install: $(VENV_DIR) ## test installation from test PyPI
$(eval TEMPVENV := $(shell mktemp -d))
python3 -m venv $(TEMPVENV)
$(TEMPVENV)/bin/pip install pip --upgrade
# Install dependencies not on testpypi registry
$(TEMPVENV)/bin/pip install pandas f90nml
# Install pymagicc without dependencies.
$(TEMPVENV)/bin/pip install \
-i https://testpypi.python.org/pypi pymagicc \
--no-dependencies --pre
# Remove local directory from path to get actual installed version.
@echo "This doesn't test dependencies"
$(TEMPVENV)/bin/python -c "import sys; sys.path.remove(''); import pymagicc; print(pymagicc.__version__)"
publish-on-pypi: $(VENV_DIR) ## release this version on PyPI (manual override, by default let CI do these releases)
-rm -rf build dist
@status=$$(git status --porcelain); \
if test "x$${status}" = x; then \
$(VENV_DIR)/bin/python setup.py sdist bdist_wheel --universal; \
$(VENV_DIR)/bin/twine upload dist/*; \
else \
echo Working directory is dirty >&2; \
fi;
test-pypi-install: $(VENV_DIR) ## test installation from PyPI
$(eval TEMPVENV := $(shell mktemp -d))
python3 -m venv $(TEMPVENV)
$(TEMPVENV)/bin/pip install pip --upgrade
$(TEMPVENV)/bin/pip install pymagicc --pre
$(TEMPVENV)/bin/python scripts/test_install.py
docs: $(VENV_DIR) docs/*.rst $(shell find ./pymagicc/ -type f -name '*.py') ## make the docs
$(VENV_DIR)/bin/sphinx-build -M html docs docs/build
validate-data: $(VENV_DIR) ## validate the data packaged in pymagicc
$(VENV_DIR)/bin/goodtables pymagicc/definitions/datapackage.json
clean: ## remove the virtual environment
rm -rf $(VENV_DIR)
.PHONY: publish-on-testpypi test-testpypi-install publish-on-pypi test-pypi-install flake8 test black clean format-notebooks