mne-tools / mne-tools/mne-python
ENH: Improve API of set_config
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.5k
- Forks
- 1.6k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 100
Description
I just wanted to enable CUDA on my machine, and had to do mne.get_config to get the config keys to figure out what to set, which was a bit annoying. That is because set_config has the api:
set_config(key: str, value: str | None, home_dir: str | None = None, set_env: bool = True)
So you have to know the key we use in the config file, which is really more of an implementation detail (though it does allow use via env vars, too, which is nice), i.e., I had to do:
mne.set_config("MNE_USE_CUDA", "true")
What would have been a lot nicer would have been:
mne.set_config(use_cuda=True)
So I have the following API improvement proposal:
set_config(
key: str | None, # add =None default
value: str | None,
home_dir: str | None = None,
set_env: bool = True,
*, # ↓↓↓ new! ↓↓↓
use_cuda="-preserve-",
subjects_dir="-preserve-",
...
):
"""
Set a MNE-Python preference key in the config file and environment.
When setting values using keyword-only parameters (anything after the ``*``
in the signature):
- The special string value ``"-preserve-"`` means "do not change the existing
value (if present) unless it's changed using ``key`` and ``value`` above".
- Any keyword-only parameter set to ``None`` will be removed from the config file.
Parameters
-----------
...
use_cuda : bool | str | None
Controls CUDA availability using a bool (including string-like equivalents,
e.g., ``"false"``). Corresponds to the ``MNE_USE_CUDA`` environment
variable.
...
"""
Thoughts?
@mscheltienne somewhere in the back of my mind I think you brought up something similar recently but after a search I couldn't find anything.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the public mne.set_config and mne.get_config entry points and review how configuration keys and environment variables are currently exposed. Define the compatibility and completion criteria for keyword-only settings such as use_cuda, including preservation, removal, and existing key/value behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100