-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
148 lines (105 loc) · 3.99 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
SHELL := /bin/bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
PYPROJECT_TOML := pyproject.toml
PYPI_VERSION := 0.1.7
PYTHON_VERSION := 3.11
TARGET := src/pdflex tests
TARGET_TEST := tests
DIST_NAME := dist/pdflex-$(PYPI_VERSION)-py3-none-any.whl
# -- Clean ---------------------------
.PHONY: clean
clean: ## Clean build and virtual environment directories
@echo -e "\n► Cleaning up project environment and directories..."
-rm -rf dist/ .venv/ build/ *.egg-info/
-find . -name "__pycache__" -type d -exec rm -rf {} +
-find . -name "*.pyc" -type f -exec rm -f {} +
# -- Dev ---------------------------
.PHONY: build
build: ## Build the distribution package using uv
@echo "Distribution Name: $(DIST_NAME)..."
uv build
uv pip install $(DIST_NAME)
.PHONY: install
install: ## Install all dependencies from pyproject.toml
uv sync --dev --group test --group docs --group lint --all-extras
.PHONY: lock
lock: ## Lock dependencies declared in pyproject.toml
uv pip compile $(PYPROJECT_TOML) --all-extras
.PHONY: requirements
requirements: ## Generate requirements files from pyproject.toml
uv pip compile $(PYPROJECT_TOML) -o requirements.txtiu
uv pip compile $(PYPROJECT_TOML) --all-extras -o requirements-dev.txt
.PHONY: sync
sync: ## Sync environment with pyproject.toml
uv sync --all-groups --dev
.PHONY: update
update: ## Update all dependencies from pyproject.toml
uv lock --upgrade
.PHONY: venv
venv: ## Create a virtual environment
uv venv --python $(PYTHON_VERSION)
# -- Docs ---------------------------
.PHONY: docs
docs: ## Build documentation site using mkdocs
@echo -e "\n► Building documentation site... (not implemented)"
# -- Lint ---------------------------
.PHONY: format-toml
format-toml: ## Format TOML files using pyproject-fmt
uvx --isolated pyproject-fmt $(TOML_FILE) --indent 4
.PHONY: format
format: ## Format Python files using Ruff
@echo -e "\n► Running the Ruff formatter..."
uvx --isolated ruff format $(TARGET) --config .ruff.toml
.PHONY: lint
lint: ## Lint Python files using Ruff
@echo -e "\n ►Running the Ruff linter..."
uvx --isolated ruff check $(TARGET) --fix --config .ruff.toml
.PHONY: format-and-lint
format-and-lint: format lint ## Format and lint Python files
.PHONY: typecheck-mypy
typecheck-mypy: ## Type-check Python files using MyPy
uv run mypy $(TARGET)
.PHONY: typecheck-pyright
typecheck-pyright: ## Type-check Python files using Pyright
uv run pyright $(TARGET)
# -- Release ----------------------------
RELEASE_FILES ?= .
RELEASE_MSG ?= "Add pymupdf dependency, release $(PYPI_VERSION)"
RELEASE_BRANCH ?= main
TAG_PREFIX ?= v
.PHONY: release
release: ## Create and push a new version release
ifndef version
$(error version parameter is required. Use 'make release version=X.Y.Z')
endif
# make release version=1.2.3 RELEASE_FILES="file1 file2" RELEASE_MSG="Custom release message" RELEASE_BRANCH=develop TAG_PREFIX=release-"
@echo "Creating release version $(PYPI_VERSION)..."
@git add $(RELEASE_FILES)
@git commit -m "$(RELEASE_MSG)"
@git tag -a $(TAG_PREFIX)$(PYPI_VERSION) -m "$(RELEASE_MSG)"
@git push origin $(RELEASE_BRANCH)
@git push origin $(TAG_PREFIX)$(PYPI_VERSION)
# -- Tests ----------------------------
.PHONY: test
test: ## Run test suite using Pytest
uv run pytest $(TARGET_TEST) --config-file $(PYPROJECT_TOML)
# -- Utils ---------------------------
.PHONY: convert-slides
convert-slides: ## Convert slides to PDF
@echo -e "\n► Converting slides to PDF..."
python \
src/pdflex/slides_to_text.py tests/data/slide-deck-math.pdf \
--output .pdflex/convert/30-slides-to-text.txt
.PHONY: help
help: ## Display this help
@echo ""
@echo "Usage: make [target]"
@echo ""
@awk 'BEGIN {FS = ":.*?## "; printf "\033[1m%-20s %-50s\033[0m\n", "Target", "Description"; \
printf "%-20s %-50s\n", "------", "-----------";} \
/^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-20s\033[0m %-50s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""