Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_ec(ecfile, short_modname, mod_subdir, modpath_exts, user_modpath_exts, init_modpaths):
"""Test whether active module naming scheme returns expected values."""
ec = EasyConfig(os.path.join(ecs_dir, ecfile))
self.assertEqual(ActiveMNS().det_full_module_name(ec), os.path.join(mod_subdir, short_modname))
self.assertEqual(ActiveMNS().det_short_module_name(ec), short_modname)
self.assertEqual(ActiveMNS().det_module_subdir(ec), mod_subdir)
self.assertEqual(ActiveMNS().det_modpath_extensions(ec), modpath_exts)
self.assertEqual(ActiveMNS().det_user_modpath_extensions(ec), user_modpath_exts)
self.assertEqual(ActiveMNS().det_init_modulepaths(ec), init_modpaths)
ec[key] = 'foo'
self.assertErrorRegex(EasyBuildError, error_regex, foo, key)
else:
# only deprecation warning, but key is replaced when getting/setting
ec[key] = 'test123'
self.assertEqual(ec[newkey], 'test123')
self.assertEqual(ec[key], 'test123')
ec[newkey] = '123test'
self.assertEqual(ec[newkey], '123test')
self.assertEqual(ec[key], '123test')
easyconfig.parser.DEPRECATED_PARAMETERS = orig_deprecated_parameters
reload(easyconfig.parser)
easyconfig.easyconfig.EasyConfig = orig_EasyConfig
easyconfig.easyconfig.ActiveMNS = orig_ActiveMNS
('gzip/1.6-gompi-1.4.10', 'gzip', True),
('OpenMPI/1.6.4-GCC-4.7.2-no-OFED', 'OpenMPI', True),
('BLACS/1.1-gompi-1.1.0-no-OFED', 'BLACS', True),
('ScaLAPACK/1.8.0-gompi-1.1.0-no-OFED-ATLAS-3.8.4-LAPACK-3.4.0-BLACS-1.1', 'ScaLAPACK', True),
('netCDF-C++/4.2-goolf-1.4.10', 'netCDF-C++', True),
('gcc/4.7.2', 'GCC', False),
('ScaLAPACK/1.8.0-gompi-1.1.0-no-OFED-ATLAS-3.8.4-LAPACK-3.4.0-BLACS-1.1', 'BLACS', False),
('apps/blacs/1.1', 'BLACS', False),
('lib/math/BLACS-stable/1.1', 'BLACS', False),
]
for modname, softname, res in test_cases:
if res:
errormsg = "%s is recognised as a module for '%s'" % (modname, softname)
else:
errormsg = "%s is NOT recognised as a module for '%s'" % (modname, softname)
self.assertEqual(ActiveMNS().is_short_modname_for(modname, softname), res, errormsg)
def test_ec(ecfile, short_modname, mod_subdir, modpath_exts, user_modpath_exts, init_modpaths):
"""Test whether active module naming scheme returns expected values."""
ec = EasyConfig(glob.glob(os.path.join(ecs_dir, '*', '*', ecfile))[0])
self.assertEqual(ActiveMNS().det_full_module_name(ec), os.path.join(mod_subdir, short_modname))
self.assertEqual(ActiveMNS().det_short_module_name(ec), short_modname)
self.assertEqual(ActiveMNS().det_module_subdir(ec), mod_subdir)
self.assertEqual(ActiveMNS().det_modpath_extensions(ec), modpath_exts)
self.assertEqual(ActiveMNS().det_user_modpath_extensions(ec), user_modpath_exts)
self.assertEqual(ActiveMNS().det_init_modulepaths(ec), init_modpaths)
def test_ec(ecfile, short_modname, mod_subdir, modpath_exts, user_modpath_exts, init_modpaths):
"""Test whether active module naming scheme returns expected values."""
ec = EasyConfig(os.path.join(ecs_dir, ecfile))
self.assertEqual(ActiveMNS().det_full_module_name(ec), os.path.join(mod_subdir, short_modname))
self.assertEqual(ActiveMNS().det_short_module_name(ec), short_modname)
self.assertEqual(ActiveMNS().det_module_subdir(ec), mod_subdir)
self.assertEqual(ActiveMNS().det_modpath_extensions(ec), modpath_exts)
self.assertEqual(ActiveMNS().det_user_modpath_extensions(ec), user_modpath_exts)
self.assertEqual(ActiveMNS().det_init_modulepaths(ec), init_modpaths)
def test_ec(ecfile, short_modname, mod_subdir, modpath_exts, user_modpath_exts, init_modpaths):
"""Test whether active module naming scheme returns expected values."""
ec = EasyConfig(glob.glob(os.path.join(ecs_dir, '*', '*', ecfile))[0])
self.assertEqual(ActiveMNS().det_full_module_name(ec), os.path.join(mod_subdir, short_modname))
self.assertEqual(ActiveMNS().det_short_module_name(ec), short_modname)
self.assertEqual(ActiveMNS().det_module_subdir(ec), mod_subdir)
self.assertEqual(ActiveMNS().det_modpath_extensions(ec), modpath_exts)
self.assertEqual(ActiveMNS().det_user_modpath_extensions(ec), user_modpath_exts)
self.assertEqual(ActiveMNS().det_init_modulepaths(ec), init_modpaths)
def make_module_extend_modpath(self):
"""
Include prepend-path statements for extending $MODULEPATH.
"""
txt = ''
if self.cfg['include_modpath_extensions']:
modpath_exts = ActiveMNS().det_modpath_extensions(self.cfg)
self.log.debug("Including module path extensions returned by module naming scheme: %s", modpath_exts)
full_path_modpath_extensions = [os.path.join(self.installdir_mod, ext) for ext in modpath_exts]
# module path extensions must exist, otherwise loading this module file will fail
for modpath_extension in full_path_modpath_extensions:
mkdir(modpath_extension, parents=True)
txt = self.module_generator.use(full_path_modpath_extensions)
# add user-specific module path; use statement will be guarded so no need to create the directories
user_modpath = build_option('subdir_user_modules')
if user_modpath:
# If a mod_path_suffix is being used, we should respect it
mod_path_suffix = build_option('suffix_modules_path')
user_modpath = os.path.join(user_modpath, mod_path_suffix)
user_modpath_exts = ActiveMNS().det_user_modpath_extensions(self.cfg)
user_modpath_exts = [os.path.join(user_modpath, e) for e in user_modpath_exts]
self.log.debug("Including user module path extensions returned by naming scheme: %s", user_modpath_exts)
print_msg(diff_msg, log=self.log)
# invalidate relevant 'module avail'/'module show' cache entries
# consider both paths: for short module name, and subdir indicated by long module name
paths = [modpath]
if self.mod_subdir:
paths.append(os.path.join(modpath, self.mod_subdir))
for path in paths:
invalidate_module_caches_for(path)
# only update after generating final module file
if not fake:
self.modules_tool.update()
mod_symlink_paths = ActiveMNS().det_module_symlink_paths(self.cfg)
self.module_generator.create_symlinks(mod_symlink_paths, fake=fake)
if not fake:
self.make_devel_module()
if build_option('set_default_module'):
self._set_module_as_default()
return modpath
# compute checksums for all source and patch files
if not (skip_checksums or self.dry_run):
for fil in self.src + self.patches:
# report both MD5 and SHA256 checksums, since both are valid default checksum types
for checksum_type in [CHECKSUM_TYPE_MD5, CHECKSUM_TYPE_SHA256]:
fil[checksum_type] = compute_checksum(fil['path'], checksum_type=checksum_type)
self.log.info("%s checksum for %s: %s", checksum_type, fil['path'], fil[checksum_type])
# fetch extensions
if self.cfg['exts_list']:
self.exts = self.fetch_extension_sources()
# create parent dirs in install and modules path already
# this is required when building in parallel
mod_symlink_paths = ActiveMNS().det_module_symlink_paths(self.cfg)
mod_subdir = os.path.dirname(ActiveMNS().det_full_module_name(self.cfg))
pardirs = [
self.installdir,
os.path.join(self.installdir_mod, mod_subdir),
]
for mod_symlink_path in mod_symlink_paths:
pardirs.append(os.path.join(install_path('mod'), mod_symlink_path, mod_subdir))
self.log.info("Checking dirs that need to be created: %s" % pardirs)
for pardir in pardirs:
mkdir(pardir, parents=True)
def make_module_dep(self, unload_info=None):
"""
Make the dependencies for the module file.
:param unload_info: dictionary with full module names as keys and module name to unload first as corr. value
"""
mns = ActiveMNS()
unload_info = unload_info or {}
# include toolchain as first dependency to load
tc_mod = None
if self.toolchain.name != DUMMY_TOOLCHAIN_NAME:
tc_mod = self.toolchain.det_short_module_name()
self.log.debug("Toolchain to load in generated module (before excluding any deps): %s", tc_mod)
# expand toolchain into toolchain components if desired
tc_dep_mods = None
if mns.expand_toolchain_load(ec=self.cfg):
tc_dep_mods = self.toolchain.toolchain_dep_mods
self.log.debug("Toolchain components to load in generated module (before excluding any): %s", tc_dep_mods)
# include load/unload statements for dependencies
deps = []