-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
110 lines (92 loc) · 3.07 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
# Set default shell to bash
SHELL := /bin/bash
# Extract settings from pyproject.toml
NAME := $(shell grep '^name =' pyproject.toml | sed -E "s/name = \"(.*)\"/\\1/")
VERSION := $(shell grep '^version =' pyproject.toml | sed -E "s/version = \"(.*)\"/\\1/")
# Define variables
DOCKER_IMAGE_NAME ?= subgenix
POETRY := poetry
DOCKER := docker
PIP := pip
# Define colors
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
NC := \033[0m # No Color
# Define styles
BOLD := \033[1m
UNDERLINE := \033[4m
# Define phony targets
.PHONY: build develop install dev-install test format lint image shell ls clean help
# Set default goal to help
.DEFAULT_GOAL := help
## Build the distribution package
build: clean
@printf "$(BLUE)Building distribution package...$(NC)\n"
@$(POETRY) build
## Set up the development environment
develop:
@printf "$(BLUE)Set up the development environment...$(NC)\n"
@$(POETRY) install
@$(POETRY) run pre-commit install
## Install the distribution package
install: build
@printf "$(BLUE)Installing distribution package...$(NC)\n"
@$(PIP) uninstall -y subgenix # TODO: Parameterize this.
@$(PIP) install dist/*.whl
## Run tests
test:
@printf "$(BLUE)Running tests...$(NC)\n"
@$(POETRY) run pytest tests
## Format code with black
format:
@printf "$(BLUE)Formatting code...$(NC)\n"
@$(POETRY) run black .
## Lint and type-check code with flake8, ruff, mypy
lint:
@printf "$(BLUE)Linting code...$(NC)\n"
$(POETRY) run flake8 .
$(POETRY) run ruff check .
@printf "$(BLUE)Type-checking code...$(NC)\n"
@$(POETRY) run mypy src/
## Build Docker image
image:
@printf "$(BLUE)Building Docker image...$(NC)\n"
@$(DOCKER) build -t $(DOCKER_IMAGE_NAME) .
## Access a shell Poetry environment
shell:
@printf "$(BLUE)Accessing Poetry shell...$(NC)\n"
@$(POETRY) shell
## List all files in the project
ls:
@printf "$(BLUE)Listing all files in the project...$(NC)\n"
@git ls-files --cached --others --exclude-standard
## Clean up build artifacts
clean:
@printf "$(BLUE)Cleaning up build artifacts...$(NC)\n"
@rm -rf ./dist
## Cycle the installation for interactive testing
iterate: format lint test install
@printf "$(BLUE)Cycling the installation for interactive testing...$(NC)\n"
subgenix ~/Videos/393906.mp4 --output ~/Videos/393906.mp4.srt --model medium --use-gpu
## TODO: Make this portable and parameterize it.
## Display this help message
help:
@printf "$(BOLD)$(UNDERLINE)Available targets:$(NC)\n\n"
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " $(YELLOW)%-20s$(NC) %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
@printf "\n$(BOLD)Usage:$(NC)\n"
@printf " make $(GREEN)<target>$(NC)\n"
@printf "\n$(BOLD)Example:$(NC)\n"
@printf " make $(GREEN)build$(NC) $(RED)# Builds the distribution package$(NC)\n"
@printf "\n$(BOLD)Project:$(NC)\n"
@printf " Name: $(GREEN)$(NAME)$(NC)\n"
@printf " Version: $(GREEN)$(VERSION)$(NC)\n"