-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
67 lines (55 loc) · 2.67 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
VENV_DIR = venv
VERSION_SRC = cthulhucli.py
clean:
rm -rf build
rm -rf dist
rm -rf *.egg-info
rm -rf __pycache__
venv:
python3 -m venv ${VENV_DIR}
${VENV_DIR}/bin/pip install --upgrade pip
${VENV_DIR}/bin/pip install .[dev]
patch: venv lint test
@VERSION=$$(${VENV_DIR}/bin/bump --patch --reset ${VERSION_SRC}); git add -u && git commit -m"Version $${VERSION}" && git tag "v$${VERSION}"
minor: venv lint test
@VERSION=$$(${VENV_DIR}/bin/bump --minor --reset ${VERSION_SRC}); git add -u && git commit -m"Version $${VERSION}" && git tag "v$${VERSION}"
major: venv lint test
@VERSION=$$(${VENV_DIR}/bin/bump --major --reset ${VERSION_SRC}); git add -u && git commit -m"Version $${VERSION}" && git tag "v$${VERSION}"
clean-tags:
git tag --no-merged master | grep -e '^v[0-9]' | xargs git tag -d
dist: venv
${VENV_DIR}/bin/python -m build --no-isolation -o dist .
upload: venv
${VENV_DIR}/bin/twine upload dist/*
release: clean dist upload
lint: venv
${VENV_DIR}/bin/ruff check
${VENV_DIR}/bin/black --check cthulhucli.py
format: venv
${VENV_DIR}/bin/black cthulhucli.py
test: venv
@# Redirect stderr to stdout
@echo '>>> import sys; sys.stderr = sys.stdout' > README.md.test
@# Automagically import everything
@echo '>>> from cthulhucli import *' >> README.md.test
@# Turn off standalone_mode so launching the command doesn't sys.exit
@echo '>>> ModelBase._standalone_mode = False' >> README.md.test
@# Copy the README.md content
@echo '' >> README.md.test
@cat README.md >> README.md.test
@# Delete all lines between "[DOCTEST_BREAK]::" and "[DOCTEST_CONTINUE]::"
@sed -i '' '/^\[DOCTEST_BREAK\]::$$/,/^\[DOCTEST_CONTINUE\]::$$/ d' README.md.test
@# Replace cthulhucli commands with REPL equivalent
@sed -ri '' '/^```console$$/,/^```$$/ s/^. cthulhucli (.*)$$/>>> CthulhuModel.cli('\''\1'\'', reader=CthulhuReader)/g' README.md.test
@# Replace cthulhucli usage reference with doctest.py
@sed -ri '' '/^```console$$/,/^```$$/ s/Usage: cthulhucli/Usage: doctest.py/g' README.md.test
@# Replace empty lines in console code blocks with "<BLANKLINE>" (to match CLI output)
@sed -i '' '/^```console$$/,/^```$$/ s/^\s*$$/<BLANKLINE>/g' README.md.test
@# Remove empty lines in python code blocks (we don't expect output there)
@sed -i '' '/^```python$$/,/^```$$/{/^$$/d;}' README.md.test
@# Prepend lines in python code blocks with ">>>" or "..." (if indented)
@sed -ri '' '/^```python$$/,/^```$$/{s/^([^` ])/>>> \1/g;s/^([ ])/\.\.\. \1/g;}' README.md.test
@# Add an empty line at the end of code blocks for mark an end for doctest
@sed -i '' 's/^```$$/\n```/g' README.md.test
@# Run doctest!
COLUMNS=80 ${VENV_DIR}/bin/python -m doctest -o NORMALIZE_WHITESPACE -o ELLIPSIS ${SRC} README.md.test