From d401910daa8e80a1c4df20b52d23c78f80460ccd Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Mon, 19 Aug 2024 16:02:16 +0100 Subject: [PATCH] fix version when using zipapp --- src/exabgp/application/version.py | 5 +++-- src/exabgp/version.py | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/exabgp/application/version.py b/src/exabgp/application/version.py index 353ad5faa..ff9176681 100644 --- a/src/exabgp/application/version.py +++ b/src/exabgp/application/version.py @@ -2,12 +2,12 @@ """exabgp current version""" +import os import sys import argparse import platform -from exabgp.version import version - +from exabgp.version import version, get_root def setargs(sub): # fmt:off @@ -25,6 +25,7 @@ def cmdline(cmdarg): sys.stdout.write('ExaBGP : %s\n' % version) sys.stdout.write('Python : %s\n' % sys.version.replace('\n', ' ')) sys.stdout.write('Uname : %s\n' % ' '.join(platform.uname()[:5])) + sys.stdout.write('From : %s\n' % get_root()) sys.stdout.flush() diff --git a/src/exabgp/version.py b/src/exabgp/version.py index 7b607c4b0..275e4337e 100644 --- a/src/exabgp/version.py +++ b/src/exabgp/version.py @@ -2,7 +2,21 @@ import sys from datetime import datetime -modification_time = modification_time = os.path.getmtime(os.path.abspath(__file__)) +def get_zipapp(): + return os.path.abspath(os.path.sep.join(__file__.split(os.path.sep)[:-2])) + +def get_root(): + if os.path.isfile(get_zipapp()): + return get_zipapp() + return os.path.abspath(os.path.sep.join(__file__.split(os.path.sep)[:-1])) + +try: + file = os.path.abspath(__file__) + modification_time = modification_time = os.path.getmtime(file) +except NotADirectoryError: + zipapp = get_zipapp() + modification_time = modification_time = os.path.getmtime(zipapp) + date = datetime.fromtimestamp(modification_time) commit = "unset"