Skip to content

Commit 365f646

Browse files
committed
Merge pull request #1660 from boegel/fix_bootstrap_py3
fix bootstrap script for environment where 'python' is Python 3.x
2 parents 3833edd + 6174bca commit 365f646

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

easybuild/scripts/bootstrap_eb.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,19 @@ def debug(msg):
9191
"""Print debug message."""
9292

9393
if print_debug:
94-
print "[[DEBUG]]", msg
94+
print("[[DEBUG]] " + msg)
9595

9696

9797
def info(msg):
9898
"""Print info message."""
9999

100-
print "[[INFO]]", msg
100+
print("[[INFO]] " + msg)
101101

102102

103103
def error(msg, exit=True):
104104
"""Print error message and exit."""
105105

106-
print "[[ERROR]]", msg
106+
print("[[ERROR]] " + msg)
107107
sys.exit(1)
108108

109109

@@ -368,7 +368,7 @@ def stage1(tmpdir, sourcepath):
368368
version_re = re.compile(pattern)
369369
version_out_file = os.path.join(tmpdir, 'eb_version.out')
370370
eb_version_cmd = 'from easybuild.tools.version import this_is_easybuild; print(this_is_easybuild())'
371-
cmd = "python -c '%s' > %s 2>&1" % (eb_version_cmd, version_out_file)
371+
cmd = "%s -c '%s' > %s 2>&1" % (sys.executable, eb_version_cmd, version_out_file)
372372
debug("Determining EasyBuild version using command '%s'" % cmd)
373373
os.system(cmd)
374374
txt = open(version_out_file, "r").read()
@@ -407,37 +407,37 @@ def stage2(tmpdir, templates, install_path, distribute_egg_dir, sourcepath):
407407

408408
info("\n\n+++ STAGE 2: installing EasyBuild in %s with EasyBuild from stage 1...\n\n" % install_path)
409409

410-
# inject path to distribute installed in stage 1 into $PYTHONPATH via preinstallopts
411-
# other approaches are not reliable, since EasyBuildMeta easyblock unsets $PYTHONPATH
412410
if distribute_egg_dir is None:
413411
preinstallopts = ''
414412
else:
413+
# inject path to distribute installed in stage 1 into $PYTHONPATH via preinstallopts
414+
# other approaches are not reliable, since EasyBuildMeta easyblock unsets $PYTHONPATH;
415415
preinstallopts = "export PYTHONPATH=%s:$PYTHONPATH && " % distribute_egg_dir
416416

417417
# also add location to easy_install provided through stage0 to $PATH
418418
curr_path = os.environ.get('PATH', '').split(os.pathsep)
419419
os.environ['PATH'] = os.pathsep.join([os.path.join(tmpdir, 'bin')] + curr_path)
420420
debug("$PATH: %s" % os.environ['PATH'])
421421

422-
# ensure that (latest) distribute is installed as well alongside EasyBuild,
422+
# ensure that (latest) setuptools is installed as well alongside EasyBuild,
423423
# since it is a required runtime dependency for recent vsc-base and EasyBuild versions
424424
# this is necessary since we provide our own distribute installation during the bootstrap (cfr. stage0)
425-
preinstallopts += "easy_install -U --prefix %(installdir)s distribute && "
425+
preinstallopts += "easy_install -U --prefix %(installdir)s setuptools && "
426426

427427
templates.update({
428428
'preinstallopts': preinstallopts,
429429
})
430430

431431
# create easyconfig file
432432
ebfile = os.path.join(tmpdir, 'EasyBuild-%s.eb' % templates['version'])
433-
f = open(ebfile, "w")
433+
handle = open(ebfile, 'w')
434434
templates.update({
435435
'source_urls': '\n'.join(["'%s/%s/%s'," % (PYPI_SOURCE_URL, pkg[0], pkg) for pkg in EASYBUILD_PACKAGES]),
436436
'sources': "%(vsc-base)s%(easybuild-framework)s%(easybuild-easyblocks)s%(easybuild-easyconfigs)s" % templates,
437437
'pythonpath': distribute_egg_dir,
438438
})
439-
f.write(EASYBUILD_EASYCONFIG_TEMPLATE % templates)
440-
f.close()
439+
handle.write(EASYBUILD_EASYCONFIG_TEMPLATE % templates)
440+
handle.close()
441441

442442
# unset $MODULEPATH, we don't care about already installed modules
443443
os.environ['MODULEPATH'] = ''
@@ -614,6 +614,13 @@ def main():
614614
moduleclass = 'tools'
615615
"""
616616

617+
# check Python version
618+
if sys.version_info[0] != 2 or sys.version_info[1] < 6:
619+
pyver = sys.version.split(' ')[0]
620+
sys.stderr.write("ERROR: Incompatible Python version: %s (should be Python 2 >= 2.6)\n" % pyver)
621+
sys.stderr.write("Please try again using 'python2 %s <prefix>'\n" % os.path.basename(__file__))
622+
sys.exit(1)
623+
617624
# distribute_setup.py script (https://pypi.python.org/pypi/distribute)
618625
#
619626
# A compressed copy of a patched distribute_setup.py (version 0.6.49), generated like so:

0 commit comments

Comments
 (0)