summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/mpremote/mpremote/main.py13
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)