Skip to content

Commit 69f4a5f

Browse files
authored
Merge pull request nicolargo#2907 from ariel-anieli/refactorize-makefile
Refactorize `Makefile`
2 parents 4dd732b + 0804d06 commit 69f4a5f

File tree

2 files changed

+92
-71
lines changed

2 files changed

+92
-71
lines changed

Makefile

Lines changed: 91 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
1-
PORT?=8008
2-
LASTTAG = $(shell git describe --tags --abbrev=0)
1+
PORT ?= 8008
2+
VENV := venv/bin
3+
VENV_DEV := venv-dev/bin
4+
VENV_MIN := venv-min/bin
5+
CONF := conf/glances.conf
6+
PIP := $(VENV)/pip
7+
PYTHON := $(VENV)/python
8+
UNITTEST := unittest
9+
10+
DOCKER_BUILD := docker buildx build
11+
DOCKER_RUN := docker run
12+
DOCKERFILE_UBUNTU := docker-files/ubuntu.Dockerfile
13+
DOCKERFILE_ALPINE := docker-files/alpine.Dockerfile
14+
PODMAN_SOCK ?= /run/user/$(shell id -u)/podman/podman.sock
15+
DOCKER_SOCK ?= /var/run/docker.sock
16+
DOCKER_SOCKS := -v $(PODMAN_SOCK):$(PODMAN_SOCK):ro -v $(DOCKER_SOCK):$(DOCKER_SOCK):ro
17+
DOCKER_OPTS := --rm -e TZ="${TZ}" -e GLANCES_OPT="" --pid host --network host
18+
19+
LASTTAG = $(shell git describe --tags --abbrev=0)
320

421
# if the command is only `make`, the default tasks will be the printing of the help.
522
.DEFAULT_GOAL := help
623

7-
.PHONY: help
24+
.PHONY: help test docs docs-server venv venv-min venv-dev
25+
826
help: ## List all make commands available
9-
@grep -E '^[\.a-zA-Z_%-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk -F ":" '{print $1}' | grep -v % | sed 's/\\//g' | sort | awk 'BEGIN {FS = ":[^:]*?##"}; {printf "\033[1;34mmake %-50s\033[0m %s\n", $$1, $$2}'
27+
@grep -E '^[\.a-zA-Z_%-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
28+
awk -F ":" '{print $1}' | \
29+
grep -v % | \
30+
sed 's/\\//g' | \
31+
sort | \
32+
awk 'BEGIN {FS = ":[^:]*?##"}; {printf "\033[1;34mmake %-50s\033[0m %s\n", $$1, $$2}'
1033

1134
# ===================================================================
1235
# Virtualenv
@@ -24,117 +47,117 @@ venv-full-python: ## Install Python 3 venv
2447
virtualenv -p /usr/bin/python3 venv
2548

2649
venv-full: venv-python ## Install Python 3 run-time dependencies
27-
./venv/bin/pip install -r requirements.txt
28-
./venv/bin/pip install -r optional-requirements.txt
50+
$(PIP) install -r requirements.txt
51+
$(PIP) install -r optional-requirements.txt
2952

3053
venv-full-upgrade: ## Upgrade Python 3 run-time dependencies
31-
./venv/bin/pip install --upgrade pip
32-
./venv/bin/pip install --upgrade -r requirements.txt
33-
./venv/bin/pip install --upgrade -r optional-requirements.txt
54+
$(PIP) install --upgrade pip
55+
$(PIP) install --upgrade -r requirements.txt
56+
$(PIP) install --upgrade -r optional-requirements.txt
3457

3558
# For minimal installation (without optional dependencies)
3659

3760
venv-min-python: ## Install Python 3 venv minimal
3861
virtualenv -p /usr/bin/python3 venv-min
3962

4063
venv-min: venv-min-python ## Install Python 3 minimal run-time dependencies
41-
./venv-min/bin/pip install -r requirements.txt
64+
$(VENV_MIN)/pip install -r requirements.txt
4265

4366
venv-min-upgrade: ## Upgrade Python 3 minimal run-time dependencies
44-
./venv-min/bin/pip install --upgrade pip
45-
./venv-min/bin/pip install --upgrade -r requirements.txt
67+
$(VENV_MIN)/pip install --upgrade pip
68+
$(VENV_MIN)/pip install --upgrade -r requirements.txt
4669

4770
# For development
4871

4972
venv-dev-python: ## Install Python 3 venv
5073
virtualenv -p /usr/bin/python3 venv-dev
5174

5275
venv-dev: venv-python ## Install Python 3 dev dependencies
53-
./venv-dev/bin/pip install -r dev-requirements.txt
54-
./venv-dev/bin/pip install -r doc-requirements.txt
55-
./venv-dev/bin/pre-commit install --hook-type pre-commit
76+
$(VENV_DEV)/pip install -r dev-requirements.txt
77+
$(VENV_DEV)/pip install -r doc-requirements.txt
78+
$(VENV_DEV)/pre-commit install --hook-type pre-commit
5679

5780
venv-dev-upgrade: ## Upgrade Python 3 dev dependencies
58-
./venv-dev/bin/pip install --upgrade pip
59-
./venv-dev/bin/pip install --upgrade -r dev-requirements.txt
60-
./venv-dev/bin/pip install --upgrade -r doc-requirements.txt
81+
$(VENV_DEV)/pip install --upgrade pip
82+
$(VENV_DEV)/pip install --upgrade -r dev-requirements.txt
83+
$(VENV_DEV)/pip install --upgrade -r doc-requirements.txt
6184

6285
# ===================================================================
6386
# Tests
6487
# ===================================================================
6588

6689
test-core: ## Run core unit tests
67-
./venv/bin/python ./unittest-core.py
90+
$(PYTHON) $(UNITTEST)-core.py
6891

6992
test-restful: ## Run Restful unit tests
70-
./venv/bin/python ./unittest-restful.py
93+
$(PYTHON) $(UNITTEST)-restful.py
7194

7295
test-xmlrpc: ## Run XMLRPC unit tests
73-
./venv/bin/python ./unittest-xmlrpc.py
96+
$(PYTHON) $(UNITTEST)-xmlrpc.py
7497

7598
test: test-core test-restful test-xmlrpc ## Run unit tests
7699

77100
test-with-upgrade: venv-upgrade venv-dev-upgrade test ## Upgrade deps and run unit tests
78101

79102
test-min: ## Run core unit tests in minimal environment
80-
./venv-min/bin/python ./unittest-core.py
103+
$(VENV_MIN)/python $(UNITTEST)-core.py
81104

82105
test-min-with-upgrade: venv-min-upgrade ## Upgrade deps and run unit tests in minimal environment
83-
./venv-min/bin/python ./unittest-core.py
106+
$(VENV_MIN)/python $(UNITTEST)-core.py
84107

85108
# ===================================================================
86109
# Linters, profilers and cyber security
87110
# ===================================================================
88111

89112
format: ## Format the code
90-
./venv-dev/bin/python -m ruff format .
113+
$(VENV_DEV)/python -m ruff format .
91114

92115
lint: ## Lint the code.
93-
./venv-dev/bin/python -m ruff check . --fix
116+
$(VENV_DEV)/python -m ruff check . --fix
94117

95118
codespell: ## Run codespell to fix common misspellings in text files
96-
./venv-dev/bin/codespell -S .git,./docs/_build,./Glances.egg-info,./venv*,./glances/outputs,*.svg -L hart,bu,te,statics -w
119+
$(VENV_DEV)/codespell -S .git,./docs/_build,./Glances.egg-info,./venv*,./glances/outputs,*.svg -L hart,bu,te,statics -w
97120

98121
semgrep: ## Run semgrep to find bugs and enforce code standards
99-
./venv-dev/bin/semgrep scan --config=auto
122+
$(VENV_DEV)/semgrep scan --config=auto
100123

101124
profiling-gprof: ## Callgraph profiling (need "apt install graphviz")
102125
@echo "Start Glances for 30 iterations (more or less 1 mins, please do not exit !)"
103126
sleep 3
104-
./venv/bin/python -m cProfile -o ./glances.cprof ./run.py --stop-after 30
105-
./venv-dev/bin/gprof2dot -f pstats ./glances.cprof | dot -Tsvg -o ./docs/_static/glances-cgraph.svg
127+
$(PYTHON) -m cProfile -o ./glances.cprof ./run.py --stop-after 30
128+
$(VENV_DEV)/gprof2dot -f pstats ./glances.cprof | dot -Tsvg -o ./docs/_static/glances-cgraph.svg
106129
rm -f ./glances.cprof
107130

