Skip to content

mpremote: Allow user configuration on Windows #9573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Josverl
Copy link
Contributor

@Josverl Josverl commented Oct 11, 2022

Simplifies the use of mpremote's user configuration on Windows, by also considering the Windows standard environment variable APPDATA, which is the OS default for storing any user/application related file-based configuration. ( changed from USERPROFILE)

This avoids the need for a Windows user to set the HOME or XDG_CONFIG_HOME environment variable, both of which are non-standard on Windows.

Per Microsoft documentation:

The recommended location for a Windows application to store user settings is in the %APPDATA% folder. This folder is a hidden folder in the user's profile directory that is designed to store application-specific data, including user settings.

However Windows users also are used to %USERPROFILE%, which was established as a location in a previous century.
in order to adhere to both recommended usage ( $XDG_CONFIG_HOME and %APPDATA%) as well as common user practices ($HOME and %USERPROFILE%) , all variables used in a scan for a valid configuration file, and this first config file is used.

Simply stated : newer standards are preferred over the older standards, and Linux environment variables take precidence.

# ENV_VAR env_value Path_checked platform.system()
1 XDG_CONFIG_HOME $HOME/.config /home/foo/.config/mpremote Linux, Windows(MSYS32), Darwin
2 HOME /home/boo /home/foo/.config/mpremote Linux, Windows(MSYS32), Darwin
3 APPDATA C:\Users\foo\AppData\Roaming C:\Users\foo\AppData\Roaming\mpremote Windows
4 USERPROFILE C:\Users\foo C:\Users\foo\mpremote Windows

@Josverl Josverl marked this pull request as ready for review October 11, 2022 08:03
@Josverl Josverl force-pushed the mpremote-win-config branch from 43a896b to b774a7e Compare October 11, 2022 09:11
@Josverl Josverl force-pushed the mpremote-win-config branch from b774a7e to 8a54028 Compare October 11, 2022 09:39
@Josverl Josverl force-pushed the mpremote-win-config branch 3 times, most recently from dce2f76 to 0fbc081 Compare October 11, 2022 11:26
@dpgeorge dpgeorge added the tools Relates to tools/ directory in source, or other tooling label Oct 25, 2022
@Josverl Josverl force-pushed the mpremote-win-config branch 4 times, most recently from ed59b5b to bf90175 Compare November 5, 2022 20:52
@codecov-commenter
Copy link

codecov-commenter commented Nov 5, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base (ef8282c) to head (ea8fc9f).
Report is 64 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9573   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files         169      169           
  Lines       21890    21890           
=======================================
+ Hits        21571    21572    +1     
+ Misses        319      318    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Josverl Josverl force-pushed the mpremote-win-config branch from 8630963 to dcc0173 Compare March 11, 2023 21:40
@github-actions
Copy link

github-actions bot commented Mar 11, 2023

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@Josverl Josverl force-pushed the mpremote-win-config branch from dcc0173 to 7f1c380 Compare March 11, 2023 22:01
@Josverl
Copy link
Contributor Author

Josverl commented Mar 11, 2023

As this was not yet merged I made a change:

  • For *nix / Mac - leave the original logic and behaviour
  • for Windows : use %APPDATA%/mpremote/config.py

@Josverl Josverl force-pushed the mpremote-win-config branch 2 times, most recently from 4226369 to 0ae37a4 Compare March 11, 2023 22:39
Josverl added a commit to Josverl/mpremote that referenced this pull request Mar 12, 2023
micropython/micropython#9573
Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
@Josverl Josverl force-pushed the mpremote-win-config branch from 0ae37a4 to 7d51239 Compare March 12, 2023 22:18
@Josverl Josverl force-pushed the mpremote-win-config branch 2 times, most recently from b832e8b to 8dabeb8 Compare July 19, 2023 20:16
@Josverl Josverl force-pushed the mpremote-win-config branch 3 times, most recently from 3185a00 to db2a4bb Compare August 2, 2023 07:59
@Josverl Josverl requested a review from dpgeorge August 22, 2023 20:48
@Josverl Josverl force-pushed the mpremote-win-config branch from db2a4bb to 3af2879 Compare August 22, 2023 21:28
@Josverl Josverl force-pushed the mpremote-win-config branch from 3af2879 to b52cf9e Compare November 27, 2023 17:08
@Josverl
Copy link
Contributor Author

Josverl commented Nov 27, 2023

Rebased again to simplify a merge.
Apparent Errors in CI/CD seem to be grounded into errors thrown by untouched parts the repo

@Josverl Josverl force-pushed the mpremote-win-config branch from b52cf9e to 493b932 Compare April 10, 2025 22:57
@Josverl
Copy link
Contributor Author

Josverl commented Apr 10, 2025

This has been in the Que for more than a few releases now, and I would like this functionality to work on my main Windows platform .
However since the original PR I have have been using the platformdirs module in some of my own tooling to solve the question on where to store what across platforms.

I think the implementation could be much simplified , and made more consistent using this module.
But it will add an additional dependency. Is that something that can be accepted , or steered away from ?
Update:
I have heard no objections, So I went ahead and was able to update the code to just 2 lines, that could be folded into one:

    path = platformdirs.user_config_dir(appname=_PROG, appauthor=False)
    config_file = os.path.join(path, "config.py")

Josverl added 3 commits May 1, 2025 17:12
Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
Use [platformdirs.user_config_dir()](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>
Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
@Josverl Josverl force-pushed the mpremote-win-config branch from 493b932 to ea8fc9f Compare May 1, 2025 15:25
@Josverl Josverl requested a review from stinos May 1, 2025 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools Relates to tools/ directory in source, or other tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants