From 77909789b421eb4c186657d6298e3d860aa47b39 Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Wed, 11 Sep 2024 20:15:07 +0000 Subject: [PATCH 1/4] Reverse order for parsing files in XDG_CONFIG_DIRS https://specifications.freedesktop.org/basedir-spec/latest/ says precedence should be XDG_CONFIG_HOME > 1st entry of XDG_CONFIG_DIRS > 2nd entry ... EasyBuild had this reversed for XDG_CONFIG_DIRS Fixes #4582 --- easybuild/tools/options.py | 2 +- test/framework/config.py | 2 +- test/framework/options.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/easybuild/tools/options.py b/easybuild/tools/options.py index 8a95aa7226..4249963eda 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/xdg').split(os.pathsep) +XDG_CONFIG_DIRS = os.environ.get('XDG_CONFIG_DIRS', '/etc/xdg').split(os.pathsep)[::-1] 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') diff --git a/test/framework/config.py b/test/framework/config.py index 337c7b9b87..08a1a83355 100644 --- a/test/framework/config.py +++ b/test/framework/config.py @@ -448,7 +448,7 @@ def test_XDG_CONFIG_env_vars(self): # $XDG_CONFIG_HOME not set, multiple directories listed in $XDG_CONFIG_DIRS del os.environ['XDG_CONFIG_HOME'] # unset, so should become default - os.environ['XDG_CONFIG_DIRS'] = os.pathsep.join([dir1, dir2, dir3]) + os.environ['XDG_CONFIG_DIRS'] = os.pathsep.join([dir3, dir2, dir1]) cfg_files = [ os.path.join(dir1, 'easybuild.d', 'bar.cfg'), os.path.join(dir1, 'easybuild.d', 'foo.cfg'), diff --git a/test/framework/options.py b/test/framework/options.py index d30fa7b390..2daa053915 100644 --- a/test/framework/options.py +++ b/test/framework/options.py @@ -3542,7 +3542,7 @@ 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', 'xdg'), os.path.join(self.test_prefix, 'moaretc')] + xdg_config_dirs = [os.path.join(self.test_prefix, 'moaretc'), os.path.join(self.test_prefix, 'etc', 'xdg')] os.environ['XDG_CONFIG_DIRS'] = os.pathsep.join(xdg_config_dirs) # put various dummy cfgfiles in place @@ -3563,7 +3563,7 @@ def test_show_default_configfiles(self): logtxt = read_file(self.logfile) expected = expected_tmpl % (xdg_config_home, os.pathsep.join(xdg_config_dirs), "%s => found" % os.path.join(xdg_config_home, 'easybuild', 'config.cfg'), - '{' + ', '.join(xdg_config_dirs) + '}', + '{' + ', '.join(xdg_config_dirs[::-1]) + '}', ', '.join(cfgfiles[:-1]), 4, ', '.join(cfgfiles)) self.assertIn(expected, logtxt) From d010c99077bb28e9cbca50c2d8bbeac1e8534a50 Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Thu, 12 Sep 2024 03:30:18 +0000 Subject: [PATCH 2/4] Only change order in DEFAULT_CONFIGFILES; XDG_CONFIG_DIRS in orig order This is a little easier to understand. --- easybuild/tools/options.py | 13 +++++++++---- test/framework/options.py | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/easybuild/tools/options.py b/easybuild/tools/options.py index 4249963eda..9ce9f86ace 100644 --- a/easybuild/tools/options.py +++ b/easybuild/tools/options.py @@ -105,6 +105,7 @@ from easybuild.tools.repository.repository import avail_repositories from easybuild.tools.systemtools import DARWIN, UNKNOWN, check_python_version, get_cpu_architecture, get_cpu_family from easybuild.tools.systemtools import get_cpu_features, get_gpu_info, get_os_type, get_system_info +from easybuild.tools.utilities import flatten from easybuild.tools.version import this_is_easybuild @@ -123,8 +124,8 @@ 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/xdg').split(os.pathsep)[::-1] -DEFAULT_SYS_CFGFILES = [f for d in XDG_CONFIG_DIRS for f in sorted(glob.glob(os.path.join(d, 'easybuild.d', '*.cfg')))] +XDG_CONFIG_DIRS = os.environ.get('XDG_CONFIG_DIRS', '/etc/xdg').split(os.pathsep) +DEFAULT_SYS_CFGFILES = [[f for f in sorted(glob.glob(os.path.join(d, 'easybuild.d', '*.cfg')))] for d in XDG_CONFIG_DIRS] DEFAULT_USER_CFGFILE = os.path.join(XDG_CONFIG_HOME, 'easybuild', 'config.cfg') DEFAULT_LIST_PR_STATE = GITHUB_PR_STATE_OPEN @@ -212,7 +213,11 @@ class EasyBuildOptions(GeneralOption): VERSION = this_is_easybuild() DEFAULT_LOGLEVEL = 'INFO' - DEFAULT_CONFIGFILES = DEFAULT_SYS_CFGFILES[:] + # https://specifications.freedesktop.org/basedir-spec/latest/ + # says precedence should be + # XDG_CONFIG_HOME > 1st entry of XDG_CONFIG_DIRS > 2nd entry ... + # EasyBuild parses this list backwards, gives priority to last entry + DEFAULT_CONFIGFILES = flatten(DEFAULT_SYS_CFGFILES[::-1]) 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')): @@ -1329,7 +1334,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/xdg}', 'easybuild.d', '*.cfg'), - " -> %s => %s" % (system_cfg_glob_paths, ', '.join(DEFAULT_SYS_CFGFILES) or "(no matches)"), + " -> %s => %s" % (system_cfg_glob_paths, ', '.join(flatten(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 2daa053915..7e87b5b7fb 100644 --- a/test/framework/options.py +++ b/test/framework/options.py @@ -3563,8 +3563,8 @@ def test_show_default_configfiles(self): logtxt = read_file(self.logfile) expected = expected_tmpl % (xdg_config_home, os.pathsep.join(xdg_config_dirs), "%s => found" % os.path.join(xdg_config_home, 'easybuild', 'config.cfg'), - '{' + ', '.join(xdg_config_dirs[::-1]) + '}', - ', '.join(cfgfiles[:-1]), 4, ', '.join(cfgfiles)) + '{' + ', '.join(xdg_config_dirs) + '}', + ', '.join(cfgfiles[1:3]+[cfgfiles[0]]), 4, ', '.join(cfgfiles)) self.assertIn(expected, logtxt) del os.environ['XDG_CONFIG_DIRS'] From 9367dce0a084594dd6f0e0bed8e10500ce72297b Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Thu, 12 Sep 2024 03:36:08 +0000 Subject: [PATCH 3/4] Appease the hound --- easybuild/tools/options.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/easybuild/tools/options.py b/easybuild/tools/options.py index 9ce9f86ace..cd2045bb54 100644 --- a/easybuild/tools/options.py +++ b/easybuild/tools/options.py @@ -125,7 +125,8 @@ def terminal_supports_colors(stream): 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/xdg').split(os.pathsep) -DEFAULT_SYS_CFGFILES = [[f for f in sorted(glob.glob(os.path.join(d, 'easybuild.d', '*.cfg')))] for d in XDG_CONFIG_DIRS] +DEFAULT_SYS_CFGFILES = [[f for f in sorted(glob.glob(os.path.join(d, 'easybuild.d', '*.cfg')))] + for d in XDG_CONFIG_DIRS] DEFAULT_USER_CFGFILE = os.path.join(XDG_CONFIG_HOME, 'easybuild', 'config.cfg') DEFAULT_LIST_PR_STATE = GITHUB_PR_STATE_OPEN From 7ebbee170f804cb2f5b188690b71189cc1df843d Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Wed, 2 Oct 2024 13:08:28 +0000 Subject: [PATCH 4/4] Change --show-default-configfiles language to clarify priority E.g.: Default list of existing configuration files (5, most important last): /home/oldeman/lo/easybuild.d/bla.cfg, /home/oldeman/lo/easybuild.d/foo.cfg, /home/oldeman/hi/easybuild.d/bla.cfg, /home/oldeman/hi/easybuild.d/foo.cfg, /home/oldeman/.config/easybuild/config.cfg --- easybuild/tools/options.py | 3 ++- test/framework/options.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/easybuild/tools/options.py b/easybuild/tools/options.py index cd2045bb54..c927b841a2 100644 --- a/easybuild/tools/options.py +++ b/easybuild/tools/options.py @@ -1337,7 +1337,8 @@ def show_default_configfiles(self): "* system-level: %s" % os.path.join('${XDG_CONFIG_DIRS:-/etc/xdg}', 'easybuild.d', '*.cfg'), " -> %s => %s" % (system_cfg_glob_paths, ', '.join(flatten(DEFAULT_SYS_CFGFILES)) or "(no matches)"), '', - "Default list of existing configuration files (%d): %s" % (found_cfgfile_cnt, found_cfgfile_list), + "Default list of existing configuration files (%d, most important last):" % found_cfgfile_cnt, + found_cfgfile_list, ] return '\n'.join(lines) diff --git a/test/framework/options.py b/test/framework/options.py index 7e87b5b7fb..007986c39c 100644 --- a/test/framework/options.py +++ b/test/framework/options.py @@ -3523,7 +3523,8 @@ def test_show_default_configfiles(self): expected_tmpl += '\n'.join([ "%s", '', - "Default list of existing configuration files (%d): %s", + "Default list of existing configuration files (%d, most important last):", + "%s", ]) # put dummy cfgfile in place in $HOME (to predict last line of output which only lists *existing* files)