mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-04 14:30:11 +01:00
Fix "fdroid --version"
Fixes https://gitlab.com/fdroid/fdroidserver/-/issues/1164 . Helpful resource: https://packaging.python.org/en/latest/guides/single-sourcing-package-version/
This commit is contained in:
parent
7ade08e46d
commit
b9c7e8f63a
@ -23,7 +23,9 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import logging
|
import logging
|
||||||
|
import importlib.metadata
|
||||||
|
|
||||||
|
import git
|
||||||
import fdroidserver.common
|
import fdroidserver.common
|
||||||
import fdroidserver.metadata
|
import fdroidserver.metadata
|
||||||
from fdroidserver import _
|
from fdroidserver import _
|
||||||
@ -142,31 +144,21 @@ def main():
|
|||||||
print(_("""ERROR: The "server" subcommand has been removed, use "deploy"!"""))
|
print(_("""ERROR: The "server" subcommand has been removed, use "deploy"!"""))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif command == '--version':
|
elif command == '--version':
|
||||||
output = _('no version info found!')
|
|
||||||
cmddir = os.path.realpath(os.path.dirname(os.path.dirname(__file__)))
|
|
||||||
moduledir = os.path.realpath(os.path.dirname(fdroidserver.common.__file__) + '/..')
|
|
||||||
if cmddir == moduledir:
|
|
||||||
# running from git
|
|
||||||
os.chdir(cmddir)
|
|
||||||
if os.path.isdir('.git'):
|
|
||||||
import subprocess
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(['git', 'describe'],
|
print(importlib.metadata.version("fdroidserver"))
|
||||||
stderr=subprocess.STDOUT,
|
|
||||||
universal_newlines=True)
|
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
output = 'git commit ' + subprocess.check_output(['git', 'rev-parse', 'HEAD'],
|
|
||||||
universal_newlines=True)
|
|
||||||
elif os.path.exists('setup.py'):
|
|
||||||
m = re.search(r'''.*[\s,\(]+version\s*=\s*["']([0-9a-z.]+)["'].*''',
|
|
||||||
open('setup.py').read(), flags=re.MULTILINE)
|
|
||||||
if m:
|
|
||||||
output = m.group(1) + '\n'
|
|
||||||
else:
|
|
||||||
from pkg_resources import get_distribution
|
|
||||||
output = get_distribution('fdroidserver').version + '\n'
|
|
||||||
print(output)
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
except importlib.metadata.PackageNotFoundError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
print(
|
||||||
|
git.repo.Repo(
|
||||||
|
os.path.dirname(os.path.dirname(__file__))
|
||||||
|
).git.describe(always=True, tags=True)
|
||||||
|
)
|
||||||
|
sys.exit(0)
|
||||||
|
except git.exc.InvalidGitRepositoryError:
|
||||||
|
print(_('No version information could be found.'))
|
||||||
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print(_("Command '%s' not recognised.\n" % command))
|
print(_("Command '%s' not recognised.\n" % command))
|
||||||
print_help(available_plugins=available_plugins)
|
print_help(available_plugins=available_plugins)
|
||||||
|
Loading…
Reference in New Issue
Block a user