|
| 1 | +## To get help on this makefile, run `make help`. |
| 2 | +# https://www.gnu.org/software/make/manual/make.html |
| 3 | + |
| 4 | +# Adapt these variables for this project: |
| 5 | +py_code_locs = merge_insertion tests |
| 6 | +# Hint: $(filter-out whatever,$(py_code_locs)) |
| 7 | +# Remember to keep in sync with GitHub Actions workflows: |
| 8 | +requirement_txts = dev/requirements.txt docs/requirements.txt |
| 9 | +perm_checks = ./* .gitignore .vscode .github |
| 10 | + |
| 11 | +# The user can change the following on the command line: |
| 12 | +PYTHON3BIN = python |
| 13 | + |
| 14 | +.PHONY: help tasklist installdeps test build-check |
| 15 | +.PHONY: smoke-checks nix-checks shellcheck ver-checks other-checks coverage unittest |
| 16 | +test: smoke-checks nix-checks shellcheck ver-checks other-checks coverage ## Run all tests |
| 17 | +# Reminder: If the `test` target changes, make the appropriate changes to .github/workflows/tests.yml |
| 18 | + |
| 19 | +SHELL = /bin/bash |
| 20 | +.ONESHELL: # each recipe is executed as a single script |
| 21 | + |
| 22 | +README.md: docs/requirements.txt docs/conf.py docs/index.rst merge_insertion/__init__.py |
| 23 | + @set -euxo pipefail |
| 24 | + make -C docs output/markdown/index.md |
| 25 | + cp docs/output/markdown/index.md README.md |
| 26 | + make -C docs clean |
| 27 | + |
| 28 | +build-check: smoke-checks |
| 29 | + @set -euxo pipefail |
| 30 | + [[ "$$OSTYPE" =~ linux.* ]] |
| 31 | + $(PYTHON3BIN) -m build --sdist |
| 32 | + dist_files=(dist/*.tar.gz) |
| 33 | + $(PYTHON3BIN) -m twine check --strict "$${dist_files[@]}" |
| 34 | + if [[ $${#dist_files[@]} -ne 1 ]]; then echo "More than one dist file:" "$${dist_files[@]}"; exit 1; fi |
| 35 | + PYTHON3BIN="$(PYTHON3BIN)" dev/isolated-dist-test.sh "$${dist_files[0]}" |
| 36 | + echo "$${dist_files[@]}" |
| 37 | + |
| 38 | +tasklist: ## List open tasks. |
| 39 | + @grep --color=auto \ |
| 40 | + --exclude-dir=.git --exclude-dir=__pycache__ --exclude-dir=.ipynb_checkpoints --exclude-dir='.venv*' \ |
| 41 | + --exclude-dir='.*cache' --exclude-dir=node_modules --exclude='LICENSE*' --exclude='.*.swp' \ |
| 42 | + -Eri '\bto.?do\b' |
| 43 | + true # ignore nonzero exit code from grep |
| 44 | + |
| 45 | +installdeps: ## Install project dependencies |
| 46 | + @set -euxo pipefail |
| 47 | + $(PYTHON3BIN) -m pip install --upgrade --upgrade-strategy=eager --no-warn-script-location pip |
| 48 | + $(PYTHON3BIN) -m pip install --upgrade --upgrade-strategy=eager --no-warn-script-location $(foreach x,$(requirement_txts),-r $(x)) |
| 49 | + # $(PYTHON3BIN) -m pip install --editable . # for modules/packages |
| 50 | + # other examples: git lfs install / npm ci |
| 51 | + |
| 52 | +smoke-checks: ## Basic smoke tests |
| 53 | + @set -euxo pipefail |
| 54 | + # example: [[ "$$OSTYPE" =~ linux.* ]] # this project only runs on Linux |
| 55 | + $(PYTHON3BIN) -c 'import sys; sys.exit(0 if sys.version_info.major==3 else 1)' # make sure we're on Python 3 |
| 56 | + |
| 57 | +nix-checks: ## Checks that depend on a *NIX OS/FS |
| 58 | + @set -euo pipefail |
| 59 | + unreliable_perms="yes" |
| 60 | + if [ "$$OSTYPE" == "msys" ]; then # e.g. Git bash on Windows |
| 61 | + echo "- Assuming unreliable permission bits because Windows" |
| 62 | + set -x |
| 63 | + else |
| 64 | + fstype="$$( findmnt --all --first --noheadings --list --output FSTYPE --notruncate --target . )" |
| 65 | + if [[ "$$fstype" =~ ^(vfat|vboxsf|9p)$$ ]]; then |
| 66 | + echo "- Assuming unreliable permission bits because fstype=$$fstype" |
| 67 | + set -x |
| 68 | + else # we can probably depend on permission bits being correct |
| 69 | + unreliable_perms="" |
| 70 | + set -x |
| 71 | + $(PYTHON3BIN) -m simple_perms -r $(perm_checks) # if this errors, run `simple-perms -m ...` for auto fix |
| 72 | + test -z "$$( find . \( -type d -name '.venv*' -prune \) -o \( -iname '*.sh' ! -executable -print \) )" |
| 73 | + fi |
| 74 | + fi |
| 75 | + # exclusions to the following can be done by adding a line `-path '*/exclude/me.py' -o \` after `find` |
| 76 | + find $(py_code_locs) \ |
| 77 | + -type f -iname '*.py' -exec \ |
| 78 | + $(PYTHON3BIN) -m igbpyutils.dev.script_vs_lib $${unreliable_perms:+"--exec-git"} --notice '{}' + |
| 79 | + |
| 80 | +shellcheck: ## Run shellcheck |
| 81 | + @set -euxo pipefail |
| 82 | + # https://www.gnu.org/software/findutils/manual/html_mono/find.html |
| 83 | + find . \( -type d \( -name '.venv*' -o -name '.devpod-internal' \) -prune \) -o \( -iname '*.sh' -exec shellcheck '{}' + \) |
| 84 | + |
| 85 | +ver-checks: ## Checks that depend on the Python version |
| 86 | + @set -euxo pipefail |
| 87 | + # https://microsoft.github.io/pyright/#/command-line |
| 88 | + npx pyright --project pyproject.toml --pythonpath "$$( $(PYTHON3BIN) -c 'import sys; print(sys.executable)' )" $(py_code_locs) |
| 89 | + $(PYTHON3BIN) -m mypy --config-file pyproject.toml $(py_code_locs) |
| 90 | + $(PYTHON3BIN) -m flake8 --toml-config=pyproject.toml $(py_code_locs) |
| 91 | + $(PYTHON3BIN) -m pylint --rcfile=pyproject.toml --recursive=y $(py_code_locs) |
| 92 | + |
| 93 | +other-checks: ## Checks not depending on the Python version |
| 94 | + @set -euxo pipefail |
| 95 | + # note the following is on one line b/c GitHub macOS Action Runners are running bash 3.2 and the multiline version didn't work there... |
| 96 | + for REQ in $(requirement_txts); do $(PYTHON3BIN) -m pur --skip-gt --dry-run-changed --nonzero-exit-code -r "$$REQ"; done |
| 97 | + |
| 98 | +unittest: ## Run unit tests |
| 99 | + $(PYTHON3BIN) -X dev -X warn_default_encoding -W error -m unittest -v |
| 100 | + |
| 101 | +coverage: ## Run unit tests with coverage |
| 102 | + @set -euxo pipefail |
| 103 | + # Note: Don't add command-line arguments here, put them in the rcfile |
| 104 | + # We also don't use --fail_under=100 because then the report won't be written. |
| 105 | + $(PYTHON3BIN) -X dev -X warn_default_encoding -W error -m coverage run --rcfile=pyproject.toml |
| 106 | + $(PYTHON3BIN) -m coverage report --rcfile=pyproject.toml |
| 107 | + # $(PYTHON3BIN) -m coverage html --rcfile=pyproject.toml |
| 108 | + $(PYTHON3BIN) -m coverage xml --rcfile=pyproject.toml |
| 109 | + $(PYTHON3BIN) -m coverage json --rcfile=pyproject.toml -o- \ |
| 110 | + | perl -wM5.014 -MJSON::PP=decode_json -MTerm::ANSIColor=colored -0777 -ne \ |
| 111 | + '$$_=decode_json($$_)->{totals}{percent_covered};print"=> ",colored([$$_==100?"green":"red"],"$$_% Coverage")," <=\n";exit($$_==100?0:1)' |
| 112 | + |
| 113 | +# https://stackoverflow.com/q/8889035 |
| 114 | +help: ## Show this help |
| 115 | + @sed -ne 's/^\([^[:space:]]*\):.*##/\1:\t/p' $(MAKEFILE_LIST) | column -t -s $$'\t' |
0 commit comments