diff options
author | Jos Verlinde <Jos_Verlinde@hotmail.com> | 2025-05-01 17:17:06 +0200 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-08-02 00:22:32 +1000 |
commit | 64b3944b0121710199d8d5958415ce71f21d67a7 (patch) | |
tree | fb188b50cb19a07b1e9906abf57076c1d89b4a0b | |
parent | 026a20da3e803328c4fc9bce66b9931d18f12c1e (diff) |
tools/mpremote: Locate config.py location across different host OSes.
Use `platformdirs.user_config_dir()` (see
https://platformdirs.readthedocs.io/en/latest/api.html#user-config-directory)
to provide portability across many different OSes and configuration styles.
Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
-rw-r--r-- | tools/mpremote/mpremote/main.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index 0aec1efad..b31186ba2 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -22,6 +22,8 @@ import os, sys, time from collections.abc import Mapping from textwrap import dedent +import platformdirs + from .commands import ( CommandError, do_connect, @@ -439,13 +441,7 @@ def load_user_config(): config.commands = {} # Get config file name. - path = os.getenv("XDG_CONFIG_HOME") - if path is None: - path = os.getenv("HOME") - if path is None: - return config - path = os.path.join(path, ".config") - path = os.path.join(path, _PROG) + path = platformdirs.user_config_dir(appname=_PROG, appauthor=False) config_file = os.path.join(path, "config.py") # Check if config file exists. @@ -457,6 +453,9 @@ def load_user_config(): config_data = f.read() prev_cwd = os.getcwd() os.chdir(path) + # Pass in the config path so that the config file can use it. + config.__dict__["config_path"] = path + config.__dict__["__file__"] = config_file exec(config_data, config.__dict__) os.chdir(prev_cwd) |