Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dependency_names method to EasyConfig class to get set of names of (direct) dependencies #4360

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1608,18 +1613,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 @@ -1653,6 +1655,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 @@ -1841,6 +1844,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 @@ -1869,6 +1875,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
Loading