-
Notifications
You must be signed in to change notification settings - Fork 27
/
Makefile
138 lines (100 loc) · 3.51 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
135
136
137
138
.PHONY: all clean
all: test
clean:
rm -rf .pytest_cache .hypothesis .mypy_cache .ruff_cache __pycache__ .coverage logs .coverage*
# ----- SETUP -----
# installation of dependencies
.PHONY: setup-pip-poetry setup-test setup-static setup-check setup-docs
QUIET := -q
setup-pip-poetry:
pip install --upgrade pip $(QUIET)
pip install poetry==1.7.0 $(QUIET)
setup: setup-pip-poetry
poetry install --with main $(QUIET)
setup-test: setup-pip-poetry
poetry install --with test $(QUIET)
setup-static: setup-pip-poetry
poetry install --with static $(QUIET)
setup-check: setup-pip-poetry
poetry install --with check $(QUIET)
# manage docs dependencies separately because
# we build docs on netlify
# netlify only has Python 3.8
# TODO could change this now we use mike
# as we don't run a build on netlify anymore
setup-docs:
pip install -r ./docs/requirements.txt $(QUIET)
# ----- TEST -----
# documentation tests and unit tests
.PHONY: test generate-test-docs test-docs
PARALLEL = auto
TEST_ARGS =
export
test: setup-test test-docs
pytest tests --cov=energypylinear --cov-report=html --cov-report=term-missing -n $(PARALLEL) --color=yes --durations=5 --verbose --ignore tests/phmdoctest $(TEST_ARGS)
# -coverage combine
# -coverage html
-coverage report
python tests/assert-test-coverage.py $(TEST_ARGS)
generate-test-docs: setup-test
bash ./tests/generate-test-docs.sh
test-docs: setup-test generate-test-docs
pytest tests/phmdoctest -n 1 --dist loadfile --color=yes --verbose $(TEST_ARGS)
# ----- CHECK -----
# linting and static typing
.PHONY: check lint static
check: lint static
MYPY_ARGS=--pretty
static: setup-static
rm -rf ./tests/phmdoctest
mypy --version
mypy $(MYPY_ARGS) ./energypylinear
mypy $(MYPY_ARGS) ./tests --explicit-package-bases
lint: setup-check
rm -rf ./tests/phmdoctest
flake8 --extend-ignore E501,DAR --exclude=__init__.py,poc
ruff check . --ignore E501 --extend-exclude=__init__.py,poc
isort --check **/*.py --profile black
ruff format --check **/*.py
poetry check
CHECK_DOCSTRINGS=./energypylinear/objectives.py ./energypylinear/assets/battery.py ./energypylinear/assets/renewable_generator.py
# currently only run manually
lint-docstrings:
flake8 --extend-ignore E501 --exclude=__init__.py,poc --exit-zero $(CHECK_DOCSTRINGS)
pydocstyle $(CHECK_DOCSTRINGS)
# pylint $(CHECK_DOCSTRINGS)
# ----- FORMATTING -----
# formatting code
.PHONY: format
format: setup-check
isort **/*.py --profile black
ruff format **/*.py
# ----- PUBLISH ------
# updating package on pypi
.PHONY: publish
-include .env.secret
publish: setup
poetry build
@poetry config pypi-token.pypi $(PYPI_TOKEN)
poetry publish
# TODO publish docs automatically
# ----- DOCS ------
# mkdocs documentation
.PHONY: docs mike-deploy
generate-docs-images: setup
python ./docs/generate-plots.py
docs: setup-docs
# `mike serve` will show docs for the different versions
# `mkdocs serve` will show docs for the current version in markdown
# `mkdocs serve` will usually be more useful during development
cd docs; mkdocs serve -a localhost:8004; cd ..
# TODO currently run manually - should be automated with publishing
# this deploys the current docs to the docs branch
# -u = update aliases of this $(VERSION) to latest
# -b = branch - aligns with the branch name we build docs off
# -r = Github remote
# -p = push
# TODO - get VERSION from pyproject.toml
# TODO - this is not used in CI anywhere yet
mike-deploy: setup-docs generate-docs-images
cd docs; mike deploy $(VERSION) latest -u -b mike-pages -r origin -p