Skip to content

Commit

Permalink
Merge pull request #362 from douglasjacobsen/detect_undefined_packages
Browse files Browse the repository at this point in the history
Detect undefined packages and print a useful error message
  • Loading branch information
rfbgo authored Dec 20, 2023
2 parents 605291f + a68a10f commit c2a6eed
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/ramble/ramble/software_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,16 @@ def _v2_setup(self):
env_packages.append(expanded_pkg)

pkgs_with_compiler = []
missing_pkgs = set()
for pkg_name in env_packages:
pkg_info = self._packages[pkg_name]
if pkg_name in self._packages:
pkg_info = self._packages[pkg_name]

if 'compiler' in pkg_info and pkg_info['compiler'] in env_packages:
pkgs_with_compiler.append((pkg_name, pkg_info['compiler']))
else:
missing_pkgs.add(pkg_name)

if 'compiler' in pkg_info and pkg_info['compiler'] in env_packages:
pkgs_with_compiler.append((pkg_name, pkg_info['compiler']))
if pkgs_with_compiler:
logger.warn(
f'Environment {final_name} contains packages and their '
Expand All @@ -223,6 +228,14 @@ def _v2_setup(self):
logger.warn(
'This might cause problems when installing the packages.'
)
if missing_pkgs:
err_msg = f'Environment {final_name} refers to the following ' \
'packages, which are not defined:\n'
for pkg_name in missing_pkgs:
err_msg += f'\t{pkg_name}\n'
err_msg += 'Please make sure all packages are defined ' \
'before using this environment.'
logger.die(err_msg)

def print_environments(self, verbosity=0):
color.cprint(rucolor.section_title('Software Stack:'))
Expand Down
29 changes: 29 additions & 0 deletions lib/ramble/ramble/test/software_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,3 +829,32 @@ def test_environment_vector_expansion_exclusion(mutable_mock_workspace_path):
assert 'basic-x86_64' in software_environments._environments.keys()
assert 'basic-x86_64_v4' not in software_environments._environments.keys()
assert 'basic-x86_64' in software_environments._environments['basic-x86_64']['packages']


def test_environment_with_missing_package_errors(mutable_mock_workspace_path, capsys):
ws_name = 'test_environment_with_missing_package_errors'
workspace('create', ws_name)

assert ws_name in workspace('list')

with ramble.workspace.read(ws_name) as ws:
spack_dict = ws.get_spack_dict()

spack_dict['packages'] = {}
spack_dict['packages']['basic'] = {
'spack_spec': '[email protected]',
}
spack_dict['environments'] = {
'basic': {
'packages': ['basic', 'undefined_package']
}
}

with pytest.raises(SystemExit):
ramble.software_environments.SoftwareEnvironments(ws)
output = capsys.readouterr()

assert 'Error: Environment basic refers to the following packages' in output
assert 'undefined_package' in output
assert 'Please make sure all packages are defined before using this environment' \
in output

0 comments on commit c2a6eed

Please sign in to comment.