From b3f201dd8dbe7b9982cb6c8a45e6774f75a7f5f3 Mon Sep 17 00:00:00 2001 From: mrtoine Date: Mon, 15 Dec 2025 13:37:56 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20gestion=20conditionnelle=20de?= =?UTF-8?q?=20la=20version=20applicative=20avec=20mise=20=C3=A0=20jour=20o?= =?UTF-8?q?u=20lecture=20depuis=20`VERSION.txt`=20selon=20le=20mode=20(DEV?= =?UTF-8?q?/PROD).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- devart/settings.py | 49 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/devart/settings.py b/devart/settings.py index 044d68c..68e1525 100644 --- a/devart/settings.py +++ b/devart/settings.py @@ -158,15 +158,44 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' # On défini une fonction qui va s'occuper de récupérer la version actuelle de l'application def get_git_version(): - try: - import subprocess - hash_version = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip().decode('utf-8') - app_version = subprocess.check_output( - ["git", "describe", "--tags", "--abbrev=0"], - stderr=subprocess.STDOUT - ).strip().decode('utf-8') - return app_version + " (" + hash_version + ")" - except Exception: - return 'Dev / Pas de git' + import subprocess + """ + DEV : Calcule la version Git et met à jour le fichier VERSION.txt + PROD : Lit simplement le fichier VERSION.txt + """ + version_file = os.path.join(BASE_DIR, 'VERSION.txt') + + # --- CAS 1 : MODE DÉVELOPPEMENT (Mise à jour du fichier) --- + if DEBUG: + try: + # 1. On récupère les infos Git + hash_part = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], + stderr=subprocess.DEVNULL).strip().decode('utf-8') + + try: + tag_part = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"], + stderr=subprocess.DEVNULL).strip().decode('utf-8') + except: + tag_part = "v0.0.x" # Fallback si pas de tag + + full_version = f"{tag_part} ({hash_part})" + + # 2. On ÉCRIT/MET À JOUR le fichier texte + with open(version_file, 'w') as f: + f.write(full_version) + + return full_version + + except Exception as e: + # Si Git échoue en local (rare, mais possible) + return f"Dev Mode (Err: {e})" + + # --- CAS 2 : MODE PRODUCTION (Lecture seule) --- + else: + if os.path.exists(version_file): + with open(version_file, 'r') as f: + return f.read().strip() + else: + return "Version inconnue (Fichier manquant)" GIT_VERSION = get_git_version() \ No newline at end of file