Set the version by reading directly the pyproject file in local (dev and Docker) - Related to #2956

This commit is contained in:
nicolargo 2024-10-23 23:03:43 +02:00
parent 2d0dcb18e1
commit 68104b7d0f
3 changed files with 20 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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'