From 05943b25385336c97dd93d7bb2f1afb860a9866f Mon Sep 17 00:00:00 2001 From: Noa Ette Date: Fri, 20 Jun 2025 12:06:49 +0200 Subject: [PATCH 1/3] Add support for XDG_CONFIG_HOME on macos --- qutebrowser/utils/standarddir.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/qutebrowser/utils/standarddir.py b/qutebrowser/utils/standarddir.py index b82845a96..1eb884675 100644 --- a/qutebrowser/utils/standarddir.py +++ b/qutebrowser/utils/standarddir.py @@ -38,6 +38,7 @@ class _Location(enum.Enum): APPNAME = 'qutebrowser' +CONFIG_LOCATIONS = [os.path.join(os.path.normpath(os.getenv('XDG_CONFIG_HOME', '~/.config')), APPNAME), '~/.' + APPNAME] class EmptyValueError(Exception): @@ -82,7 +83,7 @@ def _init_config(args: Optional[argparse.Namespace]) -> None: if utils.is_mac: path = _from_args(typ, args) if path is None: # pragma: no branch - path = os.path.expanduser('~/.' + APPNAME) + path = _get_config_location() _create(path) _locations[_Location.config] = path @@ -93,6 +94,17 @@ def _init_config(args: Optional[argparse.Namespace]) -> None: _locations[_Location.config_py] = config_py_file +def _get_config_location() -> str: + """Get the optimal location for the config directory on disk. + + Searches CONFIG_LOCATIONS in order for existing config folder, defaults to + CONFIG_LOCATIONS[0] + """ + it = (p for p in CONFIG_LOCATIONS if p is not None and os.path.exists(os.path.expanduser(p))) + path = next(it, CONFIG_LOCATIONS[0]) + return os.path.expanduser(path) + + def config(auto: bool = False) -> str: """Get the location for the config directory. From 3a6ae695cf8d8aee3128f057bd6fd1d5857b6acb Mon Sep 17 00:00:00 2001 From: Noa Ette Date: Fri, 20 Jun 2025 17:46:43 +0200 Subject: [PATCH 2/3] fix standarddir tests --- qutebrowser/utils/standarddir.py | 7 ++++--- tests/unit/utils/test_standarddir.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/qutebrowser/utils/standarddir.py b/qutebrowser/utils/standarddir.py index 1eb884675..0d64452d0 100644 --- a/qutebrowser/utils/standarddir.py +++ b/qutebrowser/utils/standarddir.py @@ -38,7 +38,7 @@ class _Location(enum.Enum): APPNAME = 'qutebrowser' -CONFIG_LOCATIONS = [os.path.join(os.path.normpath(os.getenv('XDG_CONFIG_HOME', '~/.config')), APPNAME), '~/.' + APPNAME] +CONFIG_LOCATIONS = [os.path.normpath(os.getenv('XDG_CONFIG_HOME', '~/.config')) + '/', '~/.'] class EmptyValueError(Exception): @@ -100,8 +100,9 @@ def _get_config_location() -> str: Searches CONFIG_LOCATIONS in order for existing config folder, defaults to CONFIG_LOCATIONS[0] """ - it = (p for p in CONFIG_LOCATIONS if p is not None and os.path.exists(os.path.expanduser(p))) - path = next(it, CONFIG_LOCATIONS[0]) + it = (p + APPNAME for p in CONFIG_LOCATIONS if + os.path.exists(os.path.expanduser(p + APPNAME))) + path = next(it, CONFIG_LOCATIONS[0] + APPNAME) return os.path.expanduser(path) diff --git a/tests/unit/utils/test_standarddir.py b/tests/unit/utils/test_standarddir.py index 96bcbcf4c..1fe265f84 100644 --- a/tests/unit/utils/test_standarddir.py +++ b/tests/unit/utils/test_standarddir.py @@ -74,7 +74,7 @@ def test_unset_organization_no_qapp(monkeypatch): @pytest.mark.posix def test_fake_mac_config(tmp_path, fake_home_envvar): """Test standardir.config on a fake Mac.""" - expected = str(tmp_path) + '/.qute_test' # always with / + expected = str(tmp_path) + '/.config/qute_testii' # always with / standarddir._init_config(args=None) assert standarddir.config() == expected @@ -220,7 +220,7 @@ class TestStandardDir: (standarddir.data, 2, ['Application Support', APPNAME]), (lambda: standarddir.config(auto=True), 1, [APPNAME]), (standarddir.config, 0, - os.path.expanduser('~').split(os.sep) + ['.qute_test']), + os.path.expanduser('~').split(os.sep) + ['.config'] + ['qute_test']), (standarddir.cache, 2, ['Caches', APPNAME]), (standarddir.download, 1, ['Downloads']), ]) From a9a4af2b6335adc4288de0d77a1ed222de1a322a Mon Sep 17 00:00:00 2001 From: Noa Ette Date: Sat, 21 Jun 2025 20:24:00 +0200 Subject: [PATCH 3/3] fix: typo --- tests/unit/utils/test_standarddir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/utils/test_standarddir.py b/tests/unit/utils/test_standarddir.py index 1fe265f84..d21ecc808 100644 --- a/tests/unit/utils/test_standarddir.py +++ b/tests/unit/utils/test_standarddir.py @@ -74,7 +74,7 @@ def test_unset_organization_no_qapp(monkeypatch): @pytest.mark.posix def test_fake_mac_config(tmp_path, fake_home_envvar): """Test standardir.config on a fake Mac.""" - expected = str(tmp_path) + '/.config/qute_testii' # always with / + expected = str(tmp_path) + '/.config/qute_test' # always with / standarddir._init_config(args=None) assert standarddir.config() == expected