|
| 1 | +# Makefile for Python project |
| 2 | + |
| 3 | +.DELETE_ON_ERROR: |
| 4 | +.PHONY: FORCE |
| 5 | +.PRECIOUS: |
| 6 | +.SUFFIXES: |
| 7 | + |
| 8 | +ifeq ("","$(shell command -v zsh)") |
| 9 | +$(error "zsh not found; you must install zsh first") |
| 10 | +endif |
| 11 | + |
| 12 | +SHELL:=zsh -eu -o pipefail -o null_glob |
| 13 | +SELF:=$(firstword $(MAKEFILE_LIST)) |
| 14 | + |
| 15 | +VE_DIR:=.venv |
| 16 | +PY_VERSION:=3.13 |
| 17 | + |
| 18 | +SRC_DIRS:=src |
| 19 | +TEST_DIRS:=tests |
| 20 | +DOC_TESTS:=${SRC_DIRS} # ./README.md |
| 21 | + |
| 22 | + |
| 23 | +############################################################################ |
| 24 | +#= BASIC USAGE |
| 25 | +default: help |
| 26 | + |
| 27 | +#=> help -- display this help message |
| 28 | +help: |
| 29 | + @sbin/makefile-extract-documentation "${SELF}" |
| 30 | + |
| 31 | + |
| 32 | +############################################################################ |
| 33 | +#= SETUP, INSTALLATION, PACKAGING |
| 34 | + |
| 35 | +#=> devready: create venv, install prerequisites, install pkg in develop mode |
| 36 | +.PHONY: devready |
| 37 | +devready: |
| 38 | + make ${VE_DIR} && source ${VE_DIR}/bin/activate && make develop |
| 39 | + @echo '#################################################################################' |
| 40 | + @echo '### Do not forget to `source ${VE_DIR}/bin/activate` to use this environment ###' |
| 41 | + @echo '#################################################################################' |
| 42 | + |
| 43 | +#=> venv: make a Python 3 virtual environment |
| 44 | +${VE_DIR}: |
| 45 | + uv venv --python ${PY_VERSION} $@ |
| 46 | + |
| 47 | +#=> develop: install package in develop mode |
| 48 | +.PHONY: develop |
| 49 | +develop: |
| 50 | + uv sync --extra dev --extra tests |
| 51 | + pre-commit install |
| 52 | + |
| 53 | +#=> install: install package |
| 54 | +.PHONY: install |
| 55 | +install: |
| 56 | + uv sync |
| 57 | + |
| 58 | +#=> build: make sdist and wheel |
| 59 | +.PHONY: build |
| 60 | +build: %: |
| 61 | + python -m build |
| 62 | + |
| 63 | + |
| 64 | +############################################################################ |
| 65 | +#= TESTING |
| 66 | +# see test configuration in setup.cfg |
| 67 | + |
| 68 | +#=> test: execute tests |
| 69 | +#=> test-code: test code (including embedded doctests) |
| 70 | +#=> test-docs: test example code in docs |
| 71 | +.PHONY: test test-code test-docs |
| 72 | +test: |
| 73 | + pytest --cov ${SRC_DIRS} |
| 74 | +test-code: |
| 75 | + pytest ${TEST_DIRS} |
| 76 | +test-docs: |
| 77 | + pytest ${DOC_TESTS} |
| 78 | +stest: |
| 79 | + pytest -vvv -s -k ${t} |
| 80 | +test-%: |
| 81 | + pytest -m '$*' ${TEST_DIRS} |
| 82 | + |
| 83 | +#=> tox -- run all tox tests |
| 84 | +tox: |
| 85 | + uvx tox |
| 86 | + |
| 87 | +#=> cqa: execute code quality tests |
| 88 | +cqa: |
| 89 | + uvx ruff format --check |
| 90 | + uvx ruff check |
| 91 | + |
| 92 | +############################################################################ |
| 93 | +#= UTILITY TARGETS |
| 94 | + |
| 95 | +#=> reformat: reformat code |
| 96 | +.PHONY: reformat |
| 97 | +reformat: |
| 98 | + uvx ruff check --fix |
| 99 | + uvx ruff format |
| 100 | + |
| 101 | +#=> docs -- make sphinx docs |
| 102 | +.PHONY: docs |
| 103 | +docs: develop |
| 104 | + # RTD makes json. Build here to ensure that it works. |
| 105 | + make -C docs html json |
| 106 | + |
| 107 | +############################################################################ |
| 108 | +#= CLEANUP |
| 109 | + |
| 110 | +#=> clean: remove temporary and backup files |
| 111 | +.PHONY: clean |
| 112 | +clean: |
| 113 | + rm -frv **/*~ **/*.bak |
| 114 | + -make -C docs $@ |
| 115 | + -make -C examples $@ |
| 116 | + |
| 117 | +#=> cleaner: remove files and directories that are easily rebuilt |
| 118 | +.PHONY: cleaner |
| 119 | +cleaner: clean |
| 120 | + rm -frv .cache build dist docs/_build |
| 121 | + rm -frv **/__pycache__ |
| 122 | + rm -frv **/*.egg-info |
| 123 | + rm -frv **/*.pyc |
| 124 | + rm -frv **/*.orig |
| 125 | + rm -frv **/*.rej |
| 126 | + -make -C docs $@ |
| 127 | + -make -C examples $@ |
| 128 | + |
| 129 | +#=> cleanest: remove files and directories that are more expensive to rebuild |
| 130 | +.PHONY: cleanest |
| 131 | +cleanest: cleaner |
| 132 | + rm -frv .eggs .tox venv |
| 133 | + -make -C docs $@ |
| 134 | + -make -C examples $@ |
| 135 | + |
| 136 | +#=> distclean: remove untracked files and other detritus |
| 137 | +.PHONY: distclean |
| 138 | +distclean: cleanest |
| 139 | + git clean -df |
| 140 | + |
| 141 | + |
| 142 | +############################################################################ |
| 143 | +#= Repo renamer |
| 144 | + |
| 145 | +#=> rename: rename files and substitute content for new repo name |
| 146 | +.PHONY: rename |
| 147 | +rename: |
| 148 | + ./sbin/rename-package |
| 149 | + |
| 150 | + |
| 151 | +## <LICENSE> |
| 152 | +## Copyright 2023 Source Code Committers |
| 153 | +## |
| 154 | +## Licensed under the Apache License, Version 2.0 (the "License"); |
| 155 | +## you may not use this file except in compliance with the License. |
| 156 | +## You may obtain a copy of the License at |
| 157 | +## |
| 158 | +## http://www.apache.org/licenses/LICENSE-2.0 |
| 159 | +## |
| 160 | +## Unless required by applicable law or agreed to in writing, software |
| 161 | +## distributed under the License is distributed on an "AS IS" BASIS, |
| 162 | +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 163 | +## See the License for the specific language governing permissions and |
| 164 | +## limitations under the License. |
| 165 | +## </LICENSE> |
0 commit comments