From 5724b91ee1209264a959ca32faf70535883a28f1 Mon Sep 17 00:00:00 2001 From: Patrice Peterson Date: Thu, 1 Aug 2024 14:57:07 +0200 Subject: [PATCH 1/3] Use XDG_CONFIG_DIRS value from XDG basedir spec The spec mandates `/etc/xdg` instead of `/etc` for the default value of `XDG_CONFIG_DIRS` [1]. [1] https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables --- easybuild/tools/options.py | 4 ++-- test/framework/options.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/easybuild/tools/options.py b/easybuild/tools/options.py index 128ff8561b..935f450782 100644 --- a/easybuild/tools/options.py +++ b/easybuild/tools/options.py @@ -123,7 +123,7 @@ def terminal_supports_colors(stream): CONFIG_ENV_VAR_PREFIX = 'EASYBUILD' XDG_CONFIG_HOME = os.environ.get('XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), ".config")) -XDG_CONFIG_DIRS = os.environ.get('XDG_CONFIG_DIRS', '/etc').split(os.pathsep) +XDG_CONFIG_DIRS = os.environ.get('XDG_CONFIG_DIRS', '/etc/xdg').split(os.pathsep) DEFAULT_SYS_CFGFILES = [f for d in XDG_CONFIG_DIRS for f in sorted(glob.glob(os.path.join(d, 'easybuild.d', '*.cfg')))] DEFAULT_USER_CFGFILE = os.path.join(XDG_CONFIG_HOME, 'easybuild', 'config.cfg') @@ -1313,7 +1313,7 @@ def show_default_configfiles(self): '', "* user-level: %s" % os.path.join('${XDG_CONFIG_HOME:-$HOME/.config}', 'easybuild', 'config.cfg'), " -> %s => %s" % (DEFAULT_USER_CFGFILE, ('not found', 'found')[os.path.exists(DEFAULT_USER_CFGFILE)]), - "* system-level: %s" % os.path.join('${XDG_CONFIG_DIRS:-/etc}', 'easybuild.d', '*.cfg'), + "* system-level: %s" % os.path.join('${XDG_CONFIG_DIRS:-/etc/xdg}', 'easybuild.d', '*.cfg'), " -> %s => %s" % (system_cfg_glob_paths, ', '.join(DEFAULT_SYS_CFGFILES) or "(no matches)"), '', "Default list of existing configuration files (%d): %s" % (found_cfgfile_cnt, found_cfgfile_list), diff --git a/test/framework/options.py b/test/framework/options.py index c9c92663e6..aba8752f69 100644 --- a/test/framework/options.py +++ b/test/framework/options.py @@ -3493,7 +3493,7 @@ def test_show_default_configfiles(self): '', "* user-level: ${XDG_CONFIG_HOME:-$HOME/.config}/easybuild/config.cfg", " -> %s", - "* system-level: ${XDG_CONFIG_DIRS:-/etc}/easybuild.d/*.cfg", + "* system-level: ${XDG_CONFIG_DIRS:-/etc/xdg}/easybuild.d/*.cfg", " -> %s/easybuild.d/*.cfg => ", ]) @@ -3508,12 +3508,12 @@ def test_show_default_configfiles(self): homecfgfile_str += " => found" else: homecfgfile_str += " => not found" - expected = expected_tmpl % ('(not set)', '(not set)', homecfgfile_str, '{/etc}') + expected = expected_tmpl % ('(not set)', '(not set)', homecfgfile_str, '{/etc/xdg}') self.assertIn(expected, logtxt) # to predict the full output, we need to take control over $HOME and $XDG_CONFIG_DIRS os.environ['HOME'] = self.test_prefix - xdg_config_dirs = os.path.join(self.test_prefix, 'etc') + xdg_config_dirs = os.path.join(self.test_prefix, 'etc', 'xdg') os.environ['XDG_CONFIG_DIRS'] = xdg_config_dirs expected_tmpl += '\n'.join([ @@ -3538,12 +3538,12 @@ def test_show_default_configfiles(self): xdg_config_home = os.path.join(self.test_prefix, 'home') os.environ['XDG_CONFIG_HOME'] = xdg_config_home - xdg_config_dirs = [os.path.join(self.test_prefix, 'etc'), os.path.join(self.test_prefix, 'moaretc')] + xdg_config_dirs = [os.path.join(self.test_prefix, 'etc', 'xdg'), os.path.join(self.test_prefix, 'moaretc')] os.environ['XDG_CONFIG_DIRS'] = os.pathsep.join(xdg_config_dirs) # put various dummy cfgfiles in place cfgfiles = [ - os.path.join(self.test_prefix, 'etc', 'easybuild.d', 'config.cfg'), + os.path.join(self.test_prefix, 'etc', 'xdg', 'easybuild.d', 'config.cfg'), os.path.join(self.test_prefix, 'moaretc', 'easybuild.d', 'bar.cfg'), os.path.join(self.test_prefix, 'moaretc', 'easybuild.d', 'foo.cfg'), os.path.join(xdg_config_home, 'easybuild', 'config.cfg'), From 29bcd1c0b122d15b6e148e4af04dd50ab87362df Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Fri, 30 Aug 2024 21:26:33 +0000 Subject: [PATCH 2/3] Add deprecation warning for /etc/easybuild.d If you don't set XDG_CONFIG_DIRS and files are present in /etc/easybuild.d we now get WARNING: Deprecated functionality, will no longer work in EasyBuild v6.0: Using /etc/easybuild.d is deprecated. Please use /etc/xdg/easybuild.d instead or add /etc to XDG_CONFIG_DIRS; see https://docs.easybuild.io/deprecated-functionality/ for more information This addresses https://github.com/easybuilders/easybuild-framework/pull/4591#issuecomment-2310276909 --- easybuild/tools/options.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/easybuild/tools/options.py b/easybuild/tools/options.py index 935f450782..4ff6300a26 100644 --- a/easybuild/tools/options.py +++ b/easybuild/tools/options.py @@ -213,6 +213,12 @@ class EasyBuildOptions(GeneralOption): DEFAULT_LOGLEVEL = 'INFO' DEFAULT_CONFIGFILES = DEFAULT_SYS_CFGFILES[:] + if 'XDG_CONFIG_DIRS' not in os.environ: + old_etc_location = os.path.join('/etc', 'easybuild.d') + if os.path.isdir(old_etc_location) and glob.glob(os.path.join(old_etc_location, '*.cfg')): + _log.deprecated(f"Using {old_etc_location} is deprecated. Please use /etc/xdg/easybuild.d " + "instead or add /etc to XDG_CONFIG_DIRS", '6.0') + if os.path.exists(DEFAULT_USER_CFGFILE): DEFAULT_CONFIGFILES.append(DEFAULT_USER_CFGFILE) From b8103e103211266f7497c3cba413012ec50acd4a Mon Sep 17 00:00:00 2001 From: Patrice Peterson Date: Wed, 4 Sep 2024 14:34:56 +0200 Subject: [PATCH 3/3] Appease hound --- easybuild/tools/options.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/easybuild/tools/options.py b/easybuild/tools/options.py index 4ff6300a26..a79c458a42 100644 --- a/easybuild/tools/options.py +++ b/easybuild/tools/options.py @@ -216,8 +216,8 @@ class EasyBuildOptions(GeneralOption): if 'XDG_CONFIG_DIRS' not in os.environ: old_etc_location = os.path.join('/etc', 'easybuild.d') if os.path.isdir(old_etc_location) and glob.glob(os.path.join(old_etc_location, '*.cfg')): - _log.deprecated(f"Using {old_etc_location} is deprecated. Please use /etc/xdg/easybuild.d " - "instead or add /etc to XDG_CONFIG_DIRS", '6.0') + _log.deprecated(f"Using {old_etc_location} is deprecated. Please use " + "/etc/xdg/easybuild.d instead or add /etc to XDG_CONFIG_DIRS", '6.0') if os.path.exists(DEFAULT_USER_CFGFILE): DEFAULT_CONFIGFILES.append(DEFAULT_USER_CFGFILE)