-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
126 lines (99 loc) · 4.53 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
.PHONY: build build-docker shell poetry unit-test test test-watch test-with-coverage lint commitlint wheel publish format regenerate-cassette vcr-test all-test experimental-test
USER_ID := $(shell id -u)
GROUP_ID := $(shell id -g)
IN_DOCKER_IMG := $(shell ( test -f /.dockerenv && echo 1 ) || ( test -f /opt/impact/notebook_manifest.json && echo 1 ) || echo 0)
SECRETS := $(CURDIR)/.secrets
export MODELON_IMPACT_CLIENT_INTERACTIVE:=false
export MODELON_IMPACT_CLIENT_API_KEY ?= $(shell cat $(SECRETS)/api.key)
export MODELON_IMPACT_CLIENT_URL ?= https://impact.modelon.cloud/
export MODELON_IMPACT_USERNAME ?= $(shell git config user.email)
export UPDATE_CASSETTE=0
define _run
@if [ $(IN_DOCKER_IMG) -eq 1 ]; then \
$(2);\
else \
docker run \
--rm $(1) \
-v $(CURDIR):/src \
-u $(USER_ID):$(GROUP_ID) \
--env-file docker.env \
modelon-impact-client-build:latest \
$(2);\
fi
endef
define _run_interactive
$(call _run, -it, $(1))
endef
define _run_bare
$(call _run, , $(1))
endef
ifdef WITH_COVERAGE
EXTRA_PYTEST_FLAGS+=--cov-config=.coveragerc --cov-report=html:htmlcov --cov-report=term --cov=modelon/impact
endif
build-docker:
@if [ $(IN_DOCKER_IMG) -eq 0 ]; then \
docker build -t modelon-impact-client-build:latest . ;\
fi
.venv: poetry.lock pyproject.toml
$(call _run_bare, poetry install && touch .venv || rm -rf .venv)
.devcontainerenv:
@echo "MODELON_IMPACT_CLIENT_INTERACTIVE=$${MODELON_IMPACT_CLIENT_INTERACTIVE}" > .devcontainer/devcontainer.env
@echo "MODELON_IMPACT_CLIENT_API_KEY=$${MODELON_IMPACT_CLIENT_API_KEY}" >> .devcontainer/devcontainer.env
@echo "MODELON_IMPACT_CLIENT_URL=$${MODELON_IMPACT_CLIENT_URL}" >> .devcontainer/devcontainer.env
@echo "MODELON_IMPACT_USERNAME=$${MODELON_IMPACT_USERNAME}" >> .devcontainer/devcontainer.env
@echo "UPDATE_CASSETTE=$${UPDATE_CASSETTE}" >> .devcontainer/devcontainer.env
build: build-docker .venv
shell:
$(call _run_interactive, bash)
poetry:
$(call _run_interactive, poetry shell)
unit-test: export IMPACT_PYTHON_CLIENT_EXPERIMENTAL=0
unit-test:
$(call _run_bare, poetry run -- pytest -vv -m 'not (experimental)' ${EXTRA_PYTEST_FLAGS})
experimental-test: export IMPACT_PYTHON_CLIENT_EXPERIMENTAL=1
experimental-test:
$(call _run_bare, poetry run -- pytest -vv -m '(experimental)' ${EXTRA_PYTEST_FLAGS})
vcr-test:
$(call _run_bare, poetry run -- pytest -vv -m '(vcr)' ${EXTRA_PYTEST_FLAGS})
all-test: export IMPACT_PYTHON_CLIENT_EXPERIMENTAL=1
all-test:
$(call _run_bare, poetry run -- pytest -vv ${EXTRA_PYTEST_FLAGS})
test: build lint all-test
check_environment_variables:
@echo "Checking for environmental variables..."
@if [ -z "$$MODELON_IMPACT_CLIENT_API_KEY" ]; then \
echo "Error: 'MODELON_IMPACT_CLIENT_API_KEY' variable not set"; \
exit 1; \
else \
echo "Variable 'MODELON_IMPACT_CLIENT_API_KEY' is set"; \
fi
@if [ -z "$$MODELON_IMPACT_CLIENT_URL" ]; then \
echo "Error: 'MODELON_IMPACT_CLIENT_URL' variable not set"; \
exit 1; \
else \
echo "Variable 'MODELON_IMPACT_CLIENT_URL' is set"; \
fi
regenerate-cassette: check_environment_variables
IMPACT_PYTHON_CLIENT_EXPERIMENTAL=1 UPDATE_CASSETTE=1 $(MAKE) vcr-test
test-with-coverage:
$(MAKE) WITH_COVERAGE=YES test
test-watch: build
$(call _run_bare, poetry run -- pytest-watch -- -vv ${EXTRA_PYTEST_FLAGS})
commitlint:
# Will lint the latest 10 or all commits, whicher is the smallest number:
$(eval REV_LIST_HEAD=$$(shell (git rev-list HEAD --count --first-parent)))
# rev-list gives 1 too many commits...
$(eval COMMITS_IN_REPO=$$(shell (expr $(REV_LIST_HEAD) - 1)))
$(eval COMMITS_TO_LINT=$$(shell (echo $(COMMITS_IN_REPO) && echo 10) | sort -g | head -n1))
@echo "Will lint the last '$(COMMITS_TO_LINT)' commits"
$(call _run_bare, npx commitlint --from=HEAD~$(COMMITS_TO_LINT) --config commitlint.config.js)
lint: commitlint
$(call _run_bare, poetry run -- bash -c "black --check modelon tests && flake8 modelon tests --config .flake8 && mypy --disallow-untyped-defs modelon && isort --check modelon tests && docformatter -c modelon --config ./pyproject.toml && sphinx-build -b spelling docs/source docs/build && pylint --disable all --enable spelling modelon")
wheel: build
$(call _run_bare, poetry build -f wheel)
publish: build
$(call _run_bare, npx semantic-release --ci false)
docs: build
$(call _run_bare, bash -c "poetry run -- sphinx-apidoc -f -d 5 -o docs/source modelon && poetry run -- $(MAKE) -C ./docs clean && poetry run -- $(MAKE) -C ./docs html")
format:
$(call _run_bare, poetry run -- bash -c "black modelon tests && isort modelon tests && docformatter -i modelon --config ./pyproject.toml")