108131
profiling-pyinstrument: ## PyInstrument profiling
109132
@echo "Start Glances for 30 iterations (more or less 1 mins, please do not exit !)"
110133
sleep 3
111-
./venv/bin/pip install pyinstrument
112-
./venv/bin/python -m pyinstrument -r html -o ./docs/_static/glances-pyinstrument.html -m glances --stop-after 30
134+
$(PIP) install pyinstrument
135+
$(PYTHON) -m pyinstrument -r html -o ./docs/_static/glances-pyinstrument.html -m glances --stop-after 30
113136

114137
profiling-pyspy: ## Flame profiling (currently not compatible with Python 3.12)
115138
@echo "Start Glances for 30 iterations (more or less 1 mins, please do not exit !)"
116139
sleep 3
117-
./venv-dev/bin/py-spy record -o ./docs/_static/glances-flame.svg -d 60 -s -- ./venv/bin/python ./run.py --stop-after 30
140+
$(VENV_DEV)/py-spy record -o ./docs/_static/glances-flame.svg -d 60 -s -- $(PYTHON) ./run.py --stop-after 30
118141

119142
profiling: profiling-gprof profiling-pyinstrument profiling-pyspy ## Profiling of the Glances software
120143

121144
trace-malloc: ## Trace the malloc() calls
122145
@echo "Malloc test is running, please wait ~30 secondes..."
123-
./venv/bin/python -m glances -C ./conf/glances.conf --trace-malloc --stop-after 15 --quiet
146+
$(PYTHON) -m glances -C $(CONF) --trace-malloc --stop-after 15 --quiet
124147

125148
memory-leak: ## Profile memory leaks
126-
./venv/bin/python -m glances -C ./conf/glances.conf --memory-leak
149+
$(PYTHON) -m glances -C $(CONF) --memory-leak
127150

128151
memory-profiling: ## Profile memory usage
129152
@echo "It's a very long test (~4 hours)..."
130153
rm -f mprofile_*.dat
131154
@echo "1/2 - Start memory profiling with the history option enable"
132-
./venv-dev/bin/mprof run -T 1 -C run.py -C ./conf/glances.conf --stop-after 2400 --quiet
133-
./venv-dev/bin/mprof plot --output ./docs/_static/glances-memory-profiling-with-history.png
155+
$(VENV_DEV)/mprof run -T 1 -C run.py -C $(CONF) --stop-after 2400 --quiet
156+
$(VENV_DEV)/mprof plot --output ./docs/_static/glances-memory-profiling-with-history.png
134157
rm -f mprofile_*.dat
135158
@echo "2/2 - Start memory profiling with the history option disable"
136-
./venv-dev/bin/mprof run -T 1 -C run.py -C ./conf/glances.conf --disable-history --stop-after 2400 --quiet
137-
./venv-dev/bin/mprof plot --output ./docs/_static/glances-memory-profiling-without-history.png
159+
$(VENV_DEV)/mprof run -T 1 -C run.py -C $(CONF) --disable-history --stop-after 2400 --quiet
160+
$(VENV_DEV)/mprof plot --output ./docs/_static/glances-memory-profiling-without-history.png
138161
rm -f mprofile_*.dat
139162

140163
# Trivy installation: https://aquasecurity.github.io/trivy/latest/getting-started/installation/
@@ -146,7 +169,7 @@ trivy: ## Run Trivy to find vulnerabilities in container images
146169
# ===================================================================
147170

148171
docs: ## Create the documentation
149-
./venv/bin/python -m glances -C ./conf/glances.conf --api-doc > ./docs/api.rst
172+
$(PYTHON) -m glances -C $(CONF) --api-doc > ./docs/api.rst
150173
cd docs && ./build.sh && cd ..
151174

152175
docs-server: docs ## Start a Web server to serve the documentation
@@ -181,7 +204,7 @@ webui-audit-fix: ## Fix audit the Web UI
181204

182205
flatpak: venv-dev-upgrade ## Generate FlatPack JSON file
183206
git clone https://github.com/flatpak/flatpak-builder-tools.git
184-
./venv/bin/python ./flatpak-builder-tools/pip/flatpak-pip-generator glances
207+
$(PYTHON) ./flatpak-builder-tools/pip/flatpak-pip-generator glances
185208
rm -rf ./flatpak-builder-tools
186209
@echo "Now follow: https://github.com/flathub/flathub/wiki/App-Submission"
187210

