Skip to content

Commit

Permalink
fix determining relative paths in create_index
Browse files Browse the repository at this point in the history
  • Loading branch information
boegel committed Mar 8, 2020
1 parent 6c15075 commit b5c5b38
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions easybuild/tools/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,15 +611,15 @@ def create_index(path, ignore_dirs=None):
elif not os.path.isdir(path):
raise EasyBuildError("Specified path is not a directory: %s", path)

for (dirpath, dirnames, filenames) in os.walk(path, topdown=True):
for (dirpath, dirnames, filenames) in os.walk(path, topdown=True, followlinks=True):
for filename in filenames:
# use relative paths in index
index.add(os.path.join(dirpath[len(path) + 1:], filename))
index.add(os.path.join(os.path.relpath(dirpath, path), filename))

# do not consider (certain) hidden directories
# note: we still need to consider e.g., .local !
# replace list elements using [:], so os.walk doesn't process deleted directories
# see http://stackoverflow.com/questions/13454164/os-walk-without-hidden-folders
# see https://stackoverflow.com/questions/13454164/os-walk-without-hidden-folders
dirnames[:] = [d for d in dirnames if d not in ignore_dirs]

return index
Expand Down
30 changes: 16 additions & 14 deletions test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1690,20 +1690,22 @@ def test_index_functions(self):
# load_index just returns None if there is no index in specified directory
self.assertEqual(ft.load_index(self.test_prefix), None)

# create index for test easyconfigs
index = ft.create_index(test_ecs)
self.assertEqual(len(index), 79)

expected = [
os.path.join('b', 'bzip2', 'bzip2-1.0.6-GCC-4.9.2.eb'),
os.path.join('t', 'toy', 'toy-0.0.eb'),
os.path.join('s', 'ScaLAPACK', 'ScaLAPACK-2.0.2-gompi-2018a-OpenBLAS-0.2.20.eb'),
]
for fn in expected:
self.assertTrue(fn in index)

for fp in index:
self.assertTrue(fp.endswith('.eb'))
# create index for test easyconfigs;
# test with specified path with and without trailing '/'s
for path in [test_ecs, test_ecs + '/', test_ecs + '//']:
index = ft.create_index(path)
self.assertEqual(len(index), 79)

expected = [
os.path.join('b', 'bzip2', 'bzip2-1.0.6-GCC-4.9.2.eb'),
os.path.join('t', 'toy', 'toy-0.0.eb'),
os.path.join('s', 'ScaLAPACK', 'ScaLAPACK-2.0.2-gompi-2018a-OpenBLAS-0.2.20.eb'),
]
for fn in expected:
self.assertTrue(fn in index)

for fp in index:
self.assertTrue(fp.endswith('.eb'))

# set up some files to create actual index file for
ft.copy_dir(os.path.join(test_ecs, 'g'), os.path.join(self.test_prefix, 'g'))
Expand Down
10 changes: 4 additions & 6 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,13 +785,11 @@ def test_ignore_index(self):
toy_ec = os.path.join(test_ecs_dir, 'test_ecs', 't', 'toy', 'toy-0.0.eb')
copy_file(toy_ec, self.test_prefix)

toy_ec_list = ['toy-0.0.eb', 'toy-1.2.3.eb', 'toy-4.5.6.eb']

# 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',
])
index_txt = '\n'.join(toy_ec_list)
write_file(os.path.join(self.test_prefix, '.eb-path-index'), index_txt)

args = [
Expand All @@ -803,7 +801,7 @@ def test_ignore_index(self):
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']:
for toy_ec_fn in toy_ec_list:
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))

Expand Down

0 comments on commit b5c5b38

Please sign in to comment.