Skip to content

Phase 1: Move oct2py, psutil, and pyedflib out of the base install #374

Closed

Description

@neuromechanist

Phase 1 of #324.
Base: epic/324-pyodide-browser.
Blocks: every other phase.
Parallel with: nothing.

Why

micropip.install("eegprep") fails under Pyodide today because the base dependency set pulls C-extension packages that have no WebAssembly build.
This phase removes them from the base install.
The imports are already lazy, so no call site logic changes.

Grounding, verified against the current tree

oct2py is the dominant problem, and not for the reason the epic assumed.
It has exactly one lazy import, src/eegprep/functions/adminfunc/eeglabcompat.py:298, but its dependency tree is oct2py -> octave-kernel -> ipykernel, which drags in pyzmq (needs cffi), debugpy, psutil, and tornado.
Moving oct2py alone removes four C-extension packages from the base install.
It is also inert in a browser regardless of wheels, because there is no Octave binary to drive.

psutil is a direct dependency with no WebAssembly build.
Call sites: src/eegprep/plugins/clean_rawdata/asr_process.py:64 and :115, and src/eegprep/functions/miscfunc/misc.py:207.

pyedflib has zero imports anywhere in src/.
It is only present in pyproject.toml and uv.lock.
EDF reading already goes through mne and neo.rawio.edfrawio (src/eegprep/plugins/EEG_BIDS/raw.py:79).
See the open question below.

greenlet, reached through pybids -> sqlalchemy, is not a blocker.
uv.lock shows it guarded by a platform_machine marker listing AMD64, WIN32, aarch64, amd64, ppc64le, win32, and x86_64.
Pyodide reports wasm32, so greenlet self-excludes.
Do not restructure pybids in this phase.

Everything else in the base set is either in the Pyodide distribution (numpy, scipy, matplotlib, h5py, sympy, pandas, sqlalchemy, pyyaml, scikit-learn, threadpoolctl) or is a pure-Python wheel micropip can pull from PyPI (mne, nibabel, pybids, neo, quantities, pooch, eeglabio, python-picard).

Scope

Add extras and move dependencies out of [project].dependencies:

  • [eeglab] = oct2py. Gates the Octave path in eeglabcompat.py.
  • [sys] = psutil.
  • pyedflib: see open question.

Fix the two places where a missing extra would now break behavior rather than fail clearly:

  • asr_process.py resolves max_mem=None by calling psutil.virtual_memory().free.
    With psutil absent this raises at an unhelpful point.
    Resolve to a documented fixed default instead, once, at the top of the function, per the AGENTS.md rule on environment-dependent defaults.
    State the chosen number and its rationale in the PR.
  • misc.py:207 and eeglabcompat.py:298 must raise ImportError naming the exact extra, for example pip install eegprep[sys].
    misc.py already raises a message but it names a bare uv pip install psutil; update it to name the extra.

Keep the all extra a true superset so full installs do not regress.

Non-goals

No Pyodide harness or CI in this phase; that is phase 2.
No change to pybids, mne, or neo.
No numerical change anywhere.

Acceptance criteria

  • oct2py and psutil are removed from [project].dependencies and available as [eeglab] and [sys].
  • all includes every new extra.
  • A resolution check script asserts that every package in the resolved base requirement set is either present in the Pyodide lockfile or publishes a py3-none-any wheel.
    This is the phase gate; it is deterministic and needs no browser.
    Live micropip.install confirmation lands in phase 2.
  • Calling ASR with max_mem=None in an environment without psutil succeeds and uses the documented default.
  • misc.py and eeglabcompat.py raise ImportError naming the extra.
  • Octave-marked and psutil-dependent tests skip cleanly when the extra is absent, with no weakened assertions.
  • uv.lock regenerated; uv sync --group dev still yields a working dev environment.
  • docs/source/ install page documents every extra and says which are needed for which workflow.
  • ./pre-commit.py --changed-from origin/develop clean, uv run --no-sync ruff check ., ruff format --check ., ty check clean.
  • EEGPREP_SKIP_MATLAB=1 uv run pytest tests -m "not slow" green.

Open question for the phase agent to raise, not decide

The epic proposed a [formats] extra for pyedflib.
Nothing imports it, so the options are to delete it outright, or to keep it as an empty-purpose extra for downstream users who import pyedflib themselves.
Recommendation is deletion, since an extra that installs a package eegprep never calls is misleading.
Raise this on the issue and get a maintainer answer before finalizing; do not silently pick one.

