8000 mpremote: Allow user configuration on Windows · Josverl/mpremote@8492145 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8492145

Browse files
committed
mpremote: Allow user configuration on Windows
micropython/micropython#9573 Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
1 parent 1d20ab0 commit 8492145

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

tools/mpremote/mpremote/main.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,22 @@ def load_user_config():
331331
# Create empty config object.
332332
config = __build_class__(lambda: None, "Config")()
333333
config.commands = {}
334-
335-
# Get config file name.
336-
path = os.getenv("XDG_CONFIG_HOME")
337-
if path is None:
338-
path = os.getenv("HOME")
334+
# use $XDG_CONFIG_HOME, if on Windows use $APPDATA
335+
if os.name != "nt":
336+
# Get config file name.
337+
path = os.getenv("XDG_CONFIG_HOME")
338+
if path is None:
339+
path = os.getenv("HOME")
340+
if path is None:
341+
return config
342+
path = os.path.join(path, ".config")
343+
else:
344+
path = os.getenv("HOME") or os.getenv("APPDATA")
339345
if path is None:
340346
return config
341-
path = os.path.join(path, ".config")
342347
path = os.path.join(path, _PROG)
343348
config_file = os.path.join(path, "config.py")
344-
349+
print("Loading config from: ", config_file)
345350
# Check if config file exists.
346351
if not os.path.exists(config_file):
347352
return config
@@ -351,6 +356,9 @@ def load_user_config():
351356
config_data = f.read()
352357
prev_cwd = os.getcwd()
353358
os.chdir(path)
359+
# pass in the config path so that the config file can use it
360+
config.__dict__["config_path"] = path
361+
config.__dict__["__file__"] = config_file
354362
exec(config_data, config.__dict__)
355363
os.chdir(prev_cwd)
356364

0 commit comments

Comments
 (0)
0