Skip to content

Commit f65c0c9

Browse files
committed
Add micro field to the libdiffpy version.
Assume version tag format vMajor.Minor[.Micro]. Convert DIFFPY_VERSION to a floating-point number with a last version commit age starting at the 4th decimal digit.
1 parent 2970b1a commit f65c0c9

4 files changed

Lines changed: 31 additions & 16 deletions

File tree

site_scons/libdiffpybuildutils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def gitinfo():
2525
vtag = words[0].lstrip('v')
2626
vnum = int((words[1:2] or ['0'])[0])
2727
rv['commit'], rv['date'] = glog.strip().split(None, 1)
28-
mx = re.match(r'^(\d+)\.(\d+)((?:[ab]|rc)\d*)?', vtag)
28+
mx = re.match(r'^(\d+)\.(\d+)(?:\.(\d+))?((?:[ab]|rc)\d*)?', vtag)
2929
rv['major'] = int(mx.group(1))
3030
rv['minor'] = int(mx.group(2))
31-
rv['prerelease'] = mx.group(3)
31+
rv['micro'] = int(mx.group(3) or 0)
32+
rv['prerelease'] = mx.group(4)
3233
rv['number'] = vnum
3334
rv['version'] = vtag
34-
numsep = rv['prerelease'] and '.dev' or '.'
3535
if vnum:
36-
rv['version'] += numsep + str(vnum)
36+
rv['version'] += '.post' + str(vnum)
3737
_cached_gitinfo = rv
3838
return gitinfo()
3939

src/diffpy/SConscript.version

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ def parsemajorminor(hcode):
1717
def build_VersionCode(target, source, env):
1818
tplcode = source[0].get_contents()
1919
numversion = (1000000 * ginfo['major'] +
20-
1000 * ginfo['minor'] + ginfo['number'])
20+
1000 * ginfo['minor'] + ginfo['micro'] +
21+
0.0001 * ginfo['number'])
22+
libversion = "%.0f" % numversion
23+
if ginfo['number']:
24+
libversion = "%.4f" % numversion
2125
if ginfo['prerelease']:
22-
numversion = "(-500 + %i)" % numversion
26+
libversion = "(-0.5 + %s)" % libversion
2327
flds = {
24-
'DIFFPY_VERSION' : numversion,
28+
'DIFFPY_VERSION' : libversion,
2529
'DIFFPY_VERSION_MAJOR' : ginfo['major'],
2630
'DIFFPY_VERSION_MINOR' : ginfo['minor'],
31+
'DIFFPY_VERSION_MICRO' : ginfo['micro'],
2732
'DIFFPY_VERSION_STR' : ginfo['version'],
2833
'DIFFPY_VERSION_DATE' : ginfo['date'],
2934
'DIFFPY_GIT_SHA' : ginfo['commit'],

src/diffpy/version.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818

1919
#include <diffpy/version.hpp>
2020

21-
const int libdiffpy_version_info::version = DIFFPY_VERSION;
21+
const double libdiffpy_version_info::version = DIFFPY_VERSION;
2222
const char* libdiffpy_version_info::version_str = DIFFPY_VERSION_STR;
2323
const int libdiffpy_version_info::major = DIFFPY_VERSION_MAJOR;
2424
const int libdiffpy_version_info::minor = DIFFPY_VERSION_MINOR;
25+
const int libdiffpy_version_info::micro = DIFFPY_VERSION_MICRO;
2526
const char* libdiffpy_version_info::date = DIFFPY_VERSION_DATE;
2627
const char* libdiffpy_version_info::git_sha = DIFFPY_GIT_SHA;
2728

src/diffpy/version.tpl

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* DIFFPY_VERSION,
1717
* DIFFPY_VERSION_MAJOR,
1818
* DIFFPY_VERSION_MINOR,
19+
* DIFFPY_VERSION_MICRO,
1920
* DIFFPY_VERSION_STR,
2021
* DIFFPY_VERSION_DATE
2122
* DIFFPY_GIT_SHA
@@ -25,15 +26,22 @@
2526
*
2627
*****************************************************************************/
2728

28-
#ifndef VERSION_HPP_INCLUDED
29-
#define VERSION_HPP_INCLUDED
29+
#ifndef LIBDIFFPY_VERSION_HPP_INCLUDED
30+
#define LIBDIFFPY_VERSION_HPP_INCLUDED
3031

3132
#define DIFFPY_VERSION_MAJOR ${DIFFPY_VERSION_MAJOR}
3233
#define DIFFPY_VERSION_MINOR ${DIFFPY_VERSION_MINOR}
33-
34-
// DIFFPY_VERSION % 1000 is number of git commits since minor version
35-
// DIFFPY_VERSION / 1000 % 1000 is the minor version
36-
// DIFFPY_VERSION / 1000000 is the major version
34+
#define DIFFPY_VERSION_MICRO ${DIFFPY_VERSION_MICRO}
35+
36+
// round(DIFFPY_VERSION) / 1000000 is the major version
37+
// round(DIFFPY_VERSION) / 1000 % 1000 is the minor version
38+
// round(DIFFPY_VERSION) % 1000 is the micro version
39+
// round(DIFFPY_VERSION * 10000) % 1000
40+
// is number of git commits since the last tag
41+
//
42+
// alpha and beta releases have smaller DIFFPY_VERSION than
43+
// a completed release. Numerical comparison of DIFFPY_VERSION
44+
// values from two pre-releases may be inaccurate.
3745

3846
#define DIFFPY_VERSION ${DIFFPY_VERSION}
3947

@@ -54,15 +62,16 @@
5462

5563
struct libdiffpy_version_info {
5664

57-
static const int version;
65+
static const double version;
5866
static const char* version_str;
5967
static const int major;
6068
static const int minor;
69+
static const int micro;
6170
static const char* date;
6271
static const char* git_sha;
6372

6473
};
6574

66-
#endif // VERSION_HPP_INCLUDED
75+
#endif // LIBDIFFPY_VERSION_HPP_INCLUDED
6776

6877
// vim:ft=cpp:

0 commit comments

Comments
 (0)