Makefile 2.9 KB

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