Skip to content

MAINT: Modernize path handling in misc.py using pathlib#13775

Open
Akhila21-6 wants to merge 19 commits intomne-tools:mainfrom
Akhila21-6:main
Open

MAINT: Modernize path handling in misc.py using pathlib#13775
Akhila21-6 wants to merge 19 commits intomne-tools:mainfrom
Akhila21-6:main

Conversation

@Akhila21-6
Copy link

@Akhila21-6 Akhila21-6 commented Mar 22, 2026

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.

Copy link
Contributor

@scott-huberty scott-huberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

FYI just to clarify, the issue you referenced is unrelated to this PR. This is because you referenced an issue in the wrong repo: The issue about modernizing path handling that you commented on the other day (mne-tools/mne-bids#1268 (comment) ) is in the MNE-BIDS satellite package, but this PR is for the MNE-Python package.

That being said, I'm not against migrating from os.path to pathlib in this module. I've left a few suggestions. Mostly, I think that the code comments are redundant because the code intent is already very clear.

Akhila21-6 and others added 5 commits March 22, 2026 21:54
Co-authored-by: Scott Huberty <52462026+scott-huberty@users.noreply.github.com>
Co-authored-by: Scott Huberty <52462026+scott-huberty@users.noreply.github.com>
Co-authored-by: Scott Huberty <52462026+scott-huberty@users.noreply.github.com>
Co-authored-by: Scott Huberty <52462026+scott-huberty@users.noreply.github.com>
Co-authored-by: Scott Huberty <52462026+scott-huberty@users.noreply.github.com>
@Akhila21-6
Copy link
Author

Akhila21-6 commented Mar 22, 2026 via email

@scott-huberty
Copy link
Contributor

scott-huberty commented Mar 25, 2026

@Akhila21-6 1) Can you login to CircleCI with your Github Account? Also 2) please see our contributing guide for adding a changelog entry. After you do this then the remaining failing checks should run successfully.

@Akhila21-6
Copy link
Author

Hi @scott-huberty, I have authorized CircleCI with my GitHub account and added the changelog entry in doc/changes/devel/13775.maintenance.rst. Thank you for the guidance!

@@ -0,0 +1 @@
Modernize path handling in ``mne/misc.py`` using ``pathlib``, by `Akhila Thammenenwar`_.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added two changelog entries. The syntax in this file is correct but it should go in doc/changes/dev/.

Also please add your name and public profile to doc/changes/names.inc

@Akhila21-6
Copy link
Author

Hi @scott-huberty, I have synced the branch, moved the changelog to the correct dev/ folder, and fixed the syntax for my entry in names.inc. All checks are now re-running. Thank you for your patience and guidance!

@@ -0,0 +1 @@
Modernize path handling in ``mne/misc.py`` using ``pathlib``, by `Akhila Thammenenwar`_.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Modernize path handling in ``mne/misc.py`` using ``pathlib``, by `Akhila Thammenenwar`_.
Modernize path handling in ``mne/misc.py`` using ``pathlib``, by :newcontrib:`Akhila Thammenenwar`.

@scott-huberty
Copy link
Contributor

@Akhila21-6 you seem to have deleted all other entries that were previously in names.inc. Can you please revert this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants