-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
209 lines (172 loc) · 6.4 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# Makefile for python_secrets
SHELL=bash
VERSION=$(shell cat VERSION)
PROJECT:=$(shell basename `pwd`)
# Install poetry into conda environment
export POETRY_HOME:=$(CONDA_PREFIX)
POETRY_INSTALL_URL=https://raw.githubusercontent.com/python-poetry/install.python-poetry.org/refs/heads/main/install-poetry.py
POETRY_VERSION=1.8.3
.PHONY: default
default: all
.PHONY: all
all: install
.PHONY: help
help:
@echo 'usage: make [VARIABLE=value] [target [target..]]'
@echo ''
@echo 'build - build project packages'
@echo 'twine-check - run "twine check"'
@echo 'clean - remove build artifacts'
@echo 'spotless - deep clean'
@echo 'test - generic target for both "test-tox" and "test-bats"'
@echo 'test-tox - run tox tests'
@echo 'test-bats - run Bats unit tests'
@echo 'test-bats-runtime - run Bats runtime integration/system tests'
@echo 'release - produce a pypi production release'
@echo 'release-test - produce a pypi test release'
@echo 'release-prep - final documentation preparations for release'
@echo 'install - build project with Poetry and install with Pip'
@echo 'update-packages - update dependencies with Poetry'
@echo 'docs-tests - generate bats test output for documentation'
@echo 'docs-help - generate "psec help" output for documentation'
@echo 'docs - build Sphinx docs'
#HELP test - run 'tox' for testing
.PHONY: test
test: test-tox
@echo '[+] test: All tests passed'
# [Makefile-test-tox]
# The following target rules are optimized by splitting up `tox` tests so they
# fail early on syntax and security checks before running more lengthy unit
# tests against Python versions (with coverage reporting). This is designed to
# more easily focus on code quality first and foremost.
.PHONY: test-tox
test-tox:
@if [ -f .python_secrets_environment ]; then (echo '[!] Remove .python_secrets_environment prior to testing'; exit 1); fi
touch docs/psec_help.txt
@# See also comment in tox.ini file.
tox run -m static
tox run -m tests
# ![Makefile-test-tox]
.PHONY: test-bats
test-bats: bats-libraries
@if [ "$(TRAVIS)" != "true" ]; then \
if ! type bats 2>/dev/null >/dev/null; then \
echo "[-] Skipping bats tests"; \
else \
source test-environment.bash; \
echo "[+] Running bats tests: $(shell cd tests && echo [0-9][0-9]*.bats)"; \
PYTHONWARNINGS="ignore" bats --tap tests/[0-9][0-9]*.bats && \
echo '[+] test-bats: All tests passed'; \
fi \
fi
.PHONY: test-bats-runtime
test-bats-runtime: bats-libraries
@echo "[+] Running bats runtime tests: $(shell cd tests && echo runtime_[0-9][0-9]*.bats)"; \
(source test-environment.bash; \
PYTHONWARNINGS="ignore" bats --tap tests/runtime_[0-9][0-9]*.bats && \
echo '[+] test-bats-runtime: All tests passed')
.PHONY: no-diffs
no-diffs:
@echo 'Checking Git for uncommitted changes'
git diff --quiet HEAD
#HELP release - package and upload a release to pypi
.PHONY: release
release: clean docs build twine-check
(cd dist && twine upload $$(cat .LATEST_*) -r pypi)
#HELP release-prep - final documentation preparations for release
.PHONY: release-prep
release-prep: install clean build docs-help docs-tests
@echo 'Check in help text docs and HISTORY.rst?'
#HELP release-test - upload to "testpypi"
.PHONY: release-test
release-test: clean test docs-tests docs twine-check
$(MAKE) no-diffs
(cd dist && twine upload $$(cat .LATEST_*) -r testpypi)
#HELP build - build project packages
.PHONY: build
build:
@rm -f dist/.LATEST_TARGZ dist/.LATEST_WHEEL
poetry build
@(cd dist && ls -t *.tar.gz 2>/dev/null | head -n 1 > .LATEST_TARGZ)
@(cd dist && ls -t *.whl 2>/dev/null | head -n 1 > .LATEST_WHEEL)
#HELP twine-check
.PHONY: twine-check
twine-check: build
(cd dist && twine check $$(cat .LATEST_*))
#HELP clean - remove build artifacts
.PHONY: clean
clean: clean-docs
rm -f psec/_version.py
rm -rf dist build *.egg-info
find . -name '*.pyc' -delete
.PHONY: clean-docs
clean-docs:
cd docs && make clean
.PHONY: spotless
spotless: clean
rm -rf htmlcov
rm -rf .tox/
python -m pip uninstall -y $(PROJECT)
#HELP install - build project with Poetry and install with Pip'
.PHONY: i
.PHONY: install
i install: clean build
(cd dist && python -m pip install $$(cat .LATEST_WHEEL) --force-reinstall)
#HELP uninstall - uninstall project package from active virtualenv'
.PHONY: uninstall
uninstall:
python -m pip uninstall python_secrets
# dittrich 2024-10-08 Assuming use of conda environments right now...
.PHONY: install-poetry
install-poetry:
@if [[ "$(shell poetry --version 2>/dev/null)" =~ "$(POETRY_VERSION)" ]]; then \
echo "[+] poetry version $(POETRY_VERSION) is already installed"; \
else \
(curl -sSL $(POETRY_INSTALL_URL) | python - --version $(POETRY_VERSION)); \
poetry self add "poetry-dynamic-versioning[plugin]"; \
fi
.PHONY: uninstall-poetry
uninstall-poetry:
curl -sSL $(POETRY_INSTALL_URL) | python - --version $(POETRY_VERSION) --uninstall
#HELP update-packages - update dependencies with Poetry
.PHONY: update-packages
update-packages:
poetry update
#HELP docs-tests - generate bats test output for documentation
.PHONY: docs-tests
PR=pr --omit-header --omit-pagination --page-width 80
docs-tests:
$(MAKE) -B docs/test-tox.txt
$(MAKE) -B docs/test-bats.txt
$(MAKE) -B docs/test-bats-runtime.txt
docs/test-tox.txt:
(echo '$$ make test-tox' && $(MAKE) test-tox) |\
$(PR) | tee docs/test-tox.txt
docs/test-bats.txt:
$(MAKE) test-bats | $(PR) | tee docs/test-bats.txt
docs/test-bats-runtime.txt:
(echo '$$ make test-bats-runtime' && $(MAKE) test-bats-runtime) |\
$(PR) | tee docs/test-bats-runtime.txt
#HELP docs - build Sphinx docs (NOT INTEGRATED YET FROM OPENSTACK CODE BASE)
.PHONY: docs
docs: docs/psec_help.txt
cd docs && make html
docs/psec_help.txt: install
PYTHONPATH=$(shell pwd) python -m psec help | tee docs/psec_help.txt
#HELP examples - produce some example output for docs
.PHONY: examples
examples:
@PYTHONPATH=$(shell pwd) python -m psec --help
# Git submodules and subtrees are both a huge PITA. This is way simpler.
.PHONY: bats-libraries
bats-libraries: bats bats-support bats-assert
bats:
@[ -d tests/libs/bats ] || \
(mkdir -p tests/libs/bats; git clone http://github.com/sstephenson/bats tests/libs/bats)
bats-support:
@[ -d tests/libs/bats-support ] || \
(mkdir -p tests/libs/bats-support; git clone https://github.com/ztombol/bats-support tests/libs/bats-support)
bats-assert:
@[ -d tests/libs/bats-assert ] || \
(mkdir -p tests/libs/bats-assert; git clone https://github.com/ztombol/bats-assert tests/libs/bats-assert)
#EOF