From 8f6b3945930b6e2fb0a231709745472ef5c428c3 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Mon, 7 Jul 2025 12:51:18 -0400 Subject: [PATCH 1/4] BUG: Fix bug with sys_info on Windows --- doc/changes/devel/bugfix.rst | 1 + mne/utils/config.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 doc/changes/devel/bugfix.rst diff --git a/doc/changes/devel/bugfix.rst b/doc/changes/devel/bugfix.rst new file mode 100644 index 00000000000..270da0ff040 --- /dev/null +++ b/doc/changes/devel/bugfix.rst @@ -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`_. diff --git a/mne/utils/config.py b/mne/utils/config.py index c2f3408b427..56b80162e61 100644 --- a/mne/utils/config.py +++ b/mne/utils/config.py @@ -687,7 +687,12 @@ def _get_total_memory(): "(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory", ] ).decode() - total_memory = int(o) + # Can get for eaxmple 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]) From 9b8d4136ef1a6a70439721913c9fdc02dd3a23a7 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 7 Jul 2025 16:55:41 +0000 Subject: [PATCH 2/4] [autofix.ci] apply automated fixes --- doc/changes/devel/{bugfix.rst => 13310.bugfix.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename doc/changes/devel/{bugfix.rst => 13310.bugfix.rst} (100%) diff --git a/doc/changes/devel/bugfix.rst b/doc/changes/devel/13310.bugfix.rst similarity index 100% rename from doc/changes/devel/bugfix.rst rename to doc/changes/devel/13310.bugfix.rst From 65160bce87806788b0ae96888eedb9a954f7e0c0 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Mon, 7 Jul 2025 15:19:41 -0400 Subject: [PATCH 3/4] FIX: Test --- mne/_fiff/meas_info.py | 4 ++-- mne/_fiff/tests/test_meas_info.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mne/_fiff/meas_info.py b/mne/_fiff/meas_info.py index c83b084d3e2..cbeccc36cab 100644 --- a/mne/_fiff/meas_info.py +++ b/mne/_fiff/meas_info.py @@ -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 @@ -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 diff --git a/mne/_fiff/tests/test_meas_info.py b/mne/_fiff/tests/test_meas_info.py index 9c71bc19491..b0150d00828 100644 --- a/mne/_fiff/tests/test_meas_info.py +++ b/mne/_fiff/tests/test_meas_info.py @@ -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(): From 0c6ffa1f777a904f960295461a9ea59a83d8e834 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Thu, 10 Jul 2025 10:48:13 -0400 Subject: [PATCH 4/4] Update mne/utils/config.py Co-authored-by: Stefan Appelhoff --- mne/utils/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/utils/config.py b/mne/utils/config.py index 56b80162e61..3500358a38c 100644 --- a/mne/utils/config.py +++ b/mne/utils/config.py @@ -687,7 +687,7 @@ def _get_total_memory(): "(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory", ] ).decode() - # Can get for eaxmple a "running scripts is disabled on this system" + # 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)