Skip to content

Commit c0aa754

Browse files
authored
Merge pull request nicolargo#2917 from ariel-anieli/makefile
Used patterns for rules targetting `venv`, `venv-python`, `venv-upgrade`
2 parents fcbee35 + 13079a6 commit c0aa754

File tree

1 file changed

+51
-47
lines changed

1 file changed

+51
-47
lines changed

Makefile

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
PORT ?= 8008
2-
VENV := venv/bin
3-
VENV_DEV := venv-dev/bin
4-
VENV_MIN := venv-min/bin
2+
venv_full:= venv/bin
3+
venv_dev := venv-dev/bin
4+
venv_min := venv-min/bin
55
CONF := conf/glances.conf
6-
PIP := $(VENV)/pip
7-
PYTHON := $(VENV)/python
6+
PIP := $(venv_full)/pip
7+
PYTHON := $(venv_full)/python
88
LASTTAG = $(shell git describe --tags --abbrev=0)
99

10+
VENV_TYPES := full min dev
11+
VENV_PYTHON := $(VENV_TYPES:%=venv-%-python)
12+
VENV_UPG := $(VENV_TYPES:%=venv-%-upgrade)
13+
VENV_DEPS := $(VENV_TYPES:%=venv-%)
14+
VENV_INST_UPG := $(VENV_DEPS) $(VENV_UPG)
15+
1016
IMAGES_TYPES := full minimal dev
1117
DISTROS := alpine ubuntu
1218
alpine_images := $(IMAGES_TYPES:%=docker-alpine-%)
@@ -38,52 +44,50 @@ help: ## List all make commands available
3844
# Virtualenv
3945
# ===================================================================
4046

41-
venv-python: venv-full-python venv-min-python venv-dev-python ## Install all Python 3 venv
47+
venv-%-upgrade: UPGRADE = --upgrade
4248

43-
venv: venv-full venv-min venv-dev ## Install all Python 3 dependencies
49+
define DEFINE_VARS_FOR_TYPE
50+
venv-$(TYPE) venv-$(TYPE)-upgrade: VIRTUAL_ENV = $(venv_$(TYPE))
51+
endef
4452

45-
venv-upgrade: venv-full-upgrade venv-min-upgrade venv-dev-upgrade ## Upgrade all Python 3 dependencies
53+
$(foreach TYPE,$(VENV_TYPES),$(eval $(DEFINE_VARS_FOR_TYPE)))
4654

47-
# For full installation (with optional dependencies)
55+
$(VENV_PYTHON): venv-%-python:
56+
virtualenv -p /usr/bin/python3 $(if $(filter full,$*),venv,venv-$*)
4857

49-
venv-full-python: ## Install Python 3 venv
50-
virtualenv -p /usr/bin/python3 venv
58+
$(VENV_INST_UPG): venv-%:
59+
$(if $(UPGRADE),$(VIRTUAL_ENV)/install install --upgrade pip,)
60+
$(foreach REQ,$(REQS), $(VIRTUAL_ENV)/pip install $(UPGRADE) -r $(REQ);)
61+
$(if $(PRE_COMMIT),$(VIRTUAL_ENV)/pre-commit install --hook-type pre-commit,)
62+
63+
venv-python: $(VENV_PYTHON) ## Install all Python 3 venv
64+
venv: $(VENV_DEPS) ## Install all Python 3 dependencies
65+
venv-upgrade: $(VENV_UPG) ## Upgrade all Python 3 dependencies
66+
67+
# For full installation (with optional dependencies)
5168

52-
venv-full: venv-python ## Install Python 3 run-time dependencies
53-
$(PIP) install -r requirements.txt
54-
$(PIP) install -r optional-requirements.txt
69+
venv-full venv-full-upgrade: REQS = requirements.txt optional-requirements.txt
5570

71+
venv-full-python: ## Install Python 3 venv
72+
venv-full: venv-python ## Install Python 3 run-time
5673
venv-full-upgrade: ## Upgrade Python 3 run-time dependencies
57-
$(PIP) install --upgrade pip
58-
$(PIP) install --upgrade -r requirements.txt
59-
$(PIP) install --upgrade -r optional-requirements.txt
6074

6175
# For minimal installation (without optional dependencies)
6276

63-
venv-min-python: ## Install Python 3 venv minimal
64-
virtualenv -p /usr/bin/python3 venv-min
77+
venv-min venv-min-upgrade: REQS = requirements.txt
6578

79+
venv-min-python: ## Install Python 3 venv minimal
6680
venv-min: venv-min-python ## Install Python 3 minimal run-time dependencies
67-
$(VENV_MIN)/pip install -r requirements.txt
68-
6981
venv-min-upgrade: ## Upgrade Python 3 minimal run-time dependencies
70-
$(VENV_MIN)/pip install --upgrade pip
71-
$(VENV_MIN)/pip install --upgrade -r requirements.txt
7282

7383
# For development
7484

75-
venv-dev-python: ## Install Python 3 venv
76-
virtualenv -p /usr/bin/python3 venv-dev
85+
venv-dev venv-dev-upgrade: REQS = dev-requirements.txt doc-requirements.txt
86+
venv-dev: PRE_COMMIT = 1
7787

88+
venv-dev-python: ## Install Python 3 venv
7889
venv-dev: venv-python ## Install Python 3 dev dependencies
79-
$(VENV_DEV)/pip install -r dev-requirements.txt
80-
$(VENV_DEV)/pip install -r doc-requirements.txt
81-
$(VENV_DEV)/pre-commit install --hook-type pre-commit
82-
8390
venv-dev-upgrade: ## Upgrade Python 3 dev dependencies
84-
$(VENV_DEV)/pip install --upgrade pip
85-
$(VENV_DEV)/pip install --upgrade -r dev-requirements.txt
86-
$(VENV_DEV)/pip install --upgrade -r doc-requirements.txt
8791

