Skip to content

Commit

Permalink
add support for ignoring search index via --ignore-index
Browse files Browse the repository at this point in the history
  • Loading branch information
boegel committed Feb 29, 2020
1 parent 78b6497 commit 6c15075
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
6 changes: 5 additions & 1 deletion easybuild/framework/easyconfig/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions easybuild/tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion easybuild/tools/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions easybuild/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
43 changes: 43 additions & 0 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit 6c15075

Please sign in to comment.