Makefile 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. help: ## print short description of each target
  17. @python3 -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
  18. .PHONY: checks
  19. checks: ## run all the linting checks of the codebase
  20. @echo "=== pre-commit ==="; poetry run pre-commit run --all-files || echo "--- pre-commit failed ---" >&2; \
  21. echo "=== mypy ==="; MYPYPATH=stubs poetry run mypy src || echo "--- mypy failed ---" >&2; \
  22. echo "======"
  23. .PHONY: black
  24. black: ## format the code using black
  25. poetry run black src tests docs/source/conf.py scripts docs/source/notebooks/*.py
  26. poetry run blackdoc src
  27. .PHONY: ruff-fixes
  28. ruff-fixes: ## fix the code using ruff
  29. poetry run ruff src tests scripts docs/source/conf.py docs/source/notebooks/*.py --fix
  30. .PHONY: test
  31. test: ## run the tests
  32. poetry run pytest src tests -r a -v --doctest-modules --cov=src
  33. # Note on code coverage and testing:
  34. # You must specify cov=src as otherwise funny things happen when doctests are
  35. # involved.
  36. # If you want to debug what is going on with coverage, we have found
  37. # that adding COVERAGE_DEBUG=trace to the front of the below command
  38. # can be very helpful as it shows you if coverage is tracking the coverage
  39. # of all of the expected files or not.
  40. # We are sure that the coverage maintainers would appreciate a PR that improves
  41. # the coverage handling when there are doctests and a `src` layout like ours.
  42. .PHONY: docs
  43. docs: ## build the docs
  44. poetry run sphinx-build -T -b html docs/source docs/build/html
  45. .PHONY: changelog-draft
  46. changelog-draft: ## compile a draft of the next changelog
  47. poetry run towncrier build --draft
  48. .PHONY: licence-check
  49. licence-check: ## Check that licences of the dependencies are suitable
  50. # Will likely fail on Windows, but Makefiles are in general not Windows
  51. # compatible so we're not too worried
  52. poetry export --without=tests --without=docs --without=dev > $(TEMP_FILE)
  53. poetry run liccheck -r $(TEMP_FILE) -R licence-check.txt
  54. rm -f $(TEMP_FILE)
  55. .PHONY: virtual-environment
  56. virtual-environment: ## update virtual environment, create a new one if it doesn't already exist
  57. poetry lock
  58. # Put virtual environments in the project
  59. poetry config virtualenvs.in-project true
  60. poetry install --all-extras
  61. poetry run pre-commit install