Merge pull request #2917 from ariel-anieli/makefile

Used patterns for rules targetting `venv`, `venv-python`, `venv-upgrade`
pull/2923/head
Nicolas Hennion 2024-08-11 18:28:09 +02:00 committed by GitHub
commit c0aa754ebc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 51 additions and 47 deletions

View File

@ -1,12 +1,18 @@
PORT ?= 8008
VENV := venv/bin
VENV_DEV := venv-dev/bin
VENV_MIN := venv-min/bin
venv_full:= venv/bin
venv_dev := venv-dev/bin
venv_min := venv-min/bin
CONF := conf/glances.conf
PIP := $(VENV)/pip
PYTHON := $(VENV)/python
PIP := $(venv_full)/pip
PYTHON := $(venv_full)/python
LASTTAG = $(shell git describe --tags --abbrev=0)
VENV_TYPES := full min dev
VENV_PYTHON := $(VENV_TYPES:%=venv-%-python)
VENV_UPG := $(VENV_TYPES:%=venv-%-upgrade)
VENV_DEPS := $(VENV_TYPES:%=venv-%)
VENV_INST_UPG := $(VENV_DEPS) $(VENV_UPG)
IMAGES_TYPES := full minimal dev
DISTROS := alpine ubuntu
alpine_images := $(IMAGES_TYPES:%=docker-alpine-%)
@ -38,52 +44,50 @@ help: ## List all make commands available
# Virtualenv
# ===================================================================
venv-python: venv-full-python venv-min-python venv-dev-python ## Install all Python 3 venv
venv-%-upgrade: UPGRADE = --upgrade
venv: venv-full venv-min venv-dev ## Install all Python 3 dependencies
define DEFINE_VARS_FOR_TYPE
venv-$(TYPE) venv-$(TYPE)-upgrade: VIRTUAL_ENV = $(venv_$(TYPE))
endef
venv-upgrade: venv-full-upgrade venv-min-upgrade venv-dev-upgrade ## Upgrade all Python 3 dependencies
$(foreach TYPE,$(VENV_TYPES),$(eval $(DEFINE_VARS_FOR_TYPE)))
$(VENV_PYTHON): venv-%-python:
virtualenv -p /usr/bin/python3 $(if $(filter full,$*),venv,venv-$*)
$(VENV_INST_UPG): venv-%:
$(if $(UPGRADE),$(VIRTUAL_ENV)/install install --upgrade pip,)
$(foreach REQ,$(REQS), $(VIRTUAL_ENV)/pip install $(UPGRADE) -r $(REQ);)
$(if $(PRE_COMMIT),$(VIRTUAL_ENV)/pre-commit install --hook-type pre-commit,)
venv-python: $(VENV_PYTHON) ## Install all Python 3 venv
venv: $(VENV_DEPS) ## Install all Python 3 dependencies
venv-upgrade: $(VENV_UPG) ## Upgrade all Python 3 dependencies
# For full installation (with optional dependencies)
venv-full venv-full-upgrade: REQS = requirements.txt optional-requirements.txt
venv-full-python: ## Install Python 3 venv
virtualenv -p /usr/bin/python3 venv
venv-full: venv-python ## Install Python 3 run-time dependencies
$(PIP) install -r requirements.txt
$(PIP) install -r optional-requirements.txt
venv-full: venv-python ## Install Python 3 run-time
venv-full-upgrade: ## Upgrade Python 3 run-time dependencies
$(PIP) install --upgrade pip
$(PIP) install --upgrade -r requirements.txt
$(PIP) install --upgrade -r optional-requirements.txt
# For minimal installation (without optional dependencies)
venv-min venv-min-upgrade: REQS = requirements.txt
venv-min-python: ## Install Python 3 venv minimal
virtualenv -p /usr/bin/python3 venv-min
venv-min: venv-min-python ## Install Python 3 minimal run-time dependencies
$(VENV_MIN)/pip install -r requirements.txt
venv-min-upgrade: ## Upgrade Python 3 minimal run-time dependencies
$(VENV_MIN)/pip install --upgrade pip
$(VENV_MIN)/pip install --upgrade -r requirements.txt
# For development
venv-dev venv-dev-upgrade: REQS = dev-requirements.txt doc-requirements.txt
venv-dev: PRE_COMMIT = 1
venv-dev-python: ## Install Python 3 venv
virtualenv -p /usr/bin/python3 venv-dev
venv-dev: venv-python ## Install Python 3 dev dependencies
$(VENV_DEV)/pip install -r dev-requirements.txt
$(VENV_DEV)/pip install -r doc-requirements.txt
$(VENV_DEV)/pre-commit install --hook-type pre-commit
venv-dev-upgrade: ## Upgrade Python 3 dev dependencies
$(VENV_DEV)/pip install --upgrade pip
$(VENV_DEV)/pip install --upgrade -r dev-requirements.txt
$(VENV_DEV)/pip install --upgrade -r doc-requirements.txt
# ===================================================================
# Tests
@ -101,32 +105,32 @@ test: $(UNIT_TESTS) ## Run unit tests
test-with-upgrade: venv-upgrade venv-dev-upgrade test ## Upgrade deps and run unit tests
test-min: ## Run core unit tests in minimal environment
$(VENV_MIN)/python unittest-core.py
$(venv_min)/python unittest-core.py
test-min-with-upgrade: venv-min-upgrade ## Upgrade deps and run unit tests in minimal environment
$(VENV_MIN)/python unittest-core.py
$(venv_min)/python unittest-core.py
# ===================================================================
# Linters, profilers and cyber security
# ===================================================================
format: ## Format the code
$(VENV_DEV)/python -m ruff format .
$(venv_dev)/python -m ruff format .
lint: ## Lint the code.
$(VENV_DEV)/python -m ruff check . --fix
$(venv_dev)/python -m ruff check . --fix
codespell: ## Run codespell to fix common misspellings in text files
$(VENV_DEV)/codespell -S .git,./docs/_build,./Glances.egg-info,./venv*,./glances/outputs,*.svg -L hart,bu,te,statics -w
$(venv_dev)/codespell -S .git,./docs/_build,./Glances.egg-info,./venv*,./glances/outputs,*.svg -L hart,bu,te,statics -w
semgrep: ## Run semgrep to find bugs and enforce code standards
$(VENV_DEV)/semgrep scan --config=auto
$(venv_dev)/semgrep scan --config=auto
profiling-gprof: ## Callgraph profiling (need "apt install graphviz")
@echo "Start Glances for 30 iterations (more or less 1 mins, please do not exit !)"
sleep 3
$(PYTHON) -m cProfile -o ./glances.cprof ./run.py --stop-after 30
$(VENV_DEV)/gprof2dot -f pstats ./glances.cprof | dot -Tsvg -o ./docs/_static/glances-cgraph.svg
$(venv_dev)/gprof2dot -f pstats ./glances.cprof | dot -Tsvg -o ./docs/_static/glances-cgraph.svg
rm -f ./glances.cprof
profiling-pyinstrument: ## PyInstrument profiling
@ -138,7 +142,7 @@ profiling-pyinstrument: ## PyInstrument profiling
profiling-pyspy: ## Flame profiling (currently not compatible with Python 3.12)
@echo "Start Glances for 30 iterations (more or less 1 mins, please do not exit !)"
sleep 3
$(VENV_DEV)/py-spy record -o ./docs/_static/glances-flame.svg -d 60 -s -- $(PYTHON) ./run.py --stop-after 30
$(venv_dev)/py-spy record -o ./docs/_static/glances-flame.svg -d 60 -s -- $(PYTHON) ./run.py --stop-after 30
profiling: profiling-gprof profiling-pyinstrument profiling-pyspy ## Profiling of the Glances software
@ -153,12 +157,12 @@ memory-profiling: ## Profile memory usage
@echo "It's a very long test (~4 hours)..."
rm -f mprofile_*.dat
@echo "1/2 - Start memory profiling with the history option enable"
$(VENV_DEV)/mprof run -T 1 -C run.py -C $(CONF) --stop-after 2400 --quiet
$(VENV_DEV)/mprof plot --output ./docs/_static/glances-memory-profiling-with-history.png
$(venv_dev)/mprof run -T 1 -C run.py -C $(CONF) --stop-after 2400 --quiet
$(venv_dev)/mprof plot --output ./docs/_static/glances-memory-profiling-with-history.png
rm -f mprofile_*.dat
@echo "2/2 - Start memory profiling with the history option disable"
$(VENV_DEV)/mprof run -T 1 -C run.py -C $(CONF) --disable-history --stop-after 2400 --quiet
$(VENV_DEV)/mprof plot --output ./docs/_static/glances-memory-profiling-without-history.png
$(venv_dev)/mprof run -T 1 -C run.py -C $(CONF) --disable-history --stop-after 2400 --quiet
$(venv_dev)/mprof plot --output ./docs/_static/glances-memory-profiling-without-history.png
rm -f mprofile_*.dat
# 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
$(PYTHON) -m glances --hide-public-info
run-min: ## Start minimal Glances in console mode (also called standalone)
$(VENV_MIN)/python -m glances -C $(CONF)
$(venv_min)/python -m glances -C $(CONF)
run-min-debug: ## Start minimal Glances in debug console mode (also called standalone)
$(VENV_MIN)/python -m glances -C $(CONF) -d
$(venv_min)/python -m glances -C $(CONF) -d
run-min-local-conf: ## Start minimal Glances in console mode with the system conf file
$(VENV_MIN)/python -m glances
$(venv_min)/python -m glances
$(DOCKER_RUNTIMES): run-docker-%:
$(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-$*