Skip to content

Commit

Permalink
Allow to directly import EasyConfig constants from the module
Browse files Browse the repository at this point in the history
This allows e.g. `from easybuild.framework.easyconfig.constants import SYSTEM`
instead of `easyconfig.constants.EASYCONFIG_CONSTANTS['SYSTEM'][0]`
  • Loading branch information
Flamefire committed Dec 19, 2022
1 parent 04c7161 commit a447531
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions easybuild/framework/easyconfig/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ def _get_arch_constant():
'OS_PKG_PAM_DEV': (('pam-devel', 'libpam0g-dev'),
"OS packages providing Pluggable Authentication Module (PAM) developement support"),
}

# Add EasyConfig constants to export list
globals().update({name: value for name, (value, _) in EASYCONFIG_CONSTANTS.items()})
__all__ = ['EXTERNAL_MODULE_MARKER', 'EASYCONFIG_CONSTANTS'] + list(EASYCONFIG_CONSTANTS.keys())
11 changes: 11 additions & 0 deletions test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,17 @@ def test_constant_doc(self):
]
self.assertEqual(len(doc.split('\n')), sum([len(temps)] + [len(x) for x in temps]))

def test_constants_import(self):
"""Test importing constants works"""
# Sanity check that importing an EC constant works as-if using EASYCONFIG_CONSTANTS
from easybuild.framework.easyconfig.constants import SYSTEM
self.assertEqual(SYSTEM, easyconfig.constants.EASYCONFIG_CONSTANTS['SYSTEM'][0])
# Check each individual constant
constants = __import__('easybuild.framework.easyconfig.constants', fromlist=[None])
for name, (value, doc) in easyconfig.constants.EASYCONFIG_CONSTANTS.items():
self.assertTrue(hasattr(constants, name), 'Missing ' + name)
self.assertEqual(getattr(constants, name), value)

def test_build_options(self):
"""Test configure/build/install options, both strings and lists."""
orig_contents = '\n'.join([
Expand Down

0 comments on commit a447531

Please sign in to comment.