-
Notifications
You must be signed in to change notification settings - Fork 387
Expand file tree
/
Copy pathMakefile
More file actions
137 lines (106 loc) · 3.52 KB
/
Copy pathMakefile
File metadata and controls
137 lines (106 loc) · 3.52 KB
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
### Conveniences for splunk-sdk-python development
## VIRTUALENV MANAGEMENT
# https://docs.astral.sh/uv/reference/cli/#uv-sync
# --no-config skips Splunk's internal PyPI mirror
UV_SYNC_CMD := uv sync --no-config
# https://docs.astral.sh/uv/reference/cli/#uv-run
UV_RUN_CMD := uv run
# https://docs.zizmor.sh/usage
ZIZMOR_CMD := $(UV_RUN_CMD) zizmor --pedantic --strict-collection
.PHONY: install
install:
$(UV_SYNC_CMD) --dev
.PHONY: upgrade
upgrade:
$(UV_SYNC_CMD) --dev --upgrade
# Workaround for make being unable to pass arguments to underlying cmd
# $ SDK_DEPS_GROUP="build" make ci-install
SDK_DEPS_GROUP ?= dev
.PHONY: ci-install
ci-install:
$(UV_SYNC_CMD) --frozen --group $(SDK_DEPS_GROUP)
.PHONY: lint
lint: lint-python lint-gh-actions lint-makefile
.PHONY: lint-gh-actions
lint-gh-actions:
$(ZIZMOR_CMD) ./.github
.PHONY: lint-python
lint-python:
$(UV_RUN_CMD) ruff check --fix-only $(if $(CI),--exit-non-zero-on-fix)
$(UV_RUN_CMD) ruff format $(if $(CI),--check)
$(UV_RUN_CMD) basedpyright
.PHONY: lint-makefile
lint-makefile:
$(UV_RUN_CMD) mbake format --config ./.bake.toml $(if $(CI),--check) Makefile
$(if $(CI),$(UV_RUN_CMD) mbake validate --config ./.bake.toml Makefile)
.PHONY: clean
clean:
rm -rf ./build ./dist ./.venv ./.ruff_cache ./.pytest_cache ./splunk_sdk.egg-info ./__pycache__
find . -name __pycache__ -type d -exec rm -rf {} +
DOCS_BUILDDIR := docs/_build
DOCS_HTMLDIR := $(DOCS_BUILDDIR)/html
DOCS_ZIPFILE := $(DOCS_BUILDDIR)/splunk-sdk-python-docs.zip
.PHONY: docs
docs:
rm -rf $(DOCS_BUILDDIR)
sphinx-build -b html -d $(DOCS_BUILDDIR)/doctrees ./docs $(DOCS_HTMLDIR)
sh docs/munge_links.sh $(DOCS_HTMLDIR)
@echo "[splunk-sdk] ---"
@echo "[splunk-sdk] Build finished. HTML pages available at $(DOCS_HTMLDIR)."
.PHONY: docs-zip
docs-zip: docs
cd $(DOCS_HTMLDIR) && zip -r $(abspath $(DOCS_ZIPFILE)) .
@echo "[splunk-sdk] Zip available at $(DOCS_ZIPFILE)."
## TESTING
# --ff lets previously failing tests go first
# -ra prints a report on all failed tests after a run
# -vv shows why a test failed while the rest of the suite is running
PYTHON_CMD := uv run python
PYTEST_CMD := $(PYTHON_CMD) -m pytest --no-header --ff -ra -vv
.PHONY: test
test:
$(PYTEST_CMD) ./tests
.PHONY: test-unit
test-unit:
$(PYTEST_CMD) ./tests/unit
.PHONY: test-integration
test-integration:
$(PYTEST_CMD) ./tests/integration ./tests/system
.PHONY: test-ai
test-ai:
$(PYTEST_CMD) ./tests/integration/ai ./tests/unit/ai
## DOCKER
CONTAINER_NAME := splunk
SPLUNK_HOME := /opt/splunk
.PHONY: docker-up
docker-up:
# For podman (at least on macOS) you might need to add DOCKER_BUILDKIT=0
# --build forces Docker to build a new image instead of using an existing one
docker compose up -d --build
.PHONY: docker-ensure-up
docker-ensure-up:
@for i in `seq 0 180`; do \
if docker exec -it $(CONTAINER_NAME) /bin/bash -c "/sbin/checkstate.sh &> /dev/null"; then \
break; \
fi; \
printf "\rWaiting for Splunk for %s seconds..." $$i; \
sleep 1; \
done
.PHONY: docker-start
docker-start: docker-up docker-ensure-up
.PHONY: docker-down
docker-down:
docker compose stop
.PHONY: docker-restart
docker-restart: docker-down docker-start
.PHONY: docker-remove
docker-remove:
docker compose rm -f -s
.PHONY: docker-refresh
docker-refresh: docker-remove docker-start
.PHONY: docker-splunk-restart
docker-splunk-restart:
docker exec -u splunk $(CONTAINER_NAME) $(SPLUNK_HOME)/bin/splunk restart
.PHONY: docker-tail-python-log
docker-tail-python-log:
docker exec -u root $(CONTAINER_NAME) sudo tail -n 20 $(SPLUNK_HOME)/var/log/splunk/python.log