summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2023-05-17 15:42:39 +0200
committernicolargo <nicolas@nicolargo.com>2023-05-17 15:42:39 +0200
commit658c3563a71c9dd46e9867264b0980e8e4144100 (patch)
treee69d28b10f0423ba41b2de9bce1b4b097f6c97f5
parent6f4da273c0da5dc57972cd30ff7c30077c9ae7b2 (diff)
Improve Makefile to split minimal, full and dev virtualenv
-rw-r--r--.gitignore2
-rw-r--r--Makefile124
-rw-r--r--glances/__init__.py2
-rw-r--r--glances/amps/glances_amp.py2
-rw-r--r--glances/exports/cassandra/__init__.py1
-rw-r--r--glances/exports/kafka/__init__.py2
-rw-r--r--glances/outputs/glances_stdout_csv.py1
-rw-r--r--glances/outputs/glances_stdout_json.py1
-rw-r--r--glances/plugins/connections/model.py8
-rw-r--r--glances/plugins/diskio/model.py1
-rw-r--r--glances/plugins/folders/model.py1
-rw-r--r--glances/plugins/ip/model.py2
-rw-r--r--glances/plugins/mem/model.py1
-rw-r--r--glances/plugins/plugin/view.py13
-rw-r--r--glances/plugins/ports/model.py2
-rw-r--r--glances/plugins/processlist/model.py1
-rw-r--r--glances/plugins/system/model.py1
-rw-r--r--glances/server.py2
-rwxr-xr-xunitest-restful.py1
-rwxr-xr-xunitest-xmlrpc.py1
-rwxr-xr-xunitest.py1
21 files changed, 91 insertions, 79 deletions
diff --git a/.gitignore b/.gitignore
index 20420292..8dc7d6d9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -62,5 +62,5 @@ bower_components/
/*_source.tar.bz2
# Virtual env
-/venv/
+/venv*/
diff --git a/Makefile b/Makefile
index f41f1007..4ffc82b9 100644
--- a/Makefile
+++ b/Makefile
@@ -8,39 +8,55 @@ LASTTAG = $(shell git describe --tags --abbrev=0)
help: ## List all make commands available
@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}'
-install: ## Open a Web Browser to the installation procedure
- sensible-browser "https://github.com/nicolargo/glances#installation"
+# ===================================================================
+# Virtualenv
+# ===================================================================
-venv-python: ## Install Python 3 venv
- virtualenv -p /usr/bin/python3 venv
+venv-python: venv-full-python venv-min-python venv-dev-python ## Install all Python 3 venv
-venv-dev: venv-python ## Install Python 3 dev dependencies
- ./venv/bin/pip install -r dev-requirements.txt
- ./venv/bin/pip install -r doc-requirements.txt
+venv: venv-full venv-min venv-dev ## Install all Python 3 dependencies
-venv-dev-upgrade: ## Upgrade Python 3 dev dependencies
- ./venv/bin/pip install --upgrade pip
- ./venv/bin/pip install --upgrade -r dev-requirements.txt
- ./venv/bin/pip install --upgrade -r doc-requirements.txt
+venv-upgrade: venv-full-upgrade venv-min-upgrade venv-dev-upgrade ## Upgrade all Python 3 dependencies
-venv: venv-python ## Install Python 3 run-time dependencies
+# For full installation (with optional dependencies)
+
+venv-full-python: ## Install Python 3 venv
+ virtualenv -p /usr/bin/python3 venv
+
+venv-full: venv-python ## Install Python 3 run-time dependencies
./venv/bin/pip install -r requirements.txt
./venv/bin/pip install -r optional-requirements.txt
-venv-upgrade: ## Upgrade Python 3 run-time dependencies
+venv-full-upgrade: ## Upgrade Python 3 run-time dependencies
+ ./venv/bin/pip install --upgrade pip
./venv/bin/pip install --upgrade -r requirements.txt
./venv/bin/pip install --upgrade -r optional-requirements.txt
# For minimal installation (without optional dependencies)
-venv-min-python: ## Install Python 3 venv
+venv-min-python: ## Install Python 3 venv minimal
virtualenv -p /usr/bin/python3 venv-min
-venv-min: venv-min-python ## Install Python 3 run-time dependencies
- ./venv/bin/pip install -r requirements.txt
+venv-min: venv-min-python ## Install Python 3 minimal run-time dependencies
+ ./venv-min/bin/pip install -r requirements.txt
-venv-min-upgrade: ## Upgrade Python 3 run-time dependencies
- ./venv/bin/pip install --upgrade -r requirements.txt
+venv-min-upgrade: ## Upgrade Python 3 minimal run-time dependencies
+ ./venv-min/bin/pip install --upgrade pip
+ ./venv-min/bin/pip install --upgrade -r requirements.txt
+
+# For development
+
+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/bin/pip install -r dev-requirements.txt
+ ./venv-dev/bin/pip install -r doc-requirements.txt
+
+venv-dev-upgrade: ## Upgrade Python 3 dev dependencies
+ ./venv-dev/bin/pip install --upgrade pip
+ ./venv-dev/bin/pip install --upgrade -r dev-requirements.txt
+ ./venv-dev/bin/pip install --upgrade -r doc-requirements.txt
# ===================================================================
# Tests
@@ -51,38 +67,42 @@ test: ## Run unit tests
./venv/bin/python ./unitest-restful.py
./venv/bin/python ./unitest-xmlrpc.py
./venv/bin/python -m black ./glances --check --exclude outputs/static
-# ./venv/bin/pyright glances
-test-with-upgrade: venv-upgrade venv-dev-upgrade ## Run unit tests
+test-with-upgrade: venv-upgrade venv-dev-upgrade ## Upgrade deps and run unit tests
./venv/bin/python ./unitest.py
./venv/bin/python ./unitest-restful.py
./venv/bin/python ./unitest-xmlrpc.py
./venv/bin/python -m black ./glances --check --exclude outputs/static
-# ./venv/bin/pyright glances
+
+test-min: ## Run unit tests in minimal environment
+ ./venv-min/bin/python ./unitest.py
+
+test-min-with-upgrade: venv-min-upgrade ## Upgrade deps and run unit tests in minimal environment
+ ./venv-min/bin/python ./unitest.py
# ===================================================================
# Linters and profilers
# ===================================================================
-format: venv-dev-upgrade ## Format the code
- @git ls-files '*.py' | xargs ./venv/bin/python -m autopep8 --in-place --jobs 0 --global-config=.flake8
- @git ls-files '*.py' | xargs ./venv/bin/python -m autoflake --in-place --remove-all-unused-imports --remove-unused-variables --remove-duplicate-keys --exclude="compat.py,globals.py"
- ./venv/bin/python -m black ./glances --exclude outputs/static
+format: ## Format the code
+ @git ls-files 'glances/*.py' | xargs ./venv-dev/bin/python -m autopep8 --in-place --jobs 0 --global-config=.flake8
+ @git ls-files 'glances/*.py' | xargs ./venv-dev/bin/python -m autoflake --in-place --remove-all-unused-imports --remove-unused-variables --remove-duplicate-keys --exclude="compat.py,globals.py"
+ ./venv-dev/bin/python -m black ./glances --exclude outputs/static
-flake8: venv-dev-upgrade ## Run flake8 linter.
- @git ls-files '*.py' | xargs ./venv/bin/python -m flake8 --config=.flake8
+flake8: ## Run flake8 linter.
+ @git ls-files 'glances/ *.py' | xargs ./venv-dev/bin/python -m flake8 --config=.flake8
-ruff: venv-dev-upgrade ## Run Ruff (fastest) linter.
- ./venv/bin/python -m ruff check . --config=./pyproject.toml
+ruff: ## Run Ruff (fastest) linter.
+ ./venv-dev/bin/python -m ruff check . --config=./pyproject.toml
-codespell: venv-dev-upgrade ## Run codespell to fix common misspellings in text files
- ./venv/bin/codespell -S .git,./docs/_build,./Glances.egg-info,./venv,./glances/outputs,*.svg -L hart,bu,te,statics
+codespell: ## Run codespell to fix common misspellings in text files
+ ./venv-dev/bin/codespell -S .git,./docs/_build,./Glances.egg-info,./venv*,./glances/outputs,*.svg -L hart,bu,te,statics
-semgrep: venv-dev-upgrade ## Run semgrep to find bugs and enforce code standards
- ./venv/bin/semgrep --config=auto --lang python --use-git-ignore ./glances
+semgrep: ## Run semgrep to find bugs and enforce code standards
+ ./venv-dev/bin/semgrep --config=auto --lang python --use-git-ignore ./glances
profiling: ## How to start the profiling of the Glances software
- @echo "Please complete and run: sudo ./venv/bin/py-spy record -o ./docs/_static/glances-flame.svg -d 60 -s --pid <GLANCES PID>"
+ @echo "Please complete and run: sudo ./venv-dev/bin/py-spy record -o ./docs/_static/glances-flame.svg -d 60 -s --pid <GLANCES PID>"
trace-malloc: ## Trace the malloc() calls
@echo "Malloc test is running, please wait ~30 secondes..."
@@ -95,19 +115,19 @@ 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/bin/mprof run -T 1 -C run.py -C ./conf/glances.conf --stop-after 2400 --quiet
- ./venv/bin/mprof plot --output ./docs/_static/glances-memory-profiling-with-history.png
+ ./venv-dev/bin/mprof run -T 1 -C run.py -C ./conf/glances.conf --stop-after 2400 --quiet
+ ./venv-dev/bin/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/bin/mprof run -T 1 -C run.py -C ./conf/glances.conf --disable-history --stop-after 2400 --quiet
- ./venv/bin/mprof plot --output ./docs/_static/glances-memory-profiling-without-history.png
+ ./venv-dev/bin/mprof run -T 1 -C run.py -C ./conf/glances.conf --disable-history --stop-after 2400 --quiet
+ ./venv-dev/bin/mprof plot --output ./docs/_static/glances-memory-profiling-without-history.png
rm -f mprofile_*.dat
# ===================================================================
# Docs
# ===================================================================
-docs: venv-dev-upgrade ## Create the documentation
+docs: ## Create the documentation
./venv/bin/python -m glances -C ./conf/glances.conf --api-doc > ./docs/api.rst
cd docs && ./build.sh && cd ..
@@ -120,17 +140,21 @@ release-note: ## Generate release note
@echo "\n"
git --no-pager shortlog -s -n $(LASTTAG)..HEAD
+install: ## Open a Web Browser to the installation procedure
+ sensible-browser "https://github.com/nicolargo/glances#installation"
+
# ===================================================================
# WebUI
+# Follow ./glances/outputs/static/README.md for more information
# ===================================================================
-webui: venv-dev-upgrade ## Build the Web UI
+webui: ## Build the Web UI
cd glances/outputs/static/ && npm ci && npm run build
-webui-audit: venv-dev-upgrade ## Audit the Web UI
+webui-audit: ## Audit the Web UI
cd glances/outputs/static/ && npm audit
-webui-audit-fix: venv-dev-upgrade ## Fix audit the Web UI
+webui-audit-fix: ## Fix audit the Web UI
cd glances/outputs/static/ && npm audit fix && npm ci && npm run build
# ===================================================================
@@ -147,7 +171,7 @@ flatpak: venv-dev-upgrade ## Generate FlatPack JSON file
# Docker
# ===================================================================
-docker: docker-alpine docker-ubuntu## Generate local docker images
+docker: docker-alpine docker-ubuntu ## Generate local docker images
docker-alpine: ## Generate local docker images (Alpine)
docker build --target full -f ./docker-files/alpine.Dockerfile -t glances:local-alpine-full .
@@ -172,6 +196,15 @@ run-debug: ## Start Glances in debug console mode (also called standalone)
run-local-conf: ## Start Glances in console mode with the system conf file
./venv/bin/python -m glances
+run-min: ## Start minimal Glances in console mode (also called standalone)
+ ./venv-min/bin/python -m glances -C ./conf/glances.conf
+
+run-min-debug: ## Start minimal Glances in debug console mode (also called standalone)
+ ./venv-min/bin/python -m glances -C ./conf/glances.conf -d
+
+run-min-local-conf: ## Start minimal Glances in console mode with the system conf file
+ ./venv-min/bin/python -m glances
+
run-docker-alpine-minimal: ## Start Glances Alpine Docker minimal in console mode
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
@@ -211,7 +244,4 @@ run-issue: ## Start Glances in issue mode
show-version: ## Show Glances version number
./venv/bin/python -m glances -C ./conf/glances.conf -V
-show-issue: ## Generate output for a new issue
- ./venv/bin/python -m glances -C ./conf/glances.conf --issue
-
-.PHONY: test docs docs-server venv
+.PHONY: test docs docs-server venv venv-min venv-dev
diff --git a/glances/__init__.py b/glances/__init__.py
index 7f5ce71a..50b3fc7b 100644
--- a/glances/__init__.py
+++ b/glances/__init__.py
@@ -11,6 +11,7 @@
"""Init the Glances software."""
# Import system libs
+import tracemalloc
import locale
import platform
import signal
@@ -55,7 +56,6 @@ if psutil_version_info < psutil_min_version:
sys.exit(1)
# Trac malloc is only available on Python 3.4 or higher
-import tracemalloc
def __signal_handler(signal, frame):
diff --git a/glances/amps/glances_amp.py b/glances/amps/glances_amp.py
index 6ffa2637..078e08a9 100644
--- a/glances/amps/glances_amp.py
+++ b/glances/amps/glances_amp.py
@@ -22,7 +22,7 @@ The return string is a string with one or more line (\n between lines).
If the *one_line* var is true then the AMP will be displayed in one line.
"""
-from glances.globals import u, b, nativestr
+from glances.globals import u
from glances.timer import Timer
from glances.logger import logger
diff --git a/glances/exports/cassandra/__init__.py b/glances/exports/cassandra/__init__.py
index 99fa6fb0..aa88eb13 100644
--- a/glances/exports/cassandra/__init__.py
+++ b/glances/exports/cassandra/__init__.py
@@ -15,7 +15,6 @@ from numbers import Number
from glances.logger import logger
from glances.exports.export import GlancesExport
-from glances.globals import iteritems
from cassandra.auth import PlainTextAuthProvider
from cassandra.cluster import Cluster
diff --git a/glances/exports/kafka/__init__.py b/glances/exports/kafka/__init__.py
index a962c6ae..6d365fc4 100644
--- a/glances/exports/kafka/__init__.py
+++ b/glances/exports/kafka/__init__.py
@@ -12,7 +12,7 @@
import sys
from glances.logger import logger
-from glances.globals import iteritems, json_dumps
+from glances.globals import json_dumps
from glances.exports.export import GlancesExport
from kafka import KafkaProducer
diff --git a/glances/outputs/glances_stdout_csv.py b/glances/outputs/glances_stdout_csv.py
index 719587d0..2d39a566 100644
--- a/glances/outputs/glances_stdout_csv.py
+++ b/glances/outputs/glances_stdout_csv.py
@@ -11,7 +11,6 @@
import time
-from glances.logger import logger
from glances.globals import printandflush
diff --git a/glances/outputs/glances_stdout_json.py b/glances/outputs/glances_stdout_json.py
index 6d9985ef..0f4e42c3 100644
--- a/glances/outputs/glances_stdout_json.py
+++ b/glances/outputs/glances_stdout_json.py
@@ -11,7 +11,6 @@
import time
-from glances.logger import logger
from glances.globals import printandflush
diff --git a/glances/plugins/connections/model.py b/glances/plugins/connections/model.py
index 076449d9..b3858d1e 100644
--- a/glances/plugins/connections/model.py
+++ b/glances/plugins/connections/model.py
@@ -158,9 +158,11 @@ class PluginModel(GlancesPluginModel):
msg = '{:>{width}}'.format(self.stats[s], width=max_width - len(s) + 2)
ret.append(self.curse_add_line(msg))
# Connections track
- if self.stats['nf_conntrack_enabled'] and \
- 'nf_conntrack_count' in self.stats and \
- 'nf_conntrack_max' in self.stats:
+ if (
+ self.stats['nf_conntrack_enabled']
+ and 'nf_conntrack_count' in self.stats
+ and 'nf_conntrack_max' in self.stats
+ ):
s = 'Tracked'
ret.append(self.curse_new_line())
msg = '{:{width}}'.format(nativestr(s).capitalize(), width=len(s))
diff --git a/glances/plugins/diskio/model.py b/glances/plugins/diskio/model.py
index f6c0b8ea..3502b8a0 100644
--- a/glances/plugins/diskio/model.py
+++ b/glances/plugins/diskio/model.py
@@ -13,7 +13,6 @@ from __future__ import unicode_literals
from glances.globals import nativestr
from glances.timer import getTimeSinceLastUpdate
from glances.plugins.plugin.model import GlancesPluginModel
-from glances.logger import logger
import psutil
diff --git a/glances/plugins/folders/model.py b/glances/plugins/folders/model.py
index 6c426c25..e1d8328b 100644
--- a/glances/plugins/folders/model.py
+++ b/glances/plugins/folders/model.py
@@ -15,7 +15,6 @@ import numbers
from glances.globals import nativestr
from glances.folder_list import FolderList as glancesFolderList
from glances.plugins.plugin.model import GlancesPluginModel
-from glances.logger import logger
class PluginModel(GlancesPluginModel):
diff --git a/glances/plugins/ip/model.py b/glances/plugins/ip/model.py
index 446ec08d..02d884eb 100644
--- a/glances/plugins/ip/model.py
+++ b/glances/plugins/ip/model.py
@@ -12,7 +12,7 @@
import threading
from ujson import loads
-from glances.globals import iterkeys, urlopen, queue, urlopen_auth
+from glances.globals import urlopen, queue, urlopen_auth
from glances.logger import logger
from glances.timer import Timer
from glances.timer import getTimeSinceLastUpdate
diff --git a/glances/plugins/mem/model.py b/glances/plugins/mem/model.py
index 42aaf2b0..52ceed0c 100644
--- a/glances/plugins/mem/model.py
+++ b/glances/plugins/mem/model.py
@@ -9,7 +9,6 @@
"""Virtual memory plugin."""
-from glances.logger import logger
from glances.globals import iterkeys
from glances.plugins.plugin.model import GlancesPluginModel
diff --git a/glances/plugins/plugin/view.py b/glances/plugins/plugin/view.py
index ac67e93c..aadf3e2f 100644
--- a/glances/plugins/plugin/view.py
+++ b/glances/plugins/plugin/view.py
@@ -23,18 +23,9 @@ I am your father...
...for all Glances view plugins.
"""
-import re
import json
-import copy
-from operator import itemgetter
-
-from glances.globals import iterkeys, itervalues, listkeys, mean, nativestr
-from glances.actions import GlancesActions
-from glances.history import GlancesHistory
-from glances.logger import logger
-from glances.events import glances_events
-from glances.thresholds import glances_thresholds
-from glances.timer import Counter, Timer
+
+from glances.globals import listkeys
from glances.plugins.plugin.model import fields_unit_short, fields_unit_type
diff --git a/glances/plugins/ports/model.py b/glances/plugins/ports/model.py
index ac0e9a51..454672f8 100644
--- a/glances/plugins/ports/model.py
+++ b/glances/plugins/ports/model.py
@@ -19,7 +19,7 @@ import numbers
from glances.globals import WINDOWS, MACOS, BSD, bool_type
from glances.ports_list import GlancesPortsList
from glances.web_list import GlancesWebList
-from glances.timer import Timer, Counter
+from glances.timer import Counter
from glances.logger import logger
from glances.plugins.plugin.model import GlancesPluginModel
diff --git a/glances/plugins/processlist/model.py b/glances/plugins/processlist/model.py
index 30f9cbba..82bf494a 100644
--- a/glances/plugins/processlist/model.py
+++ b/glances/plugins/processlist/model.py
@@ -18,7 +18,6 @@ from glances.processes import glances_processes, sort_stats
from glances.outputs.glances_unicode import unicode_message
from glances.plugins.core.model import PluginModel as CorePluginModel
from glances.plugins.plugin.model import GlancesPluginModel
-from glances.programs import processes_to_programs
def seconds_to_hms(input_seconds):
diff --git a/glances/plugins/system/model.py b/glances/plugins/system/model.py
index 71873709..0b53bfd5 100644
--- a/glances/plugins/system/model.py
+++ b/glances/plugins/system/model.py
@@ -14,7 +14,6 @@ import platform
import re
from io import open
-from glances.logger import logger
from glances.globals import iteritems
from glances.plugins.plugin.model import GlancesPluginModel
diff --git a/glances/server.py b/glances/server.py
index 44e8b1ea..649801d6 100644
--- a/glances/server.py
+++ b/glances/server.py
@@ -15,7 +15,7 @@ import sys
from base64 import b64decode
from glances import __version__
-from glances.globals import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer, Server
+from glances.globals import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer
from glances.autodiscover import GlancesAutoDiscoverClient
from glances.logger import logger
from glances.stats_server import GlancesStatsServer
diff --git a/unitest-restful.py b/unitest-restful.py
index f9455385..a697ff78 100755
--- a/unitest-restful.py
+++ b/unitest-restful.py
@@ -16,7 +16,6 @@ import subprocess
import time
import numbers
import unittest
-import sys
from glances import __version__
from glances.globals import text_type
diff --git a/unitest-xmlrpc.py b/unitest-xmlrpc.py
index 22e9e977..03df2bac 100755
--- a/unitest-xmlrpc.py
+++ b/unitest-xmlrpc.py
@@ -16,7 +16,6 @@ import shlex
import subprocess
import time
import unittest
-import sys
from glances import __version__
from glances.globals import ServerProxy
diff --git a/unitest.py b/unitest.py
index e2cf8ebb..206c850a 100755
--- a/unitest.py
+++ b/unitest.py
@@ -33,7 +33,6 @@ from glances.plugins.plugin.model import GlancesPluginModel
from glances.programs import processes_to_programs
from glances.secure import secure_popen
-from tracemalloc import Snapshot
# Global variables
# =================