MAINT: Modernize path handling in misc.py using pathlib#13775
Open
Akhila21-6 wants to merge 21 commits intomne-tools:mainfrom
Open
MAINT: Modernize path handling in misc.py using pathlib#13775Akhila21-6 wants to merge 21 commits intomne-tools:mainfrom
Akhila21-6 wants to merge 21 commits intomne-tools:mainfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference issue (if any)
This PR modernizes path handling in mne/misc.py using pathlib. (Note: A previous reference to #1268 was removed as it pertained to the mne-bids repository; however, this migration remains a beneficial standalone improvement for mne-python.)
What does this implement/fix?
This PR modernizes the file handling logic in mne/viz/misc.py by transitioning from traditional open() and os.path methods to the pathlib module.
Key Changes:
Modified parse_config and read_reject_parameters to use pathlib.Path.
Optimized file reading using Path.read_text().splitlines(), making the code more concise and Pythonic.
Ensured compatibility by wrapping fname in Path() to handle both string and path-like inputs.
Removed unused import os to keep the module clean.
Additional information
I am a GSoC 2026 applicant. I have verified these changes by running the following test suite locally on a Windows environment:
python -m pytest mne/viz/tests/test_misc.py
The tests resulted in 5 passed, 5 skipped (skips were due to missing large external datasets, but all relevant code logic tests passed). I successfully resolved local PATH and ModuleNotFoundError issues to ensure the environment was correctly configured for testing.