Makefile 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Makefile to help automate key steps
  2. .DEFAULT_GOAL := help
  3. # Will likely fail on Windows, but Makefiles are in general not Windows
  4. # compatible so we're not too worried
  5. TEMP_FILE := $(shell mktemp)
  6. # A helper script to get short descriptions of each target in the Makefile
  7. define PRINT_HELP_PYSCRIPT
  8. import re, sys
  9. for line in sys.stdin:
  10. match = re.match(r'^([\$$\(\)a-zA-Z_-]+):.*?## (.*)$$', line)
  11. if match:
  12. target, help = match.groups()
  13. print("%-30s %s" % (target, help))
  14. endef
  15. export PRINT_HELP_PYSCRIPT
  16. .PHONY: help
  17. help: ## print short description of each target
  18. @python3 -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
  19. .PHONY: checks
  20. checks: ## run all the linting checks of the codebase
  21. @echo "=== pre-commit ==="; poetry run pre-commit run --all-files || echo "--- pre-commit failed ---" >&2; \
  22. echo "=== mypy ==="; MYPYPATH=stubs poetry run mypy src || echo "--- mypy failed ---" >&2; \
  23. echo "======"
  24. .PHONY: ruff-fixes
  25. ruff-fixes: ## fix the code using ruff
  26. # format before and after checking so that the formatted stuff is checked and
  27. # the fixed stuff is formatted
  28. poetry run ruff format src tests scripts docs/source/conf.py docs/source/notebooks/*.py
  29. poetry run ruff src tests scripts docs/source/conf.py docs/source/notebooks/*.py --fix
  30. poetry run ruff format src tests scripts docs/source/conf.py docs/source/notebooks/*.py
  31. .PHONY: test
  32. test: ## run the tests
  33. poetry run pytest src tests -r a -v --doctest-modules --cov=src
  34. # Note on code coverage and testing:
  35. # You must specify cov=src as otherwise funny things happen when doctests are
  36. # involved.
  37. # If you want to debug what is going on with coverage, we have found
  38. # that adding COVERAGE_DEBUG=trace to the front of the below command
  39. # can be very helpful as it shows you if coverage is tracking the coverage
  40. # of all of the expected files or not.
  41. # We are sure that the coverage maintainers would appreciate a PR that improves
  42. # the coverage handling when there are doctests and a `src` layout like ours.
  43. .PHONY: docs
  44. docs: ## build the docs
  45. poetry run sphinx-build -T -b html docs/source docs/build/html
  46. .PHONY: changelog-draft
  47. changelog-draft: ## compile a draft of the next changelog
  48. poetry run towncrier build --draft
  49. .PHONY: licence-check
  50. licence-check: ## Check that licences of the dependencies are suitable
  51. # Will likely fail on Windows, but Makefiles are in general not Windows
  52. # compatible so we're not too worried
  53. poetry export --without=tests --without=docs --without=dev > $(TEMP_FILE)
  54. poetry run liccheck -r $(TEMP_FILE) -R licence-check.txt
  55. rm -f $(TEMP_FILE)
  56. .PHONY: virtual-environment
  57. virtual-environment: ## update virtual environment, create a new one if it doesn't already exist
  58. # Ensure that the lock file is up to date,
  59. # but don't update dependencies in the process
  60. # see https://python-poetry.org/docs/cli/#lock
  61. poetry lock --no-update
  62. # Put virtual environments in the project
  63. poetry config virtualenvs.in-project true
  64. poetry install --all-extras
  65. poetry run pre-commit install