-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
74 lines (58 loc) · 1.98 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
.PHONY: create-$(VENV) activate run install-reqs db-init db-clean ruff flake8 lint
.DEFAULT_GOAL := run
# The system's python interpreter. Used only to create virtual environment.
PY = python3
# The name of the virtual environment.
VENV = blog-venv
# The path to the virtual environment's bin or Scripts directory.
BIN = $(VENV)/bin
# Adding support to Windows.
ifeq ($(OS), Windows_NT)
PY = python
BIN = $(VENV)/Scripts
endif
PIP = $(BIN)/pip
PYTHON = $(BIN)/$(PY)
ACTIVATE = $(BIN)/activate
# For some reason, the globstar (eg, **/*.py) is broken in windows. This is a workaround.
# Source: https://stackoverflow.com/questions/2483182/recursive-wildcards-in-gnu-make
# Other: https://dev.to/blikoor/customize-git-bash-shell-498l
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
create-$(VENV): requirements.txt requirements-dev.txt
@echo "Creating virtual environment..."
$(PY) -m venv $(VENV)
$(PIP) install --upgrade pip
$(PIP) install --upgrade -r requirements.txt
$(PIP) install --upgrade -r requirements-dev.txt
@echo "Done."
activate: $(VENV)
@echo "Activating virtual environment..."
. ./$(ACTIVATE)
@echo "Done."
run: $(VENV)
@echo "Running..."
$(PYTHON) src/run.py
@echo "Done."
install-reqs: $(VENV) requirements.txt requirements-dev.txt
@echo "Installing requirements..."
$(PIP) install --upgrade -r requirements.txt
$(PIP) install --upgrade -r requirements-dev.txt
@echo "Done."
db-init: $(VENV)
@echo "Initializing database..."
# $(PYTHON) src/db_init.py
$(PYTHON) -c "import os; os.chdir('src'); import db_init; db_init.init_db()"
@echo "Done."
db-clean: $(VENV) src/instance/site.db
@echo "Clearing database..."
$(PYTHON) -c "import os; os.chdir('src'); import db_init; db_init.drop_db()"
@echo "Done."
ruff: $(VENV)
@echo "Linting Python files using ruff..."
$(BIN)/ruff .
@echo "Done."
flake8: $(VENV)
@echo "Linting Python files using flake8..."
$(BIN)/flake8 --color always
@echo "Done."
lint: ruff flake8