Skip to content

Commit d9025c1

Browse files
committed
Convert to PDO-style versioning
Update version to 0.2.0 Signed-off-by: Mic Bowman <mic.bowman@intel.com>
1 parent cc37e84 commit d9025c1

File tree

2 files changed

+40
-31
lines changed

2 files changed

+40
-31
lines changed

VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
v0.2.0 cc37e8428d9564256bbdff63714113eb63795f3e automated testing enabled; pdo 0.4.1
2+
v0.1.0 b57f345c67b6babb8b386d695b6c7e665b76e8b0 initial commit of exchange and digital asset families; pdo 0.2.63

bin/get_version

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,42 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import argparse
18+
import os
19+
import pathlib
1720
import subprocess
18-
import sys
19-
import warnings
20-
21-
count = 0
22-
commit = ''
23-
dirty = ''
24-
25-
try :
26-
output = subprocess.check_output(['git', 'describe', '--dirty'])
27-
(version, *rest) = output.decode('utf-8').strip().split('-')
28-
(major, minor, patch) = version.strip('v').split('.')
29-
30-
# first case: this is a dirty tagged release, only dirty flag
31-
if len(rest) == 1 :
32-
assert rest[0] == 'dirty'
33-
dirty = 'dirty'
34-
# second case: this is a committed post tag release
35-
elif len(rest) == 2 :
36-
count = rest[0]
37-
commit = rest[1]
38-
# third case: this is a dirty, committed post tag release
39-
elif len(rest) == 3 :
40-
assert rest[2] == 'dirty'
41-
count = rest[0]
42-
commit = rest[1]
43-
dirty = rest[2]
44-
45-
print('{}.{}.{}'.format(major, minor, count))
46-
except Exception as e :
47-
warnings.warn('failed to compute version, using default')
48-
print('0.0.0')
21+
22+
pdo_source_root=pathlib.Path(__file__).parent.parent
23+
version_file = pdo_source_root / 'VERSION'
24+
25+
parser = argparse.ArgumentParser()
26+
27+
parser.add_argument(
28+
'--version-file', '-f',
29+
help=f'File where version information is stored (default: {version_file})',
30+
type=str)
31+
32+
options = parser.parse_args()
33+
34+
if options.version_file :
35+
version_file = pathlib.Path(options.version_file)
36+
pdo_source_root = version_file.parent
37+
38+
# the version file is a tab separated list of version numbers and git commit hashes in reverse
39+
# order (newest is at the top of the file)
40+
with open(version_file, 'r') as vf :
41+
(version, commit, *rest) = vf.readline().strip().split('\t')
42+
43+
# the version is of the form x.y.z, there may be an optional 'v' at the beginning of the version
44+
# string
45+
(major, minor, patch) = version.strip('v').split('.')
46+
47+
# compute the number of commits since the tagged version was
48+
# committed to the repository
49+
command = ['git', 'rev-list', commit + '...HEAD', '--count']
50+
output = subprocess.run(command, cwd=pdo_source_root, capture_output=True, text=True)
51+
count = output.stdout.strip()
52+
53+
# the actual patch version number is the recorded patch number added to the number of commits
54+
# since the version was committed
55+
print('{}.{}.{}'.format(major, minor, int(patch) + int(count)))

0 commit comments

Comments
 (0)