diff --git a/easybuild/framework/easyconfig/easyconfig.py b/easybuild/framework/easyconfig/easyconfig.py index babdda2676..f5bebaee5b 100644 --- a/easybuild/framework/easyconfig/easyconfig.py +++ b/easybuild/framework/easyconfig/easyconfig.py @@ -1901,7 +1901,11 @@ def robot_find_easyconfig(name, version): res = None for path in paths: - if path in _path_indexes: + + if build_option('ignore_index'): + _log.info("Ignoring index for %s...", path) + path_index = [] + elif path in _path_indexes: path_index = _path_indexes[path] _log.info("Found loaded index for %s", path) elif os.path.exists(path): diff --git a/easybuild/tools/config.py b/easybuild/tools/config.py index 51ff946f21..1c16245e21 100644 --- a/easybuild/tools/config.py +++ b/easybuild/tools/config.py @@ -226,6 +226,7 @@ def mk_full_default_path(name, prefix=DEFAULT_PREFIX): 'group_writable_installdir', 'hidden', 'ignore_checksums', + 'ignore_index', 'install_latest_eb_release', 'lib64_fallback_sanity_check', 'logtostdout', diff --git a/easybuild/tools/filetools.py b/easybuild/tools/filetools.py index 4645e37041..d651ab2b6b 100644 --- a/easybuild/tools/filetools.py +++ b/easybuild/tools/filetools.py @@ -770,7 +770,7 @@ def search_file(paths, query, short=False, ignore_dirs=None, silent=False, filen print_msg("Searching (case-insensitive) for '%s' in %s " % (query.pattern, path), log=_log, silent=silent) path_index = load_index(path, ignore_dirs=ignore_dirs) - if path_index is None: + if path_index is None or build_option('ignore_index'): if os.path.exists(path): _log.info("No index found for %s, creating one...", path) path_index = create_index(path, ignore_dirs=ignore_dirs) diff --git a/easybuild/tools/options.py b/easybuild/tools/options.py index 22d7299f7f..1540bb18c5 100644 --- a/easybuild/tools/options.py +++ b/easybuild/tools/options.py @@ -684,6 +684,7 @@ def easyconfig_options(self): 'create-index': ("Create index for files in specified directory", None, 'store', None), 'fix-deprecated-easyconfigs': ("Fix use of deprecated functionality in specified easyconfig files.", None, 'store_true', False), + 'ignore-index': ("Ignore index when searching for files", None, 'store_true', False), 'index-max-age': ("Maximum age for index before it is considered stale (in seconds)", int, 'store', DEFAULT_INDEX_MAX_AGE), 'inject-checksums': ("Inject checksums of specified type for sources/patches into easyconfig file(s)", diff --git a/test/framework/options.py b/test/framework/options.py index 52103c0000..3b9fc440fc 100644 --- a/test/framework/options.py +++ b/test/framework/options.py @@ -776,6 +776,49 @@ def test_search(self): args = [opt, pattern, '--robot', test_easyconfigs_dir] self.assertErrorRegex(EasyBuildError, "Invalid search query", self.eb_main, args, raise_error=True) + def test_ignore_index(self): + """ + Test use of --ignore-index. + """ + + test_ecs_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs') + toy_ec = os.path.join(test_ecs_dir, 'test_ecs', 't', 'toy', 'toy-0.0.eb') + copy_file(toy_ec, self.test_prefix) + + # install index that list more files than are actually available, + # so we can check whether it's used + index_txt = '\n'.join([ + 'toy-0.0.eb', + 'toy-1.2.3.eb', + 'toy-4.5.6.eb', + ]) + write_file(os.path.join(self.test_prefix, '.eb-path-index'), index_txt) + + args = [ + '--search=toy', + '--robot-paths=%s' % self.test_prefix, + ] + self.mock_stdout(True) + self.eb_main(args, testing=False, raise_error=True) + stdout = self.get_stdout() + self.mock_stdout(False) + + for toy_ec_fn in ['toy-0.0.eb', 'toy-1.2.3.eb', 'toy-4.5.6.eb']: + regex = re.compile(re.escape(os.path.join(self.test_prefix, toy_ec_fn)), re.M) + self.assertTrue(regex.search(stdout), "Pattern '%s' should be found in: %s" % (regex.pattern, stdout)) + + args.append('--ignore-index') + self.mock_stdout(True) + self.eb_main(args, testing=False, raise_error=True) + stdout = self.get_stdout() + self.mock_stdout(False) + + regex = re.compile(re.escape(os.path.join(self.test_prefix, 'toy-0.0.eb')), re.M) + self.assertTrue(regex.search(stdout), "Pattern '%s' should be found in: %s" % (regex.pattern, stdout)) + for toy_ec_fn in ['toy-1.2.3.eb', 'toy-4.5.6.eb']: + regex = re.compile(re.escape(os.path.join(self.test_prefix, toy_ec_fn)), re.M) + self.assertFalse(regex.search(stdout), "Pattern '%s' should not be found in: %s" % (regex.pattern, stdout)) + def test_search_archived(self): "Test searching for archived easyconfigs" args = ['--search-filename=^intel']