Skip to content

BUG: Fix bug with sys_info on Windows #13310

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

Merged
merged 5 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/devel/13310.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug in :func:`mne.sys_info` where calling it in Windows could lead to a an error while trying to get the amount of available memory, by `Eric Larson`_.
4 changes: 2 additions & 2 deletions mne/_fiff/meas_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ class Info(ValidatedDict, SetChannelsMixin, MontageMixin, ContainsMixin):
Helium level (%) after position correction.
orig_file_guid : str
Original file GUID.
meas_date : datetime.datetime
meas_date : datetime.datetime | None
The helium level meas date.
.. versionchanged:: 1.8
Expand Down Expand Up @@ -2884,7 +2884,7 @@ def write_meas_info(fid, info, data_type=None, reset_range=True):
write_float(fid, FIFF.FIFF_HELIUM_LEVEL, hi["helium_level"])
if hi.get("orig_file_guid") is not None:
write_string(fid, FIFF.FIFF_ORIG_FILE_GUID, hi["orig_file_guid"])
if hi["meas_date"] is not None:
if hi.get("meas_date", None) is not None:
write_int(fid, FIFF.FIFF_MEAS_DATE, _dt_to_stamp(hi["meas_date"]))
end_block(fid, FIFF.FIFFB_HELIUM)
del hi
Expand Down
13 changes: 13 additions & 0 deletions mne/_fiff/tests/test_meas_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,19 @@ def test_field_round_trip(tmp_path):
assert_object_equal(info, info_read)
with pytest.raises(TypeError, match="datetime"):
info["helium_info"]["meas_date"] = (1, 2)
# should allow it to be None, though (checking gh-13154)
info["helium_info"]["meas_date"] = None
info.save(fname, overwrite=True)
info_read = read_info(fname)
assert_object_equal(info, info_read)
assert info_read["helium_info"]["meas_date"] is None
# not 100% sure how someone could end up with it deleted, but should still be
# writeable
del info["helium_info"]["meas_date"]
info.save(fname, overwrite=True)
info_read = read_info(fname)
info["helium_info"]["meas_date"] = None # we always set it (which is reasonable)
assert_object_equal(info, info_read)


def test_equalize_channels():
Expand Down
7 changes: 6 additions & 1 deletion mne/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,12 @@ def _get_total_memory():
"(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory",
]
).decode()
total_memory = int(o)
# Can get for example a "running scripts is disabled on this system"
# error where "o" will be a long string rather than an int
try:
total_memory = int(o)
except Exception: # pragma: no cover
total_memory = 0
elif platform.system() == "Linux":
o = subprocess.check_output(["free", "-b"]).decode()
total_memory = int(o.splitlines()[1].split()[1])
Expand Down