Skip to content

Commit

Permalink
Merge pull request #4360 from Flamefire/dependency_names
Browse files Browse the repository at this point in the history
add `EasyConfig.dependency_names`
  • Loading branch information
boegel authored Oct 27, 2023
2 parents bbfd3a7 + 8c9b09a commit b3bcb19
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
9 changes: 9 additions & 0 deletions easybuild/framework/easyconfig/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,15 @@ def dependencies(self, build_only=False):

return retained_deps

def dependency_names(self, build_only=False):
"""
Return a set of names of all (direct) dependencies after filtering.
Iterable builddependencies are flattened when not iterating.
:param build_only: only return build dependencies, discard others
"""
return {dep['name'] for dep in self.dependencies(build_only=build_only) if dep['name']}

def builddependencies(self):
"""
Return a flat list of the parsed build dependencies
Expand Down
19 changes: 13 additions & 6 deletions test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ def test_dependency(self):
self.assertEqual(det_full_ec_version(first), '1.1-GCC-4.6.3')
self.assertEqual(det_full_ec_version(second), '2.2-GCC-4.6.3')

self.assertEqual(eb.dependency_names(), {'first', 'second', 'foo', 'bar'})
# same tests for builddependencies
self.assertEqual(eb.dependency_names(build_only=True), {'first', 'second'})
first = eb.builddependencies()[0]
second = eb.builddependencies()[1]

Expand Down Expand Up @@ -354,6 +356,7 @@ def test_false_dep_version(self):
self.assertEqual(len(deps), 2)
self.assertEqual(deps[0]['name'], 'second_build')
self.assertEqual(deps[1]['name'], 'first')
self.assertEqual(eb.dependency_names(), {'first', 'second_build'})

# more realistic example: only filter dep for POWER
self.contents = '\n'.join([
Expand All @@ -377,12 +380,14 @@ def test_false_dep_version(self):
deps = eb.dependencies()
self.assertEqual(len(deps), 1)
self.assertEqual(deps[0]['name'], 'not_on_power')
self.assertEqual(eb.dependency_names(), {'not_on_power'})

# only power, dependency gets filtered
st.get_cpu_architecture = lambda: POWER
eb = EasyConfig(self.eb_file)
deps = eb.dependencies()
self.assertEqual(deps, [])
self.assertEqual(eb.dependency_names(), set())

def test_extra_options(self):
""" extra_options should allow other variables to be stored """
Expand Down Expand Up @@ -1636,18 +1641,15 @@ def test_filter_deps(self):
test_ecs_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'easyconfigs', 'test_ecs')
ec_file = os.path.join(test_ecs_dir, 'f', 'foss', 'foss-2018a.eb')
ec = EasyConfig(ec_file)
deps = sorted([dep['name'] for dep in ec.dependencies()])
self.assertEqual(deps, ['FFTW', 'GCC', 'OpenBLAS', 'OpenMPI', 'ScaLAPACK'])
self.assertEqual(ec.dependency_names(), {'FFTW', 'GCC', 'OpenBLAS', 'OpenMPI', 'ScaLAPACK'})

# test filtering multiple deps
init_config(build_options={'filter_deps': ['FFTW', 'ScaLAPACK']})
deps = sorted([dep['name'] for dep in ec.dependencies()])
self.assertEqual(deps, ['GCC', 'OpenBLAS', 'OpenMPI'])
self.assertEqual(ec.dependency_names(), {'GCC', 'OpenBLAS', 'OpenMPI'})

# test filtering of non-existing dep
init_config(build_options={'filter_deps': ['zlib']})
deps = sorted([dep['name'] for dep in ec.dependencies()])
self.assertEqual(deps, ['FFTW', 'GCC', 'OpenBLAS', 'OpenMPI', 'ScaLAPACK'])
self.assertEqual(ec.dependency_names(), {'FFTW', 'GCC', 'OpenBLAS', 'OpenMPI', 'ScaLAPACK'})

# test parsing of value passed to --filter-deps
opts = init_config(args=[])
Expand Down Expand Up @@ -1681,6 +1683,7 @@ def test_filter_deps(self):
init_config(build_options=build_options)
ec = EasyConfig(ec_file, validate=False)
self.assertEqual(ec.dependencies(), [])
self.assertEqual(ec.dependency_names(), set())

def test_replaced_easyconfig_parameters(self):
"""Test handling of replaced easyconfig parameters."""
Expand Down Expand Up @@ -1869,6 +1872,9 @@ def test_external_dependencies(self):
}
self.assertEqual(deps[7]['external_module_metadata'], cray_netcdf_metadata)

# External module names are omitted
self.assertEqual(ec.dependency_names(), {'intel'})

# provide file with partial metadata for some external modules;
# metadata obtained from probing modules should be added to it...
metadata = os.path.join(self.test_prefix, 'external_modules_metadata.cfg')
Expand Down Expand Up @@ -1897,6 +1903,7 @@ def test_external_dependencies(self):
deps = ec.dependencies()

self.assertEqual(len(deps), 8)
self.assertEqual(ec.dependency_names(), {'intel'})

for idx in [0, 1, 2, 6]:
self.assertEqual(deps[idx]['external_module_metadata'], {})
Expand Down

0 comments on commit b3bcb19

Please sign in to comment.