Skip to content

Commit

Permalink
fix version when using zipapp
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-mangin committed Aug 19, 2024
1 parent d09208c commit d401910
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/exabgp/application/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()


Expand Down
16 changes: 15 additions & 1 deletion src/exabgp/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d401910

Please sign in to comment.