-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
79 lines (67 loc) · 2.08 KB
/
Copy pathMakefile
File metadata and controls
79 lines (67 loc) · 2.08 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
# Variables
VENV := venv
OS := $(shell uname 2>/dev/null || echo Windows)
# Detect correct Python and Pip commands based on OS
ifeq ($(OS), Windows) # Windows
PYTHON := $(VENV)/Scripts/python.exe
PIP := $(VENV)/Scripts/pip.exe
PYTHON_CMD := python
CLEAR_CMD := cls
TIME_CMD :=
else # Unix-like
PYTHON := $(VENV)/bin/python3
PIP := $(VENV)/bin/pip
PYTHON_CMD := python3
CLEAR_CMD := clear
TIME_CMD := time
endif
# Logs directory
LOG_DIR := ./Logs
# Ensure logs directory exists (cross-platform)
ENSURE_LOG_DIR := @mkdir -p $(LOG_DIR) 2>/dev/null || $(PYTHON_CMD) -c "import os; os.makedirs('$(LOG_DIR)', exist_ok=True)"
# Run-and-log function
# On Windows: simply runs the Python script normally
# On Unix-like systems: supports DETACH variable
# - If DETACH is set, runs the script in detached mode and tails the log file
# - Else, runs the script normally
ifeq ($(OS), Windows) # Windows
RUN_AND_LOG = $(PYTHON) $(1)
else
RUN_AND_LOG = \ # Unix-like
if [ -z "$(DETACH)" ]; then \
$(PYTHON) $(1); \
else \
LOG_FILE=$(LOG_DIR)/$$(basename $(1) .py).log; \
nohup $(PYTHON) $(1) > $$LOG_FILE 2>&1 & \
tail -f $$LOG_FILE; \
fi
endif
# Default target
all: run
# Make Rules
run: dependencies
$(ENSURE_LOG_DIR)
$(CLEAR_CMD)
$(call RUN_AND_LOG, ./main.py)
# Create virtual environment if missing
$(VENV):
@echo "Creating virtual environment..."
$(PYTHON_CMD) -m venv $(VENV)
$(PYTHON) -m pip install --upgrade pip
dependencies: $(VENV)
@echo "Installing/Updating Python dependencies..."
$(PIP) install -r requirements.txt
# Generate requirements.txt from current venv
generate_requirements: $(VENV)
$(PIP) freeze > requirements.txt
# Run the repository installer script (makes it executable and runs it)
install:
@echo "Running install_dependencies.sh"
@chmod +x ./install_dependencies.sh || true
@./install_dependencies.sh
# Clean artifacts
clean:
rm -rf $(VENV) || rmdir /S /Q $(VENV) 2>nul
find . -type f -name '*.pyc' -delete || del /S /Q *.pyc 2>nul
find . -type d -name '__pycache__' -delete || rmdir /S /Q __pycache__ 2>nul
.PHONY: all run clean dependencies generate_requirements install