Skip to content

tools/mpremote/config: Add environment-variable and .env-style config options. #17662

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

AJMansfield
Copy link
Contributor

@AJMansfield AJMansfield commented Jul 11, 2025

Summary

This PR factors out mpremote's configuration code into a separate file, and adds the ability to specify that configuration from two other sources: environment variables with the MPREMOTE_ prefix, and/or a dotenv-style configuration file called .mpremote in the user's current directory or one of its parents.

My own motivation for wanting environment-variable control here is ease of automation. In heavily-scripted and especially containerized environments, environment variables are generally easier to work with than configuration files. This will help pave the way for e.g. a future CI/CD task for running the mpremote test suite.

The dotenv configuration mechanism is another common configuration method I found while researching existing python libraries for combining and dispatching to available file-based and environment-variable-based configuration methods. I ended up not finding a tool that could process the MPREMOTE_ and MPREMOTE_CMD_ environment-variable prefixes together the way I'd have liked, but I had the dotenv-style loader working already by that point. It adds a convenient way to specify project-specific mpremote configurations to be automatically used when running mpremote in the context of that specific project.

This was inspired by discussion on #17485, and also incorporates a not-entirely-trivial rebase of #9573 to include @Josverl's fixes to the current config.py issues on Windows.

Testing

Not yet done; we're at least at "works on my machine", but I've not yet gone through testing every combinations of configuration sources across multiple applicable environments.

Part of testing this will also need to be ensuring that all available settings are tested, to make sure the testing process has been sensitive to e.g. a need to add some sort of explicit type conversion processing (to the environment-variable loading, or at the site where the relevant config item is used). Since I'll have to go through that anyway I'll also make sure all of those options have documentation.

Trade-offs and Alternatives

More opinionated philosophies like The Twelve-Factor App suggest that environment variables should be the only configuration mechanism. Some of its reasoning in favor of environment variables might be worth reading, but I don't agree with the conclusion that the current config.py mechanism ought to be dropped.

It might still be better to drop the dotenv-style, to avoid proliferating too many ways a user could get tangled in stupid "where even is the damn config file" style headaches, and avoid an obligation to maintain support for it; though I think the usability it adds outweighs that.

Copy link

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

@AJMansfield AJMansfield force-pushed the mpremote_config branch 2 times, most recently from 6e2a5da to 54da244 Compare July 11, 2025 15:30
AJMansfield and others added 5 commits July 11, 2025 11:34
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
Co-authored-by: Anson Mansfield <amansfield@mantaro.com>
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
Copy link

codecov bot commented Jul 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.44%. Comparing base (df05cae) to head (2a63934).
Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17662   +/-   ##
=======================================
  Coverage   98.44%   98.44%           
=======================================
  Files         171      171           
  Lines       22192    22192           
=======================================
  Hits        21847    21847           
  Misses        345      345           

☔ 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.

@dpgeorge dpgeorge added the tools Relates to tools/ directory in source, or other tooling label Jul 15, 2025
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.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy