Skip to content

Commit

Permalink
handle deprecated template constants
Browse files Browse the repository at this point in the history
  • Loading branch information
jfgrimm committed Mar 27, 2024
1 parent b1271e7 commit c3172cf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
53 changes: 51 additions & 2 deletions easybuild/framework/easyconfig/format/pyheaderconfigobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from easybuild.framework.easyconfig.constants import EASYCONFIG_CONSTANTS
from easybuild.framework.easyconfig.format.format import get_format_version, EasyConfigFormat
from easybuild.framework.easyconfig.licenses import EASYCONFIG_LICENSES_DICT
from easybuild.framework.easyconfig.templates import TEMPLATE_CONSTANTS
from easybuild.framework.easyconfig.templates import DEPRECATED_TEMPLATE_CONSTANTS, TEMPLATE_CONSTANTS
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.configobj import ConfigObj
from easybuild.tools.systemtools import get_shared_lib_ext
Expand Down Expand Up @@ -86,6 +86,55 @@ def build_easyconfig_variables_dict():
return vars_dict


def handle_deprecated_constants(method):
"""Decorator to handle deprecated easyconfig template constants"""
def wrapper(self, key, *args, **kwargs):
"""Check whether any deprecated constants are used"""
deprecated = DEPRECATED_TEMPLATE_CONSTANTS
if key in deprecated:
depr_key = key
key, ver = deprecated[depr_key]
_log.deprecated(f"Easyconfig template constant '{depr_key}' is deprecated, use '{key}' instead", ver)
return method(self, key, *args, **kwargs)
return wrapper


class DeprecatedDict(dict):
"""Custom dictionary that handles deprecated easyconfig template constants gracefully"""

def __init__(self, *args, **kwargs):
self.clear()
self.update(*args, **kwargs)

@handle_deprecated_constants
def __contains__(self, key):
return super().__contains__(key)

@handle_deprecated_constants
def __delitem__(self, key):
return super().__delitem__(key)

@handle_deprecated_constants
def __getitem__(self, key):
return super().__getitem__(key)

@handle_deprecated_constants
def __setitem__(self, key, value):
return super().__setitem__(key, value)

def update(self, *args, **kwargs):
if args:
if isinstance(args[0], dict):
for key, value in args[0].items():
self.__setitem__(key, value)
else:
for key, value in args[0]:
self.__setitem__(key, value)

for key, value in kwargs.items():
self.__setitem__(key, value)


class EasyConfigFormatConfigObj(EasyConfigFormat):
"""
Extended EasyConfig format, with support for a header and sections that are actually parsed (as opposed to exec'ed).
Expand Down Expand Up @@ -176,7 +225,7 @@ def parse_header(self, header):

def parse_pyheader(self, pyheader):
"""Parse the python header, assign to docstring and cfg"""
global_vars = self.pyheader_env()
global_vars = DeprecatedDict(self.pyheader_env())
self.log.debug("pyheader initial global_vars %s", global_vars)
self.log.debug("pyheader text being exec'ed: %s", pyheader)

Expand Down
1 change: 1 addition & 0 deletions easybuild/framework/easyconfig/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
# deprecated template constants, and their replacements
DEPRECATED_TEMPLATE_CONSTANTS = {
# <old_template_constant>: (<new_template_constant>, <deprecation_version>),
'GITHUB_SOURCE': ('GITHUB_URL', '6.0'),
}

extensions = ['tar.gz', 'tar.xz', 'tar.bz2', 'tgz', 'txz', 'tbz2', 'tb2', 'gtgz', 'zip', 'tar', 'xz', 'tar.Z']
Expand Down

0 comments on commit c3172cf

Please sign in to comment.