-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
203 lines (157 loc) · 4.8 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# **************************************************************************** #
# General Make configuration
# This suppresses make's command echoing. This suppression produces a cleaner output.
# If you need to see the full commands being issued by make, comment this out.
MAKEFLAGS += -s
# Fix bad built-in make behaviors
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
# Use > instead of \t
.RECIPEPREFIX = >
# **************************************************************************** #
# load the pypi credentials
ifneq (,$(wildcard .env))
include .env
# export them for twine
export
endif
# **************************************************************************** #
APP_FOLDER := src
APP_NAME := stagehand
APP_MAIN := $(APP_FOLDER)/$(APP_NAME)/__main__.py
APP_INFO := $(APP_FOLDER)/$(APP_NAME)/app_info.py
# load the project variables
ifneq (,$(wildcard $(APP_INFO)))
include $(APP_INFO)
# remove extra quotes
AppName := $(patsubst "%",%,$(AppName))
AppVersion := $(patsubst "%",%,$(AppVersion))
AppPublisher := $(patsubst "%",%,$(AppPublisher))
AppExeName := $(patsubst "%",%,$(AppExeName))
AppIconName := $(patsubst "%",%,$(AppIconName))
AppId := $(patsubst "%",%,$(AppId))
# export them for InnoSetup
export
endif
# **************************************************************************** #
# Development Targets
# run the application
run: venv
> $(VENV_PYTHON) $(APP_MAIN)
# run the application in pdb
debug: venv
> $(VENV_PYTHON) -m pdb $(APP_MAIN)
#
build:
> uv build
#
publish:
> twine upload dist/* -u __token__
#
reload:
> -pipx uninstall stagehand
> pipx install . -e
# ---------------------------------------------------------------------------- #
PORTABLE_FLAG := $(APP_FOLDER)/.portable
# create the portable flag folder
portable:
> mkdir "$(PORTABLE_FLAG)"
# remove the portable flag folder
non_portable:
> $(RM) "$(PORTABLE_FLAG)"
# **************************************************************************** #
# Utility Targets
# open the qtawesome icon browser
qta: venv
> $(VENV)/qta-browser
obs: venv
> $(VENV_PYTHON) app/plugins/obs_core/gen.py
# build all the plugins into zips
plugins: venv
> $(VENV_PYTHON) tools/plugins.py build
install_plugins: venv
> $(VENV_PYTHON) tools/plugins.py install
clean_plugins: venv
> $(VENV_PYTHON) tools/plugins.py clean
# **************************************************************************** #
# Build Targets
# build a self-contained onefile executable
onefile: venv plugins
> $(VENV_PYINSTALLER) -y onefile.spec
# build a one folder bundle
bundle: venv plugins
> $(VENV_PYINSTALLER) -y bundle.spec
# run the bundled executable
run_bundle:
ifeq ($(OS),Windows_NT)
> dist/$(AppName)/$(AppName).exe
else
> dist/$(AppName)/$(AppName)
endif
# **************************************************************************** #
# Release Targets
# wrap the bundle into a zip file
zip:
> $(PYTHON) -m zipfile -c dist/$(AppName)-$(AppVersion)-portable.zip dist/$(AppName)/
# build an installer with InnoSetup
installer:
> iscc "installer.iss"
# remove the various build outputs
clean:
> -@ $(RM) build
> -@ $(RM) dist
# **************************************************************************** #
# python venv settings
VENV_NAME := .venv
REQUIREMENTS := requirements.txt
VENV_DIR := $(VENV_NAME)
PYTHON := python
ifeq ($(OS),Windows_NT)
VENV := $(VENV_DIR)/Scripts
else
VENV := $(VENV_DIR)/bin
endif
VENV_CANARY_DIR := $(VENV_DIR)/canary
VENV_CANARY_FILE := $(VENV_CANARY_DIR)/$(REQUIREMENTS)
VENV_TMP_DIR := $(VENV_DIR)/tmp
VENV_TMP_FREEZE := $(VENV_TMP_DIR)/freeze.txt
VENV_PYTHON := $(VENV)/$(PYTHON)
VENV_PYINSTALLER := $(VENV)/pyinstaller
RM := rm -rf
CP := cp
# Add this as a requirement to any make target that relies on the venv
.PHONY: venv
# venv: $(VENV_DIR) $(VENV_CANARY_FILE)
venv: $(VENV_DIR)
# Create the venv if it doesn't exist
$(VENV_DIR):
> uv venv
# Update the venv if the canary is out of date
$(VENV_CANARY_FILE): $(REQUIREMENTS)
> uv pip install -r $(REQUIREMENTS)
> -$(RM) $(VENV_CANARY_DIR)
> -mkdir $(VENV_CANARY_DIR)
> -$(CP) $(REQUIREMENTS) $(VENV_CANARY_FILE)
# forcibly update the canary file
canary: $(VENV_CANARY_DIR)
> -$(RM) $(VENV_CANARY_DIR)
> -mkdir $(VENV_CANARY_DIR)
> $(CP) $(REQUIREMENTS) $(VENV_CANARY_FILE)
# update requirements.txt to match the state of the venv
freeze_reqs: venv
> $(VENV_PYTHON) -m pip freeze > $(REQUIREMENTS)
# try to update the venv - expirimental feature, don't rely on it
update_venv: venv
> uv pip sync $(REQUIREMENTS)
> -$(RM) $(VENV_CANARY_DIR)
> -mkdir $(VENV_CANARY_DIR)
> -$(CP) $(REQUIREMENTS) $(VENV_CANARY_FILE)
# remove all packages from the venv
clean_venv:
> $(RM) $(VENV_CANARY_DIR)
> mkdir $(VENV_TMP_DIR)
> uv pip freeze > $(VENV_TMP_FREEZE)
> uv pip uninstall -y -r $(VENV_TMP_FREEZE)
> $(RM) $(VENV_TMP_DIR)
# clean the venv and rebuild it
reset_venv: clean_venv update_venv