8892
# ===================================================================
8993
# Tests
@@ -101,32 +105,32 @@ test: $(UNIT_TESTS) ## Run unit tests
101105
test-with-upgrade: venv-upgrade venv-dev-upgrade test ## Upgrade deps and run unit tests
102106

103107
test-min: ## Run core unit tests in minimal environment
104-
$(VENV_MIN)/python unittest-core.py
108+
$(venv_min)/python unittest-core.py
105109

106110
test-min-with-upgrade: venv-min-upgrade ## Upgrade deps and run unit tests in minimal environment
107-
$(VENV_MIN)/python unittest-core.py
111+
$(venv_min)/python unittest-core.py
108112

109113
# ===================================================================
110114
# Linters, profilers and cyber security
111115
# ===================================================================
112116

113117
format: ## Format the code
114-
$(VENV_DEV)/python -m ruff format .
118+
$(venv_dev)/python -m ruff format .
115119

116120
lint: ## Lint the code.
117-
$(VENV_DEV)/python -m ruff check . --fix
121+
$(venv_dev)/python -m ruff check . --fix
118122

119123
codespell: ## Run codespell to fix common misspellings in text files
120-
$(VENV_DEV)/codespell -S .git,./docs/_build,./Glances.egg-info,./venv*,./glances/outputs,*.svg -L hart,bu,te,statics -w
124+
$(venv_dev)/codespell -S .git,./docs/_build,./Glances.egg-info,./venv*,./glances/outputs,*.svg -L hart,bu,te,statics -w
121125

122126
semgrep: ## Run semgrep to find bugs and enforce code standards
123-
$(VENV_DEV)/semgrep scan --config=auto
127+
$(venv_dev)/semgrep scan --config=auto
124128

125129
profiling-gprof: ## Callgraph profiling (need "apt install graphviz")
126130
@echo "Start Glances for 30 iterations (more or less 1 mins, please do not exit !)"
127131
sleep 3
128132
$(PYTHON) -m cProfile -o ./glances.cprof ./run.py --stop-after 30
129-
$(VENV_DEV)/gprof2dot -f pstats ./glances.cprof | dot -Tsvg -o ./docs/_static/glances-cgraph.svg
133+
$(venv_dev)/gprof2dot -f pstats ./glances.cprof | dot -Tsvg -o ./docs/_static/glances-cgraph.svg
130134
rm -f ./glances.cprof
131135

132136
profiling-pyinstrument: ## PyInstrument profiling
@@ -138,7 +142,7 @@ profiling-pyinstrument: ## PyInstrument profiling
138142
profiling-pyspy: ## Flame profiling (currently not compatible with Python 3.12)
139143
@echo "Start Glances for 30 iterations (more or less 1 mins, please do not exit !)"
140144
sleep 3
141-
$(VENV_DEV)/py-spy record -o ./docs/_static/glances-flame.svg -d 60 -s -- $(PYTHON) ./run.py --stop-after 30
145+
$(venv_dev)/py-spy record -o ./docs/_static/glances-flame.svg -d 60 -s -- $(PYTHON) ./run.py --stop-after 30
142146

143147
profiling: profiling-gprof profiling-pyinstrument profiling-pyspy ## Profiling of the Glances software
144148

@@ -153,12 +157,12 @@ memory-profiling: ## Profile memory usage
153157
@echo "It's a very long test (~4 hours)..."
154158
rm -f mprofile_*.dat
155159
@echo "1/2 - Start memory profiling with the history option enable"
156-
$(VENV_DEV)/mprof run -T 1 -C run.py -C $(CONF) --stop-after 2400 --quiet
157-
$(VENV_DEV)/mprof plot --output ./docs/_static/glances-memory-profiling-with-history.png
160+
$(venv_dev)/mprof run -T 1 -C run.py -C $(CONF) --stop-after 2400 --quiet
161+
$(venv_dev)/mprof plot --output ./docs/_static/glances-memory-profiling-with-history.png
158162
rm -f mprofile_*.dat
159163
@echo "2/2 - Start memory profiling with the history option disable"
160-
$(VENV_DEV)/mprof run -T 1 -C run.py -C $(CONF) --disable-history --stop-after 2400 --quiet
161-
$(VENV_DEV)/mprof plot --output ./docs/_static/glances-memory-profiling-without-history.png
164+
$(venv_dev)/mprof run -T 1 -C run.py -C $(CONF) --disable-history --stop-after 2400 --quiet
165+
$(venv_dev)/mprof plot --output ./docs/_static/glances-memory-profiling-without-history.png
162166
rm -f mprofile_*.dat
163167

164168
# Trivy installation: https://aquasecurity.github.io/trivy/latest/getting-started/installation/
@@ -256,13 +260,13 @@ run-local-conf-hide-public: ## Start Glances in console mode with the system con
256260
$(PYTHON) -m glances --hide-public-info
257261

258262
run-min: ## Start minimal Glances in console mode (also called standalone)
259-
$(VENV_MIN)/python -m glances -C $(CONF)
263+
$(venv_min)/python -m glances -C $(CONF)
260264

261265
run-min-debug: ## Start minimal Glances in debug console mode (also called standalone)
262-
$(VENV_MIN)/python -m glances -C $(CONF) -d
266+
$(venv_min)/python -m glances -C $(CONF) -d
263267

264268
run-min-local-conf: ## Start minimal Glances in console mode with the system conf file
265-
$(VENV_MIN)/python -m glances
269+
$(venv_min)/python -m glances
266270

267271
$(DOCKER_RUNTIMES): run-docker-%:
268272
$(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-$*

0 commit comments

Comments
 (0)