Skip to content

Commit 3329f73

Browse files
committed
BLD: output friendlier error messages from scons.
Replace assertion failures with a gentler scons termination.
1 parent 0e048ce commit 3329f73

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

site_scons/libdiffpybuildutils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88

99
MYDIR = os.path.dirname(os.path.abspath(__file__))
1010

11-
GIT_MISSING_ERROR_MSG = """
11+
EMSG_GIT_MISSING = """
1212
Cannot determine libdiffpy version. Compile from a git repository
1313
or use a source archive from
1414
1515
https://github.com/diffpy/libdiffpy/releases
1616
"""
1717

18+
EMSG_BAD_FALLBACK_VERSION = """
19+
Inconsistent FALLBACK_VERSION {} vs {} from git tag.
20+
"""
21+
1822

1923
def gitinfo():
2024
'Extract dictionary of version data from git records.'
@@ -65,12 +69,13 @@ def getversion():
6569
if gi:
6670
afb = FALLBACK_VERSION
6771
gfb = gi['version'].split('.post')[0] + '.post0'
68-
emsg = "Inconsistent FALLBACK_VERSION {!r}. Git tag suggests {!r}."
69-
assert gfb == afb, emsg.format(afb, gfb)
72+
if gfb != afb:
73+
raise RuntimeError(EMSG_BAD_FALLBACK_VERSION.format(afb, gfb))
7074
rv.update(gi)
7175
else:
7276
# Not a git repository. Require that gitarchive.cfg is expanded.
73-
assert '$Format:' not in ga['commit'], GIT_MISSING_ERROR_MSG
77+
if '$Format:' in ga['commit']:
78+
raise RuntimeError(EMSG_GIT_MISSING)
7479
rv['commit'] = ga['commit']
7580
rv['date'] = ga['date']
7681
# First assume we have an undetermined post-release. Keep version

src/diffpy/SConscript.version

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ import string
55
Import('env')
66

77

8+
def get_version_or_die():
9+
from libdiffpybuildutils import getversion
10+
try:
11+
rv = getversion()
12+
except RuntimeError as e:
13+
print(e)
14+
Exit(1)
15+
return rv
16+
17+
818
def parsemajorminor(hcode):
919
'Extract major and minor version from a C++ header file.'
1020
mx = re.search(r'(?m)^#define *DIFFPY_VERSION_MAJOR *(\d+)', hcode)
@@ -69,9 +79,8 @@ vhpp = File('version.hpp')
6979
if os.path.isfile(str(vhpp.srcnode())):
7080
majorminor = parsemajorminor(vhpp.srcnode().get_contents())
7181
else:
72-
from libdiffpybuildutils import getversion
7382
vtpl = File('version.tpl')
74-
gver = getversion()
83+
gver = get_version_or_die()
7584
vhpp, = env.BuildVersionCode(['version.hpp'], vtpl)
7685
env.Depends(vhpp, env.Value(gver['version'] + gver['commit']))
7786
majorminor = (gver['major'], gver['minor'])

0 commit comments

Comments
 (0)