-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
150 lines (137 loc) · 4.81 KB
/
Copy pathMakefile
File metadata and controls
150 lines (137 loc) · 4.81 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
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
149
150
.PHONY: all update venv venvupdate cleanpy cleanvenv cleanall help
# run one shell only
.ONESHELL: all update venv venvupdate cleanpy cleanvenv cleanall help
# disable running of targets in parallel
.NOTPARALLEL: all update venv venvupdate cleanpy cleanvenv cleanall help
# predefined variables
CURRDIRECTORY := $(notdir $(CURDIR))
DOCKERTAG := $(shell python -c "print('$(CURRDIRECTORY)'.lower())"):latest
# Detect shell capabilities.
SHELL_BASENAME := $(notdir $(SHELL))
# Strip extension to normalize (e.g. powershell.exe -> powershell, bash.exe -> bash)
SHELL_CORE := $(basename $(SHELL_BASENAME))
KNOWN_POSIX_SHELLS := sh bash zsh ksh ash dash busybox
# Only mark POSIX if the core name matches the whitelist (prevents false positive on 'powershell')
HAVE_POSIX_SHELL := $(filter $(KNOWN_POSIX_SHELLS),$(SHELL_CORE))
ifeq ($(OS),Windows_NT)
# Windows defaults (cmd / PowerShell)
PYTHONVENV := .venv/Scripts/
PYTHONVENVEXE := .venv/Scripts/python.exe
RM_CMD := del /Q /S
WHERE_CMD := where
ECHO_BLANK := echo.
ifeq ($(SHELL),sh.exe)
# Explicitly keep Windows settings when PowerShell detected
ECHO_BLANK := echo .
else ifneq ($(HAVE_POSIX_SHELL),)
# If NOT PowerShell but actually a POSIX-like shell, override with POSIX tooling
RM_CMD := rm -rf
WHERE_CMD := which
ECHO_BLANK := echo
endif
else
PYTHONVENV := .venv/bin/
PYTHONVENVEXE := .venv/bin/python
RM_CMD := rm -rf
WHERE_CMD := which
ECHO_BLANK := echo
endif
# default target
all: cleanpy update venv
@$(ECHO_BLANK)
@echo "******************* all FINISHED *******************"
@$(ECHO_BLANK)
# local update of pip/virtualenv
update:
@echo "******************* update START *******************"
@$(ECHO_BLANK)
python -m pip install --upgrade pip setuptools wheel poetry virtualenv uv ruff pylint mypy pyright
@$(ECHO_BLANK)
@echo "******************* update FINISHED *******************"
@$(ECHO_BLANK)
# target for building the python venv
venv:
@echo "******************* venv START *******************"
@$(ECHO_BLANK)
@echo "Local Python Version..."
python --version
$(WHERE_CMD) python
@$(ECHO_BLANK)
@echo "Make Virtual Environment..."
uv venv --python 3.11 --seed --clear
@$(ECHO_BLANK)
@echo "Check Virtual Environment Python Version..."
$(PYTHONVENVEXE) --version
$(PYTHONVENVEXE) -c "import sys; print(sys.executable)"
@$(ECHO_BLANK)
@echo "Upgrade project dependencies..."
uv lock --upgrade
@$(ECHO_BLANK)
@echo "Install project dependencies..."
@$(ECHO_BLANK)
uv sync --no-install-project
@$(ECHO_BLANK)
@echo "Check for conflicts..."
uv pip check
@$(ECHO_BLANK)
@echo "Check for outdated dependencies and just list them..."
$(PYTHONVENVEXE) -m pip list --outdated
@$(ECHO_BLANK)
@echo "******************* virtualenv venv FINISHED *******************"
@$(ECHO_BLANK)
# target for upgrading venv (assumes venv exists)
venvupdate:
@echo "******************* venvupdate START *******************"
@$(ECHO_BLANK)
@echo "Check Virtual Environment Python Version..."
$(PYTHONVENVEXE) --version
$(PYTHONVENVEXE) -c "import sys; print(sys.executable)"
@$(ECHO_BLANK)
@echo "Upgrade project dependencies..."
uv lock --upgrade
@$(ECHO_BLANK)
@echo "Install project dependencies..."
@$(ECHO_BLANK)
uv sync --no-install-project
@$(ECHO_BLANK)
@echo "Check for conflicts..."
uv pip check
@$(ECHO_BLANK)
@echo "Check for outdated dependencies and just list them..."
$(PYTHONVENVEXE) -m pip list --outdated
@$(ECHO_BLANK)
@echo "******************* venvupdate FINISHED *******************"
@$(ECHO_BLANK)
# remove cache files
cleanpy:
@echo "******************* cleanpy START *******************"
@$(ECHO_BLANK)
$(RM_CMD) __pycache__
@$(ECHO_BLANK)
@echo "******************* cleanpy FINISHED *******************"
@$(ECHO_BLANK)
# remove venv
cleanvenv:
@echo "******************* cleanvenv START *******************"
@$(ECHO_BLANK)
$(RM_CMD) .venv
$(RM_CMD) uv.lock
@$(ECHO_BLANK)
@echo "******************* cleanvenv FINISHED *******************"
@$(ECHO_BLANK)
# clean all
cleanall: cleanpy cleanvenv
@$(ECHO_BLANK)
@echo "******************* cleanall FINISHED *******************"
@$(ECHO_BLANK)
# help target
help:
@echo "Available targets:"
@echo " all - Clean Python cache, update tools, and create/setup venv"
@echo " update - Upgrade pip, setuptools, wheel, poetry, virtualenv, uv, and ruff"
@echo " venv - Create and set up Python virtual environment with dependencies"
@echo " venvupdate - Update dependencies in existing venv (requires venv to exist)"
@echo " cleanpy - Remove Python cache files (__pycache__)"
@echo " cleanvenv - Remove the virtual environment (.venv)"
@echo " cleanall - Remove cache and venv"
@echo " help - Show this help message"