This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
118 lines (101 loc) · 4.04 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
include include.mk
include environment.mk
include test/colab/colab-test.mk
.DEFAULT_GOAL:=help
define get_python_package_version
$(1)==$(shell $(POETRY) show $1 --no-ansi --only main | grep version | awk '{print $$3}')
endef
define autoreloadpy
from IPython import get_ipython
ipython = get_ipython()
ipython.magic("load_ext autoreload")
ipython.magic("autoreload 2")
endef
export autoreloadpy
install: $(INSTALL_STAMP) ## Install dependencies
$(INSTALL_STAMP): pyproject.toml poetry.lock $(PREREQ_STAMP)
ifdef IN_VENV
$(POETRY) install
else
$(POETRY) install --sync
endif
@poetry run ipython profile create --ipython-dir=build/ipython
@echo "$$autoreloadpy" > build/ipython/profile_default/startup/00-autoreload.py
@touch $(INSTALL_STAMP)
.PHONY: test
test: $(INSTALL_STAMP) ## Run unit tests
$(POETRY) run pytest test/unit --cov .
test-login: $(TEST_TOKEN_FILE)
$(TEST_TOKEN_FILE):
@stty -echo
@printf "Enter test user token for https://app.layer.ai: "
@read TOKEN && echo $$TOKEN > $(TEST_TOKEN_FILE)
@stty echo
.PHONY: ray-test
ray-test: $(INSTALL_STAMP) $(TEST_TOKEN_FILE)
@rm -rf $(E2E_TEST_HOME)
ifdef CI
$(eval DATADOG_ARGS := --ddtrace-patch-all --ddtrace)
endif
$(POETRY) run ray start --head --ray-client-server-port=20001 --include-dashboard=False --disable-usage-stats
LAYER_DEFAULT_PATH=$(E2E_TEST_HOME) SDK_E2E_TESTS_LOGS_DIR=$(E2E_TEST_HOME)/stdout-logs/ $(POETRY) run python build_scripts/sdk_login.py $(TEST_TOKEN_FILE)
LAYER_DEFAULT_PATH=$(E2E_TEST_HOME) SDK_E2E_TESTS_LOGS_DIR=$(E2E_TEST_HOME)/stdout-logs/ $(POETRY) run pytest $(E2E_TEST_SELECTOR) -s -vv $(DATADOG_ARGS) -m ray
$(POETRY) run ray stop
.PHONY: e2e-test
e2e-test: $(INSTALL_STAMP) $(TEST_TOKEN_FILE)
@rm -rf $(E2E_TEST_HOME)
ifdef CI
$(eval DATADOG_ARGS := --ddtrace-patch-all --ddtrace)
endif
LAYER_DEFAULT_PATH=$(E2E_TEST_HOME) SDK_E2E_TESTS_LOGS_DIR=$(E2E_TEST_HOME)/stdout-logs/ $(POETRY) run python build_scripts/sdk_login.py $(TEST_TOKEN_FILE)
LAYER_DEFAULT_PATH=$(E2E_TEST_HOME) SDK_E2E_TESTS_LOGS_DIR=$(E2E_TEST_HOME)/stdout-logs/ $(POETRY) run pytest $(E2E_TEST_SELECTOR) -s -n $(E2E_TEST_PARALLELISM) -vv $(DATADOG_ARGS) -m "not ray"
.PHONY: colab-test
colab-test: ## Run colab test against image pulled from dockerhub
# Catching sigint/sigterm to forcefully interrupt run on ctrl+c
@/bin/bash -c "trap \"trap - SIGINT SIGTERM ERR; echo colab-test cancelled by user; exit 1\" SIGINT SIGTERM ERR; $(MAKE) colab-test-internal"
.PHONY: format
format: $(INSTALL_STAMP) ## Apply formatters
$(POETRY) run isort .
$(POETRY) run black .
.PHONY: lint
lint: $(INSTALL_STAMP) ## Run all linters
$(POETRY) run isort --check-only .
$(POETRY) run black --check . --diff
$(POETRY) run flake8 .
$(POETRY) run pylint --recursive yes .
$(POETRY) run mypy .
$(POETRY) run bandit -c pyproject.toml -r .
$(POETRY) lock --check
.PHONY: check-package-loads
check-package-loads: ## Check that we can load the package without the dev dependencies
@rm -f $(INSTALL_STAMP)
ifdef IN_VENV
$(POETRY) install --no-dev
else
$(POETRY) install --no-dev --remove-untracked
endif
$(POETRY) run python -c "import layer"
.PHONY: check
check: test lint ## Run test and lint
.PHONY: publish
publish: ## Publish to PyPi - should only run in CI
@test $${PATCH_VERSION?PATCH_VERSION expected}
@test $${PYPI_USER?PYPI_USER expected}
@test $${PYPI_PASSWORD?PYPI_PASSWORD expected}
$(eval CURRENT_VERSION := $(shell $(POETRY) version --short))
$(eval PARTIAL_VERSION=$(shell echo $(CURRENT_VERSION) | grep -Po '.*(?=\.)'))
$(POETRY) version $(PARTIAL_VERSION).$(PATCH_VERSION)
$(POETRY) publish --build --username $(PYPI_USER) --password $(PYPI_PASSWORD)
$(POETRY) version $(CURRENT_VERSION)
.PHONY: deepclean
deepclean: clean ## Resets development environment including test credentials and venv
@rm -rf `poetry env info -p`
@rm -rf build
@rm -f $(TEST_TOKEN_FILE)
.PHONY: help
help: ## Show this help message.
@echo 'usage: make [target]'
@echo
@echo 'targets:'
@grep --no-filename -E '^[8+a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo