|
1 | | -SHELL := /bin/bash |
2 | | -# ============================================================================= |
3 | | -# Variables |
4 | | -# ============================================================================= |
5 | | - |
6 | 1 | .DEFAULT_GOAL:=help |
7 | 2 | .ONESHELL: |
8 | | -USING_PDM = $(shell grep "tool.pdm" pyproject.toml && echo "yes") |
9 | | -ENV_PREFIX = $(shell python3 -c "if __import__('pathlib').Path('.venv/bin/pip').exists(): print('.venv/bin/')") |
10 | | -VENV_EXISTS = $(shell python3 -c "if __import__('pathlib').Path('.venv/bin/activate').exists(): print('yes')") |
11 | | -PDM_OPTS ?= |
12 | | -PDM ?= pdm $(PDM_OPTS) |
| 3 | +ENV_PREFIX =.venv/bin/ |
| 4 | +VENV_EXISTS = $(shell python3 -c "if __import__('pathlib').Path('.venv/bin/activate').exists(): print('yes')") |
| 5 | +BUILD_DIR =dist |
| 6 | +SRC_DIR =src |
| 7 | +BASE_DIR =$(shell pwd) |
13 | 8 |
|
14 | 9 | .EXPORT_ALL_VARIABLES: |
15 | 10 |
|
| 11 | +ifndef VERBOSE |
| 12 | +.SILENT: |
| 13 | +endif |
| 14 | + |
16 | 15 |
|
17 | | -.PHONY: help |
18 | | -help: ## Display this help text for Makefile |
| 16 | +help: ## Display this help |
19 | 17 | @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) |
20 | 18 |
|
21 | | -.PHONY: upgrade |
22 | | -upgrade: ## Upgrade all dependencies to the latest stable versions |
23 | | - @echo "=> Updating all dependencies" |
24 | | - @if [ "$(USING_PDM)" ]; then $(PDM) update; fi |
25 | | - @echo "=> Dependencies Updated" |
26 | | - @$(ENV_PREFIX)pre-commit autoupdate |
27 | | - @echo "=> Updated Pre-commit" |
28 | 19 |
|
29 | 20 | # ============================================================================= |
30 | 21 | # Developer Utils |
31 | 22 | # ============================================================================= |
32 | | -.PHONY: install-pdm |
33 | | -install-pdm: ## Install latest version of PDM |
34 | | - @curl -sSLO https://pdm.fming.dev/install-pdm.py && \ |
35 | | - curl -sSL https://pdm.fming.dev/install-pdm.py.sha256 | shasum -a 256 -c - && \ |
36 | | - python3 install-pdm.py |
37 | | - |
38 | | -install: ## Install the project and |
39 | | - @if ! $(PDM) --version > /dev/null; then echo '=> Installing PDM'; $(MAKE) install-pdm; fi |
40 | | - @if [ "$(VENV_EXISTS)" ]; then echo "=> Removing existing virtual environment"; fi |
41 | | - if [ "$(VENV_EXISTS)" ]; then $(MAKE) destroy; fi |
42 | | - if [ "$(VENV_EXISTS)" ]; then $(MAKE) clean; fi |
43 | | - @if [ "$(USING_PDM)" ]; then $(PDM) config venv.in_project true && python3 -m venv --copies .venv && . $(ENV_PREFIX)/activate && $(ENV_PREFIX)/pip install --quiet -U wheel setuptools cython pip; fi |
44 | | - @if [ "$(USING_PDM)" ]; then $(PDM) install -G:all; fi |
| 23 | +install-hatch: ## Install Hatch |
| 24 | + @sh ./scripts/install-hatch.sh |
| 25 | + |
| 26 | +configure-hatch: ## Configure Hatch defaults |
| 27 | + @hatch config set dirs.env.virtual .direnv |
| 28 | + @hatch config set dirs.env.pip-compile .direnv |
| 29 | + |
| 30 | +upgrade-hatch: ## Update Hatch, UV, and Ruff |
| 31 | + @hatch self update |
| 32 | + |
| 33 | +install: ## Install the project and all dependencies |
| 34 | + @if [ "$(VENV_EXISTS)" ]; then echo "=> Removing existing virtual environment"; $(MAKE) destroy-venv; fi |
| 35 | + @$(MAKE) clean |
| 36 | + @if ! hatch --version > /dev/null; then echo '=> Installing `hatch` with standalone installation'; $(MAKE) install-hatch ; fi |
| 37 | + @echo "=> Creating Python environments..." |
| 38 | + @$(MAKE) configure-hatch |
| 39 | + @hatch env create local |
45 | 40 | @echo "=> Install complete! Note: If you want to re-install re-run 'make install'" |
46 | 41 |
|
47 | 42 |
|
48 | | -clean: ## Cleanup temporary build artifacts |
| 43 | +.PHONY: upgrade |
| 44 | +upgrade: ## Upgrade all dependencies to the latest stable versions |
| 45 | + @echo "=> Updating all dependencies" |
| 46 | + @hatch-pip-compile --upgrade --all |
| 47 | + @echo "=> Python Dependencies Updated" |
| 48 | + @hatch run lint:pre-commit autoupdate |
| 49 | + @echo "=> Updated Pre-commit" |
| 50 | + |
| 51 | + |
| 52 | +.PHONY: clean |
| 53 | +clean: ## remove all build, testing, and static documentation files |
49 | 54 | @echo "=> Cleaning working directory" |
50 | | - @if [ "$(USING_PDM)" ]; then $(PDM) run pre-commit clean; fi |
51 | | - @rm -rf .pytest_cache .ruff_cache .hypothesis build/ -rf dist/ .eggs/ |
| 55 | + @rm -rf .pytest_cache .ruff_cache .hypothesis build/ dist/ .eggs/ .coverage coverage.xml coverage.json htmlcov/ .mypy_cache |
52 | 56 | @find . -name '*.egg-info' -exec rm -rf {} + |
53 | 57 | @find . -name '*.egg' -exec rm -f {} + |
54 | 58 | @find . -name '*.pyc' -exec rm -f {} + |
55 | 59 | @find . -name '*.pyo' -exec rm -f {} + |
56 | 60 | @find . -name '*~' -exec rm -f {} + |
57 | 61 | @find . -name '__pycache__' -exec rm -rf {} + |
| 62 | + @find . -name '.pytest_cache' -exec rm -rf {} + |
58 | 63 | @find . -name '.ipynb_checkpoints' -exec rm -rf {} + |
59 | | - @rm -rf .coverage coverage.xml coverage.json htmlcov/ .pytest_cache tests/.pytest_cache tests/**/.pytest_cache .mypy_cache |
60 | | - $(MAKE) docs-clean |
| 64 | + @echo "=> Source cleaned successfully" |
| 65 | + |
| 66 | +deep-clean: clean destroy-venv ## Clean everything up |
| 67 | + @hatch python remove all |
| 68 | + @echo "=> Hatch environments pruned and python installations trimmed" |
| 69 | + |
| 70 | +destroy-venv: ## Destroy the virtual environment |
| 71 | + @hatch env prune |
| 72 | + @hatch env remove lint |
| 73 | + @rm -Rf .venv |
| 74 | + @rm -Rf .direnv |
| 75 | + |
| 76 | +.PHONY: build |
| 77 | +build: clean ## Build and package the collectors |
| 78 | + @echo "=> Building package..." |
| 79 | + @hatch build |
| 80 | + @echo "=> Package build complete..." |
| 81 | + |
| 82 | + |
| 83 | +############### |
| 84 | +# docs # |
| 85 | +############### |
| 86 | +.PHONY: serve-docs |
| 87 | +serve-docs: ## Serve HTML documentation |
| 88 | + @hatch run docs:serve |
| 89 | + |
| 90 | +.PHONY: docs |
| 91 | +docs: ## generate HTML documentation and serve it to the browser |
| 92 | + @hatch run docs:build |
61 | 93 |
|
62 | | -destroy: ## Destroy the virtual environment |
63 | | - @rm -rf .venv |
64 | 94 |
|
65 | 95 | # ============================================================================= |
66 | 96 | # Tests, Linting, Coverage |
67 | 97 | # ============================================================================= |
68 | 98 | .PHONY: lint |
69 | 99 | lint: ## Runs pre-commit hooks; includes ruff linting, codespell, black |
70 | 100 | @echo "=> Running pre-commit process" |
71 | | - @$(ENV_PREFIX)pre-commit run --all-files |
| 101 | + @hatch run lint:fix |
72 | 102 | @echo "=> Pre-commit complete" |
73 | 103 |
|
74 | | -.PHONY: coverage |
75 | | -coverage: ## Run the tests and generate coverage report |
76 | | - @echo "=> Running tests with coverage" |
77 | | - @$(ENV_PREFIX)pytest tests --cov=litestar_asyncg |
78 | | - @$(ENV_PREFIX)coverage html |
79 | | - @$(ENV_PREFIX)coverage xml |
80 | | - @echo "=> Coverage report generated" |
81 | | - |
82 | 104 | .PHONY: test |
83 | 105 | test: ## Run the tests |
84 | 106 | @echo "=> Running test cases" |
85 | | - @$(ENV_PREFIX)pytest tests |
| 107 | + @hatch run +py=3.12 test:cov |
86 | 108 | @echo "=> Tests complete" |
87 | 109 |
|
88 | | - |
89 | | -.PHONY: check-all |
90 | | -check-all: lint test coverage ## Run all linting, tests, and coverage checks |
91 | | - |
92 | | -# ============================================================================= |
93 | | -# Docs |
94 | | -# ============================================================================= |
95 | | -.PHONY: docs-install |
96 | | -docs-install: ## Install docs dependencies |
97 | | - @echo "=> Installing documentation dependencies" |
98 | | - @$(PDM) install --group docs |
99 | | - @echo "=> Installed documentation dependencies" |
100 | | - |
101 | | -docs-clean: ## Dump the existing built docs |
102 | | - @echo "=> Cleaning documentation build assets" |
103 | | - @rm -rf docs/_build |
104 | | - @echo "=> Removed existing documentation build assets" |
105 | | - |
106 | | -docs-serve: docs-clean ## Serve the docs locally |
107 | | - @echo "=> Serving documentation" |
108 | | - $(ENV_PREFIX)sphinx-autobuild docs docs/_build/ -j auto --watch litestar_asyncg --watch docs --watch tests --watch CONTRIBUTING.rst --port 8002 |
109 | | - |
110 | | -docs: docs-clean ## Dump the existing built docs and rebuild them |
111 | | - @echo "=> Building documentation" |
112 | | - @$(ENV_PREFIX)sphinx-build -M html docs docs/_build/ -E -a -j auto --keep-going |
| 110 | +.PHONY: test-all |
| 111 | +test-all: ## Run the tests for all python versions |
| 112 | + @echo "=> Running test cases" |
| 113 | + @hatch run test:cov |
| 114 | + @echo "=> Tests complete" |
0 commit comments