summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolashennion@gmail.com>2024-10-23 23:03:43 +0200
committernicolargo <nicolashennion@gmail.com>2024-10-23 23:03:43 +0200
commit68104b7d0f73379cd69d4620b325d37ccc34448d (patch)
tree461cba06ffe145df65f5897757fbbb31f1986006
parent2d0dcb18e1b07f749a804ebc0b2e1b54199990bd (diff)
Set the version by reading directly the pyproject file in local (dev and Docker) - Related to #2956
-rw-r--r--docker-files/alpine.Dockerfile5
-rw-r--r--docker-files/ubuntu.Dockerfile2
-rw-r--r--glances/__init__.py15
3 files changed, 20 insertions, 2 deletions
diff --git a/docker-files/alpine.Dockerfile b/docker-files/alpine.Dockerfile
index 2b2bfe66..55370869 100644
--- a/docker-files/alpine.Dockerfile
+++ b/docker-files/alpine.Dockerfile
@@ -70,6 +70,7 @@ COPY requirements.txt docker-requirements.txt webui-requirements.txt optional-re
##############################################################################
# BUILD: Install the minimal image deps
+# Minimal in Docker mean: Docker + WebUI
FROM build as buildMinimal
ARG PYTHON_VERSION
@@ -103,6 +104,10 @@ ARG PYTHON_VERSION
COPY ./docker-compose/glances.conf /etc/glances/glances.conf
COPY ./glances/. /app/glances/
+# Copy pyproject file in order to have the version
+# Note: Glances is not installed as a Pypi pkg in Docker
+COPY pyproject.toml /app
+
# Copy binary and update PATH
COPY docker-bin.sh /usr/local/bin/glances
RUN chmod a+x /usr/local/bin/glances
diff --git a/docker-files/ubuntu.Dockerfile b/docker-files/ubuntu.Dockerfile
index 3a5ccc4c..d81d4a4d 100644
--- a/docker-files/ubuntu.Dockerfile
+++ b/docker-files/ubuntu.Dockerfile
@@ -59,6 +59,7 @@ COPY requirements.txt docker-requirements.txt webui-requirements.txt optional-re
##############################################################################
# BUILD: Install the minimal image deps
+# Minimal in Docker mean: Docker + WebUI
FROM build as buildMinimal
ARG PYTHON_VERSION
@@ -86,6 +87,7 @@ ARG PYTHON_VERSION
# Copy Glances source code and config file
COPY ./docker-compose/glances.conf /etc/glances/glances.conf
COPY ./glances/. /app/glances/
+COPY pyproject.toml /app
# Copy binary and update PATH
COPY docker-bin.sh /usr/local/bin/glances
diff --git a/glances/__init__.py b/glances/__init__.py
index 2683afd1..fb28869e 100644
--- a/glances/__init__.py
+++ b/glances/__init__.py
@@ -11,19 +11,30 @@
# Import system libs
import locale
+import os
import platform
+import re
import signal
import sys
import tracemalloc
from importlib import metadata
# Global name
-# Version should start and end with a numerical char
+# Version is now set in the pyproject.toml file
+# and should start and end with a numerical char
# See https://packaging.python.org/specifications/core-metadata/#version
try:
+ # Read the version from the metadata (when deployed with Pypi)
__version__ = metadata.version("glances")
except metadata.PackageNotFoundError:
- __version__ = "0.0.0+unknown"
+ if os.path.exists('pyproject.toml'):
+ # In local try to read the version in the pyproject.toml file
+ # Dirty but it make the job
+ with open('pyproject.toml', encoding='utf-8') as f:
+ __version__ = re.search(r"^version = ['\"]([^'\"]*)['\"]", f.read(), re.M).group(1)
+ else:
+ # Else set a unknown version
+ __version__ = "0.0.0+unknown"
__apiversion__ = '4'
__author__ = 'Nicolas Hennion <nicolas@nicolargo.com>'
__license__ = 'LGPLv3'