dexter has uploaded this change for review. (
https://gerrit.osmocom.org/c/pysim/+/41738?usp=email )
Change subject: pySim-shell: output git hash in case get_distribution fails
......................................................................
pySim-shell: output git hash in case get_distribution fails
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. In
that case, let's check if pySim-shell.py is inside a git repository
and if so, get the HEAD commit hash and display it instead.
Related: OS#6830
Change-Id: I2b9038f88cfcaa07894a2f09c7f5ad8a5474083d
---
M pySim-shell.py
1 file changed, 12 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/38/41738/1
diff --git a/pySim-shell.py b/pySim-shell.py
index a8b15d5..96658d3 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -520,7 +520,18 @@
def do_version(self, opts):
"""Print the pySim software version."""
import pkg_resources
- self.poutput(pkg_resources.get_distribution('pySim'))
+ from pkg_resources import DistributionNotFound
+ try:
+ self.poutput(pkg_resources.get_distribution('pySim'))
+ except DistributionNotFound as e:
+ import subprocess
+ import os
+ cwd = os.path.dirname(os.path.realpath(__file__))
+ if os.path.isdir(cwd + "/.git"):
+ version = subprocess.check_output(['git', 'rev-parse',
'HEAD'], cwd=cwd).decode('ascii').strip()
+ self.poutput("pySim-git-" + version)
+ else:
+ raise(e)
@with_default_category('pySim Commands')
class PySimCommands(CommandSet):
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/41738?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I2b9038f88cfcaa07894a2f09c7f5ad8a5474083d
Gerrit-Change-Number: 41738
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <[email protected]>