/goal prompt

/goal Remove every WebAssembly-incompatible package from eegprep's base install by moving it behind an extra, without changing any numerical behavior or breaking full installs.

Source of truth: pyproject.toml, uv.lock, and the three verified call sites src/eegprep/functions/adminfunc/eeglabcompat.py:298, src/eegprep/plugins/clean_rawdata/asr_process.py:64 and :115, and src/eegprep/functions/miscfunc/misc.py:207. Read AGENTS.md first, especially the rules on resolving environment-dependent defaults once, failing fast on unknown inputs, and not adding compatibility shims.

Constraints: the package must keep working standalone; do not touch pybids, mne, or neo; do not add defensive try/except around impossible states; every changed line must trace to this task.

Finish line: [eeglab] and [sys] extras exist and all is a superset; the resolution check script passes for the base requirement set; ASR with max_mem=None works without psutil; missing extras raise ImportError naming the extra; install docs updated; pre-commit, ruff, ruff format, ty, and EEGPREP_SKIP_MATLAB=1 uv run pytest tests -m "not slow" all clean.

Before finalizing, post the pyedflib question on the issue and wait for a maintainer answer. Report any review finding you chose not to fix, with the reason.

Activity

  1. added
    phase
    on Sep 17, 2026
  2. neuromechanist commented on Sep 17, 2026

    @neuromechanist
    MemberAuthor

    🤖 pyedflib open question: implemented the recommended option (removed it outright from [project].dependencies; no [formats] extra added).

    Twist not covered in the original grounding: tests/test_bids_load_frombids_helpers.py imports pyedflib directly to synthesize an EDF fixture for testing the BIDS/EDF loader (src/ never imports it). Deleting it outright would have broken that test's collection. Moved it to the dev dependency group instead (test-fixture-only, same treatment as pytest itself), so it never reaches published installs, [all], or micropip.install, but uv sync --group dev still has it for running the test suite.

    Flagging as before: this is easy to reverse if you'd rather add it back as an unused [formats] extra for downstream users who import pyedflib themselves. See the PR for details: will link once opened.

  3. neuromechanist commented on Sep 17, 2026

    @neuromechanist
    MemberAuthor

    🤖 Reviewed #380 against this issue's non-goals. Two points, one resolved and one that needed a maintainer decision.

    ASR max_mem default: keeping the fixed 64 MB. Decided, but recording the evidence because the PR description understates the change.

    This issue's non-goals say "no numerical change anywhere," and the swap from a psutil-derived budget to a fixed 64 MB does change asr_process output. Measured on 64 channels of 60 s at 250 Hz, max_mem=4096 versus max_mem=64 gives a max absolute difference of 8.09 on unit-variance data and a relative Frobenius difference of 3.25e-01. The mechanism is that update_at is built per block, so the reconstruction matrix is refreshed on a grid that restarts at every block boundary; changing the memory budget changes the number of blocks and therefore the update positions.

    It is still the right call, for reasons the PR did not spell out:

    • clean_asr.py:34 already defaults to maxmem=64 and clean_asr.py:194 is the only in-package caller of asr_process, so the standard cleaning pipeline was already running at 64 and is unaffected.
    • Only direct asr_process(..., max_mem=None) calls change, and those were previously machine-dependent, which the old code's own warning text admitted was "not fully reproducible."
    • A fixed budget makes ASR reproducible across machines, which is worth more here than preserving a value that varied with free RAM.

    Callers who want the old behavior pass max_mem explicitly.

    Changelog was missing. The extras split changes what a plain install provides and the ASR default changes numerical output, so both are user-facing under the AGENTS.md rule that user-facing changes need matching docs in the same branch. Added in docs/source/changelog.rst on the branch.

    pyedflib: agreed with moving it to the dev group rather than deleting it outright. The grounding in this issue said "zero imports in src/," which was accurate but incomplete; tests/test_bids_load_frombids_helpers.py:7 imports it to write a synthetic EDF fixture. Keeping it in dev keeps it out of every published install while leaving the suite runnable, which satisfies the intent.

  4. neuromechanist commented on Sep 17, 2026

    @neuromechanist
    MemberAuthor

    🤖 Done. PR #380 merged into epic/324-pyodide-browser. Closing manually because Closes #374 only fires on merges into the default branch, not into an epic branch; the work reaches develop when epic #324 merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    phase

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions