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