@@ -201,91 +224,91 @@ docker: docker-alpine docker-ubuntu ## Generate local docker images
201224
docker-alpine: docker-alpine-full docker-alpine-minimal docker-alpine-dev ## Generate local docker images (Alpine)
202225

203226
docker-alpine-full: ## Generate local docker image (Alpine full)
204-
docker buildx build --target full -f ./docker-files/alpine.Dockerfile -t glances:local-alpine-full .
227+
$(DOCKER_BUILD) --target full -f $(DOCKERFILE_ALPINE) -t glances:local-alpine-full .
205228

206229
docker-alpine-minimal: ## Generate local docker image (Alpine minimal)
207-
docker buildx build --target minimal -f ./docker-files/alpine.Dockerfile -t glances:local-alpine-minimal .
230+
$(DOCKER_BUILD) --target minimal -f $(DOCKERFILE_ALPINE) -t glances:local-alpine-minimal .
208231

209232
docker-alpine-dev: ## Generate local docker image (Alpine dev)
210-
docker buildx build --target dev -f ./docker-files/alpine.Dockerfile -t glances:local-alpine-dev .
233+
$(DOCKER_BUILD) --target dev -f $(DOCKERFILE_ALPINE) -t glances:local-alpine-dev .
211234

212235
docker-ubuntu: docker-ubuntu-full docker-ubuntu-minimal docker-ubuntu-dev ## Generate local docker images (Ubuntu)
213236

214237
docker-ubuntu-full: ## Generate local docker image (Ubuntu full)
215-
docker buildx build --target full -f ./docker-files/ubuntu.Dockerfile -t glances:local-ubuntu-full .
238+
$(DOCKER_BUILD) --target full -f $(DOCKERFILE_UBUNTU) -t glances:local-ubuntu-full .
216239

217240
docker-ubuntu-minimal: ## Generate local docker image (Ubuntu minimal)
218-
docker buildx build --target minimal -f ./docker-files/ubuntu.Dockerfile -t glances:local-ubuntu-minimal .
241+
$(DOCKER_BUILD) --target minimal -f $(DOCKERFILE_UBUNTU) -t glances:local-ubuntu-minimal .
219242

220243
docker-ubuntu-dev: ## Generate local docker image (Ubuntu dev)
221-
docker buildx build --target dev -f ./docker-files/ubuntu.Dockerfile -t glances:local-ubuntu-dev .
244+
$(DOCKER_BUILD) --target dev -f $(DOCKERFILE_UBUNTU) -t glances:local-ubuntu-dev .
222245

223246
# ===================================================================
224247
# Run
225248
# ===================================================================
226249

227250
run: ## Start Glances in console mode (also called standalone)
228-
./venv/bin/python -m glances -C ./conf/glances.conf
251+
$(PYTHON) -m glances -C $(CONF)
229252

230253
run-debug: ## Start Glances in debug console mode (also called standalone)
231-
./venv/bin/python -m glances -C ./conf/glances.conf -d
254+
$(PYTHON) -m glances -C $(CONF) -d
232255

233256
run-local-conf: ## Start Glances in console mode with the system conf file
234-
./venv/bin/python -m glances
257+
$(PYTHON) -m glances
235258

236259
run-local-conf-hide-public: ## Start Glances in console mode with the system conf file and hide public information
237-
./venv/bin/python -m glances --hide-public-info
260+
$(PYTHON) -m glances --hide-public-info
238261

239262
run-min: ## Start minimal Glances in console mode (also called standalone)
240-
./venv-min/bin/python -m glances -C ./conf/glances.conf
263+
$(VENV_MIN)/python -m glances -C $(CONF)
241264

242265
run-min-debug: ## Start minimal Glances in debug console mode (also called standalone)
243-
./venv-min/bin/python -m glances -C ./conf/glances.conf -d
266+
$(VENV_MIN)/python -m glances -C $(CONF) -d
244267

245268
run-min-local-conf: ## Start minimal Glances in console mode with the system conf file
246-
./venv-min/bin/python -m glances
269+
$(VENV_MIN)/python -m glances
247270

248271
run-docker-alpine-minimal: ## Start Glances Alpine Docker minimal in console mode
249-
docker run --rm -e TZ="${TZ}" -e GLANCES_OPT="" -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro -v /var/run/docker.sock:/var/run/docker.sock:ro --pid host --network host -it glances:local-alpine-minimal
272+
$(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-alpine-minimal
250273

251274
run-docker-alpine-full: ## Start Glances Alpine Docker full in console mode
252-
docker run --rm -e TZ="${TZ}" -e GLANCES_OPT="" -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro -v /var/run/docker.sock:/var/run/docker.sock:ro --pid host --network host -it glances:local-alpine-full
275+
$(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-alpine-full
253276

254277
run-docker-alpine-dev: ## Start Glances Alpine Docker dev in console mode
255-
docker run --rm -e TZ="${TZ}" -e GLANCES_OPT="" -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro -v /var/run/docker.sock:/var/run/docker.sock:ro --pid host --network host -it glances:local-alpine-dev
278+
$(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-alpine-dev
256279

257280
run-docker-ubuntu-minimal: ## Start Glances Ubuntu Docker minimal in console mode
258-
docker run --rm -e TZ="${TZ}" -e GLANCES_OPT="" -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro -v /var/run/docker.sock:/var/run/docker.sock:ro --pid host --network host -it glances:local-ubuntu-minimal
281+
$(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-ubuntu-minimal
259282

260283
run-docker-ubuntu-full: ## Start Glances Ubuntu Docker full in console mode
261-
docker run --rm -e TZ="${TZ}" -e GLANCES_OPT="" -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro -v /var/run/docker.sock:/var/run/docker.sock:ro --pid host --network host -it glances:local-ubuntu-full
284+
$(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-ubuntu-full
262285

263286
run-docker-ubuntu-dev: ## Start Glances Ubuntu Docker dev in console mode
264-
docker run --rm -e TZ="${TZ}" -e GLANCES_OPT="" -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro -v /var/run/docker.sock:/var/run/docker.sock:ro --pid host --network host -it glances:local-ubuntu-dev
287+
$(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-ubuntu-dev
265288

266289
run-webserver: ## Start Glances in Web server mode
267-
./venv/bin/python -m glances -C ./conf/glances.conf -w
290+
$(PYTHON) -m glances -C $(CONF) -w
268291

269292
run-webserver-local-conf: ## Start Glances in Web server mode with the system conf file
270-
./venv/bin/python -m glances -w
293+
$(PYTHON) -m glances -w
271294

272295
run-webserver-local-conf-hide-public: ## Start Glances in Web server mode with the system conf file and hide public info
273-
./venv/bin/python -m glances -w --hide-public-info
296+
$(PYTHON) -m glances -w --hide-public-info
274297

275298
run-restapiserver: ## Start Glances in REST API server mode
276-
./venv/bin/python -m glances -C ./conf/glances.conf -w --disable-webui
299+
$(PYTHON) -m glances -C $(CONF) -w --disable-webui
277300

278301
run-server: ## Start Glances in server mode (RPC)
279-
./venv/bin/python -m glances -C ./conf/glances.conf -s
302+
$(PYTHON) -m glances -C $(CONF) -s
280303

281304
run-client: ## Start Glances in client mode (RPC)
282-
./venv/bin/python -m glances -C ./conf/glances.conf -c localhost
305+
$(PYTHON) -m glances -C $(CONF) -c localhost
283306

284307
run-browser: ## Start Glances in browser mode (RPC)
285-
./venv/bin/python -m glances -C ./conf/glances.conf --browser
308+
$(PYTHON) -m glances -C $(CONF) --browser
286309

287310
run-issue: ## Start Glances in issue mode
288-
./venv/bin/python -m glances -C ./conf/glances.conf --issue
311+
$(PYTHON) -m glances -C $(CONF) --issue
289312

290313
run-multipass: ## Install and start Glances in a VM (only available on Ubuntu with multipass already installed)
291314
multipass launch -n glances-on-lts lts
@@ -295,6 +318,4 @@ run-multipass: ## Install and start Glances in a VM (only available on Ubuntu wi
295318
multipass delete glances-on-lts
296319

297320
show-version: ## Show Glances version number
298-
./venv/bin/python -m glances -C ./conf/glances.conf -V
299-
300-
.PHONY: test docs docs-server venv venv-min venv-dev
321+
$(PYTHON) -m glances -C $(CONF) -V

docs/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ will change the root API URL to ``http://localhost:61208/glances/api/4`` and the
4343
API documentation URL
4444
---------------------
4545

46-
The API documentation is embeded in the server and available at the following URL:
46+
The API documentation is embedded in the server and available at the following URL:
4747
``http://localhost:61208/docs#/``.
4848

4949
WebUI refresh

0 commit comments

Comments
 (0)