Skip to content

Commit

Permalink
use semver for version info
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangWaltenberger committed Jan 17, 2024
1 parent 3a0335e commit e6439fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 32 deletions.
42 changes: 10 additions & 32 deletions smodels/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from __future__ import print_function
import sys
import os
from typing import Union
from semver import VersionInfo

def installDirectory():
"""
Expand Down Expand Up @@ -127,32 +129,6 @@ def authors():
authors += to_add
return authors

def _toTuple_ ( ver ):
""" convert version string to tuple """
a = ver.replace(" ",".",1).split(".")
for ctr,el in enumerate(a):
try:
a[ctr]=int(el)
except ValueError:
a[ctr]=el
b=[]
for i in a:
found=False
for pf in [ "rc", "post", "pre" ]:
if type(i)==str and pf in i:
found=True
minor = i[:i.find(pf)]
try:
minor = int(minor)
except (ValueError,TypeError):
pass
b.append ( minor )
b.append ( i[i.find(pf):] )
continue
if not found:
b.append ( i )
return tuple(b)

def requirements():
ret=[]
f = open("%s/smodels/share/requirements.txt" % installDirectory())
Expand All @@ -161,20 +137,22 @@ def requirements():
f.close()
return ret

def version(astuple=False):
def version( return_object : bool = False ) -> Union[str,VersionInfo]:
"""
Print version number of the SModelS framework.
Returns version number of the SModelS framework.
:param return_object: Return a semver VersionInfo object instead of string
:returns: version, either as string or as semver VersionInfo object
"""
f = open("%s/smodels/version" % installDirectory())
f = open( f"{installDirectory()}/smodels/version" )
l = f.readline()
f.close()
l = l.replace("\n", "")
l.strip()
if not astuple:
if not return_object:
return l
return _toTuple_ ( l )

import semver
return semver.parse ( l )

def license():
"""
Expand Down
1 change: 1 addition & 0 deletions smodels/share/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pyslha>=3.1.0
pyhf>=0.6.1
jsonpatch>=1.25
jsonschema>=3.2.0
semver>=2.0.0

0 comments on commit e6439fd

Please sign in to comment.