From d010c99077bb28e9cbca50c2d8bbeac1e8534a50 Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Thu, 12 Sep 2024 03:30:18 +0000 Subject: [PATCH] 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']