-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
118 lines (86 loc) · 3.17 KB
/
Makefile
File metadata and controls
118 lines (86 loc) · 3.17 KB
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
.DEFAULT_GOAL := help
PYTORCH_DOCKER_IMAGE = pytorch/pytorch:1.8.1-cuda11.1-cudnn8
PYTHON_DOCKER_IMAGE = python:3.8-buster
GIT_DESCRIBE = $(shell git describe --first-parent)
ARCHIVE = tinify.tar.gz
src_dirs := tinify tests examples docs
.PHONY: help
help: ## Show this message
@echo "Usage: make COMMAND\n\nCommands:"
@grep '\s##\s' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' | cat
# Check style and linting
.PHONY: check-ruff-format check-ruff-organize-imports check-ruff-lint check-mypy static-analysis
check-ruff-format: ## Run ruff format checks
@echo "--> Running ruff format checks"
@ruff format --check $(src_dirs)
check-ruff-organize-imports: ## Run ruff organize imports checks
@echo "--> Running ruff organize imports checks"
@ruff check --ignore ALL --select I $(src_dirs)
check-ruff-lint: ## Run ruff lint checks
@echo "--> Running ruff lint checks"
@ruff check $(src_dirs)
check-mypy: ## Run mypy checks
@echo "--> Running mypy checks"
@mypy
static-analysis: check-ruff-format check-ruff-organize-imports check-ruff-lint # check-mypy ## Run all static checks
# Apply styling
.PHONY: style
style: ## Apply style formating
@echo "--> Running ruff format"
@ruff format $(src_dirs)
@echo "--> Running ruff check --ignore ALL --select I"
@ruff check --ignore ALL --select I $(src_dirs)
# Run tests
.PHONY: tests coverage
tests: ## Run tests
@echo "--> Running Python tests"
@pytest -x -m "not slow" --cov tinify --cov-append --cov-report= ./tests/
coverage: ## Run coverage
@echo "--> Running Python coverage"
@coverage report
@coverage html
# Build docs
.PHONY: docs docs-sphinx docs-mkdocs docs-serve
docs: docs-mkdocs ## Build docs (MkDocs)
docs-sphinx: ## Build Sphinx docs
@echo "--> Building Sphinx docs"
@cd docs && SPHINXOPTS="-W" make html
docs-mkdocs: ## Build MkDocs docs
@echo "--> Building MkDocs docs"
@mkdocs build
docs-serve: ## Serve MkDocs docs locally
@echo "--> Serving MkDocs docs at http://127.0.0.1:8000"
@mkdocs serve
# Build Rust extensions
.PHONY: build-rust build-rust-dev clean-rust
build-rust: ## Build Rust extensions (release)
@echo "--> Building Rust extensions (release)"
@cd tinify/rust_exts && maturin build --release
@pip install tinify/rust_exts/target/wheels/*.whl --force-reinstall
build-rust-dev: ## Build Rust extensions (development)
@echo "--> Building Rust extensions (development)"
@cd tinify/rust_exts && maturin develop
clean-rust: ## Clean Rust build artifacts
@echo "--> Cleaning Rust build artifacts"
@cd tinify/rust_exts && cargo clean
# Docker images
.PHONY: docker docker-cpu
docker: ## Build docker image
@git archive --format=tar.gz HEAD > docker/${ARCHIVE}
@cd docker && \
docker build \
--build-arg PYTORCH_IMAGE=${PYTORCH_DOCKER_IMAGE} \
--build-arg WITH_JUPYTER=0 \
--progress=auto \
-t tinify:${GIT_DESCRIBE} .
@rm docker/${ARCHIVE}
docker-cpu: ## Build docker image (cpu only)
@git archive --format=tar.gz HEAD > docker/${ARCHIVE}
@cd docker && \
docker build \
-f Dockerfile.cpu \
--build-arg BASE_IMAGE=${PYTHON_DOCKER_IMAGE} \
--build-arg WITH_JUPYTER=0 \
--progress=auto \
-t tinify:${GIT_DESCRIBE}-cpu .
@rm docker/${ARCHIVE}