mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-16 18:38:32 +03:00
pySim-shell: renovate version command
In case pySim-shell is used directly from the git repository (not
installed via a package manager), the version command fails with an
exception because pkg_resources.get_distribution('pySim') fails.
Let's renovate the version command and migrate from pkg_resources to
importlib.resources. There are many users and developers out there who
retrieve pySim-shell directly from the git repository and not via pip3.
To accommodate for that, let's check if pySim-shell.py is located in a
git repository and if so, let's display the HEAD commit hash instead.
Since the version of the currently installed pyosmocom version also
plays a critical role, let's display the pyosmocom version as well.
Related: OS#6830
Change-Id: I2b9038f88cfcaa07894a2f09c7f5ad8a5474083d
This commit is contained in:
@@ -519,8 +519,17 @@ Online manual available at https://downloads.osmocom.org/docs/pysim/master/html/
|
|||||||
@cmd2.with_category(CUSTOM_CATEGORY)
|
@cmd2.with_category(CUSTOM_CATEGORY)
|
||||||
def do_version(self, opts):
|
def do_version(self, opts):
|
||||||
"""Print the pySim software version."""
|
"""Print the pySim software version."""
|
||||||
import pkg_resources
|
from importlib.metadata import version as vsn
|
||||||
self.poutput(pkg_resources.get_distribution('pySim'))
|
self.poutput("pyosmocom " + vsn('pyosmocom'))
|
||||||
|
import os
|
||||||
|
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
if os.path.isdir(os.path.join(cwd, ".git")):
|
||||||
|
import subprocess
|
||||||
|
url = subprocess.check_output(['git', 'config', '--get', 'remote.origin.url']).decode('ascii').strip()
|
||||||
|
version = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=cwd).decode('ascii').strip()
|
||||||
|
self.poutput(os.path.basename(url) + " " + version)
|
||||||
|
else:
|
||||||
|
self.poutput("pySim " + vsn('pySim'))
|
||||||
|
|
||||||
@with_default_category('pySim Commands')
|
@with_default_category('pySim Commands')
|
||||||
class PySimCommands(CommandSet):
|
class PySimCommands(CommandSet):
|
||||||
|
|||||||
Reference in New Issue
Block a user