Skip to content

Modernize core modules: pathlib, type hints, DRY engine consolidation#13

Open
Copilot wants to merge 4 commits intomainfrom
copilot/modernize-mesofield-implementations
Open

Modernize core modules: pathlib, type hints, DRY engine consolidation#13
Copilot wants to merge 4 commits intomainfrom
copilot/modernize-mesofield-implementations

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 27, 2026

Modernize and simplify the Mesofield framework across core modules, reducing ~68 net lines while fixing several pre-existing bugs that prevented tests from running.

Modernization

  • config.pypathlib.Path: Replace all os.path usage with pathlib.Path for BIDS path generation, hardware resolution, and JSON persistence. _save_dir is now a Path internally.

  • engines.py — DRY consolidation: DevEngine now inherits from PupilEngine instead of duplicating the entire exec_sequenced_event loop (~60 lines removed). Only overrides set_config/setup_sequence/teardown_sequence to skip NIDAQ behavior.

  • Type hints (8 files): from __future__ import annotations + modern union syntax (str | None, list[str], dict[str, Any]) across __init__, __main__, base, config, hardware, protocols.

  • __init__.py: Added __all__ for explicit public API.

Bug fixes

  • base.py: Hardcoded cameras[1]/cameras[0] → safe iteration. Previously crashed with fewer than 2 cameras.
  • data/writer.py: Removed circular import of BASE_DIR from crop_enhance_mp4 (already defined locally) that caused cv2 import failure at module load.
  • __main__.py: Removed hardcoded D:\jgronemeyer\... Windows path in plot_session.
  • test_workflow.py: Fixed indentation error, invalid YAML, reference to non-existent DataSaver.writer_for, missing data.setup() call.

Example: config path handling before/after

# Before
bids = os.path.join(f"sub-{self.subject}", f"ses-{self.session}")
return os.path.abspath(os.path.join(self.save_dir, bids))

# After
return str(Path(self.save_dir) / f"sub-{self.subject}" / f"ses-{self.session}")
# Before: DevEngine duplicated ~60 lines from PupilEngine
class DevEngine(MDAEngine):
    def exec_sequenced_event(self, event): ...  # identical copy

# After
class DevEngine(PupilEngine):
    def set_config(self, cfg):
        self._config = cfg
        self.nidaq = None  # skip NIDAQ

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits February 27, 2026 20:39
Co-authored-by: Gronemeyer <46824871+Gronemeyer@users.noreply.github.com>
Co-authored-by: Gronemeyer <46824871+Gronemeyer@users.noreply.github.com>
…evel guard

Co-authored-by: Gronemeyer <46824871+Gronemeyer@users.noreply.github.com>
Copilot AI changed the title [WIP] Simplify and modernize implementations for Mesofield framework Modernize core modules: pathlib, type hints, DRY engine consolidation Feb 27, 2026
@Gronemeyer Gronemeyer marked this pull request as ready for review February 27, 2026 22:12
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