Skip to content

Commit 3612f7b

Browse files
larsonerautofix-ci[bot]sappelhoff
authored
BUG: Fix bug with sys_info on Windows (#13310)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Stefan Appelhoff <[email protected]>
1 parent 2cc3715 commit 3612f7b

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

doc/changes/devel/13310.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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`_.

mne/_fiff/meas_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ class Info(ValidatedDict, SetChannelsMixin, MontageMixin, ContainsMixin):
14511451
Helium level (%) after position correction.
14521452
orig_file_guid : str
14531453
Original file GUID.
1454-
meas_date : datetime.datetime
1454+
meas_date : datetime.datetime | None
14551455
The helium level meas date.
14561456
14571457
.. versionchanged:: 1.8
@@ -2884,7 +2884,7 @@ def write_meas_info(fid, info, data_type=None, reset_range=True):
28842884
write_float(fid, FIFF.FIFF_HELIUM_LEVEL, hi["helium_level"])
28852885
if hi.get("orig_file_guid") is not None:
28862886
write_string(fid, FIFF.FIFF_ORIG_FILE_GUID, hi["orig_file_guid"])
2887-
if hi["meas_date"] is not None:
2887+
if hi.get("meas_date", None) is not None:
28882888
write_int(fid, FIFF.FIFF_MEAS_DATE, _dt_to_stamp(hi["meas_date"]))
28892889
end_block(fid, FIFF.FIFFB_HELIUM)
28902890
del hi

mne/_fiff/tests/test_meas_info.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,19 @@ def test_field_round_trip(tmp_path):
10011001
assert_object_equal(info, info_read)
10021002
with pytest.raises(TypeError, match="datetime"):
10031003
info["helium_info"]["meas_date"] = (1, 2)
1004+
# should allow it to be None, though (checking gh-13154)
1005+
info["helium_info"]["meas_date"] = None
1006+
info.save(fname, overwrite=True)
1007+
info_read = read_info(fname)
1008+
assert_object_equal(info, info_read)
1009+
assert info_read["helium_info"]["meas_date"] is None
1010+
# not 100% sure how someone could end up with it deleted, but should still be
1011+
# writeable
1012+
del info["helium_info"]["meas_date"]
1013+
info.save(fname, overwrite=True)
1014+
info_read = read_info(fname)
1015+
info["helium_info"]["meas_date"] = None # we always set it (which is reasonable)
1016+
assert_object_equal(info, info_read)
10041017

10051018

10061019
def test_equalize_channels():

mne/utils/config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,12 @@ def _get_total_memory():
687687
"(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory",
688688
]
689689
).decode()
690-
total_memory = int(o)
690+
# Can get for example a "running scripts is disabled on this system"
691+
# error where "o" will be a long string rather than an int
692+
try:
693+
total_memory = int(o)
694+
except Exception: # pragma: no cover
695+
total_memory = 0
691696
elif platform.system() == "Linux":
692697
o = subprocess.check_output(["free", "-b"]).decode()
693698
total_memory = int(o.splitlines()[1].split()[1])

0 commit comments

Comments
 (0)