Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 48 additions & 33 deletions easybuild/easyblocks/m/mathematica.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"""

from easybuild.tools import LooseVersion
import glob
import os

from easybuild.easyblocks.generic.binary import Binary
Expand Down Expand Up @@ -59,8 +58,13 @@ def __init__(self, *args, **kwargs):
def configure_step(self):
"""No configuration for Mathematica."""
# ensure a license server is specified
if self.cfg['license_server'] is None:
raise EasyBuildError("No license server specified.")
# check environment variable if not set in easyconfig
if self.cfg["license_server"] is None:
self.cfg["license_server"] = os.getenv("EB_MATHEMATICA_LICENSE_SERVER")

if self.cfg["license_server"] is None:
raise EasyBuildError("No license server specified via 'license_server' easyconfig parameter or "
"$EB_MATHEMATICA_LICENSE_SERVER environment variable.")

def build_step(self):
"""No build step for Mathematica."""
Expand All @@ -72,35 +76,38 @@ def install_step(self):
# make sure $DISPLAY is not set (to avoid that installer uses GUI)
orig_display = os.environ.pop('DISPLAY', None)

install_script_glob = '%s_%s_LINUX*.sh' % (self.name, self.version)
# Starting at V13, Mathematica have renamed their install file...
if LooseVersion(self.version) >= LooseVersion("13"):
install_script_glob = '%s_%s_*LINUX*.sh' % (self.name, self.version)
if LooseVersion(self.version) >= LooseVersion("14.1"):
install_script_glob = 'Wolfram_%s_LIN.sh' % (self.version)

matches = glob.glob(install_script_glob)
if len(matches) == 1:
install_script = matches[0]
cmd = self.cfg['preinstallopts'] + './' + install_script
shortver = '.'.join(self.version.split('.')[:2])
qa_install_path = os.path.join('/usr', 'local', 'Wolfram', self.name, shortver)
if LooseVersion(self.version) >= LooseVersion("14.1"):
qa_install_path = os.path.join('/usr', 'local', 'Wolfram', 'Wolfram', shortver)
# Use install script from easyconfig sources
install_script = self.cfg.get("install_script") or self.src[0]['name']

qa = [
(r"Enter the installation directory, or press ENTER to select[\s\n]*%s:[\s\n]*>" % qa_install_path,
self.installdir),
(r"Create directory \(y/n\)\?[\s\n]*>", 'y'),
(r"Should the installer attempt to make this change \(y/n\)\?[\s\n]*>", 'n'),
(r"or press ENTER to select[\s\n]*/usr/local/bin:[\s\n]*>", os.path.join(self.installdir, "bin")),
]
no_qa = [
r"Now installing.*\n\n.*\[.*\].*",
]
run_shell_cmd(cmd, qa_patterns=qa, qa_wait_patterns=no_qa, qa_timeout=200)
if not os.path.exists(install_script):
raise EasyBuildError("Install script not found: %s", install_script)

cmd = self.cfg['preinstallopts'] + './' + install_script
shortver = '.'.join(self.version.split('.')[:2])
# Starting at V14, the product is called "Wolfram" instead of "Mathematica"
if LooseVersion(self.version) >= LooseVersion("14"):
product_name = "Wolfram"
else:
raise EasyBuildError("Failed to isolate install script using '%s': %s", install_script_glob, matches)
product_name = self.name
qa_install_path = os.path.join('/usr', 'local', 'Wolfram', product_name, shortver)
qa = [
(r"Enter the installation directory, or press ENTER to select[\s\n]*%s:[\s\n]*>" % qa_install_path,
self.installdir),
(r"Create directory \(y/n\)\?[\s\n]*>", 'y'),
(r"Should the installer attempt to make this change \(y/n\)\?[\s\n]*>", 'n'),
(r"or press ENTER to select[\s\n]*/usr/local/bin:[\s\n]*>", os.path.join(self.installdir, "bin")),
]
no_qa = [
r"Now installing.*\n\n.*\[.*\].*",
r"NOTE: Because you are not logged in with root privileges.*",
r".*rpm -Uvh.*wolframscript.*",
r".*Extracting installer.*",
r".*\|\d+%",
r".*Documentation.*Installer.*",
r"You are not logged in with root privilege.*",
r"The selected directory.*contains files.*",
]
run_shell_cmd(cmd, qa_patterns=qa, qa_wait_patterns=no_qa, qa_timeout=200)

# add license server configuration file
# some relevant documentation at http://reference.wolfram.com/mathematica/tutorial/ConfigurationFiles.html
Expand Down Expand Up @@ -146,14 +153,22 @@ def sanity_check_step(self):
'files': ['bin/math'],
'dirs': ['AddOns', 'Configuration', 'Documentation', 'Executables', 'SystemFiles'],
}
# Starting at V14, the main executable is called 'wolfram' instead of 'mathematica'
if LooseVersion(self.version) >= LooseVersion("14"):
custom_paths['files'].append('bin/wolfram')
else:
custom_paths['files'].append('bin/mathematica')

if LooseVersion(self.version) >= LooseVersion("11.3.0"):
custom_paths['files'].append('Executables/wolframscript')
elif LooseVersion(self.version) >= LooseVersion("11.0.0"):
custom_paths['files'].append('bin/wolframscript')

if LooseVersion(self.version) < LooseVersion("14.1"):
custom_commands = ['mathematica --version']
# Use appropriate executable for version check
if LooseVersion(self.version) >= LooseVersion("14"):
version_cmd = 'wolframnb --version'
else:
custom_commands = ['wolframnb --version']
version_cmd = 'mathematica --version'
custom_commands = [version_cmd]

super().sanity_check_step(custom_paths=custom_paths, custom_commands=custom_commands)