Skip to content
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
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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, does __all__.extend(list(EASYCONFIG_CONSTANTS.keys()) work too?

Just to make sure we don't overlooked adding stuff to all if additional (real) constants are added to constants.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested that and no. __all__ has a default value if it is not set (only), so at that point it is an undefined variable.

It actually isn't really required because (almost) nobody does from easyconfig.constants import * which is the only use case of __all__, everything else works without it.

17 changes: 16 additions & 1 deletion test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
from easybuild.tools.py2vs3 import OrderedDict, reload
from easybuild.tools.robot import resolve_dependencies
from easybuild.tools.systemtools import AARCH64, KNOWN_ARCH_CONSTANTS, POWER, X86_64
from easybuild.tools.systemtools import get_cpu_architecture, get_shared_lib_ext
from easybuild.tools.systemtools import get_cpu_architecture, get_shared_lib_ext, get_os_name, get_os_version

from easybuild.tools.toolchain.utilities import search_toolchain
from easybuild.tools.utilities import quote_str, quote_py_str
from test.framework.utilities import find_full_path
Expand Down Expand Up @@ -1278,6 +1279,20 @@ def test_constant_doc(self):
]
self.assertEqual(len(doc.split('\n')), sum([len(temps)] + [len(x) for x in temps]))

def test_constant_import(self):
"""Test importing EC constants works"""
from easybuild.framework.easyconfig.constants import SYSTEM, OS_NAME, OS_VERSION
self.assertEqual(SYSTEM, {'name': 'system', 'version': 'system'})
self.assertEqual(OS_NAME, get_os_name())
self.assertEqual(OS_VERSION, get_os_version())

def test_constant_import_values(self):
"""Test that importing an EC constant works as-if using EASYCONFIG_CONSTANTS"""
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