From 2e2a2c4eb2ceba659ada35c6589fab808bc574f9 Mon Sep 17 00:00:00 2001 From: liincuan Date: Thu, 20 Mar 2025 22:47:55 +0800 Subject: [PATCH] Resolve conflict between lincuan:patch-1 and sccn:develop in OctaveWrapper - Adopted the eval approach from develop to ensure compatibility with Octave, as direct method calls may fail due to unsupported struct array returns. - Added file synchronization (flush and fsync) to address the timing issue noted in patch-1, ensuring pop_saveset completes writing before pop_loadset is called. - Set delete=True for temporary files to ensure automatic cleanup, avoiding file accumulation. - Retained TODO and explanatory comments for future reference. --- src/eegprep/eeglabcompat.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/eegprep/eeglabcompat.py b/src/eegprep/eeglabcompat.py index 9c5eb53..2d8527e 100644 --- a/src/eegprep/eeglabcompat.py +++ b/src/eegprep/eeglabcompat.py @@ -61,9 +61,13 @@ def wrapper(*args): break if needs_roundtrip: # passage data through a file - with tempfile.NamedTemporaryFile(delete=False, suffix='.set') as temp_file: + with tempfile.NamedTemporaryFile(delete=True, suffix='.set') as temp_file: + # Save data to the temporary file pop_saveset(args[0], temp_file.name) - # needs to use eval since returning struct arrays is not supported + # Ensure the file is fully written before proceeding + temp_file.flush() + os.fsync(temp_file.fileno()) # Force write to disk to avoid timing issues + # Needs to use eval since returning struct arrays is not supported in Octave self.engine.eval(f"EEG = pop_loadset('{temp_file.name}');", nargout=0) # TODO: marshalling of extra arguments should follow octave conventions eval_str = f"EEG = {name}(EEG{',' if args[1:] else ''}{','.join([str(a) for a in args[1:]])});" @@ -266,4 +270,4 @@ def test_eeglab_compat(): # clean_artifacts( EEG, ChannelCriterion='on' ) -# test_eeglab_compat() \ No newline at end of file +# test_eeglab_compat()