From 70a76ac7da1d889db5b43d2544556a5bd4cb113e Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Mon, 20 Nov 2023 14:34:03 +0100 Subject: [PATCH] Match argument order between BasePlayer and PlayerLSL (#178) --- .github/workflows/pytest.yml | 2 +- doc/changes/latest.rst | 19 +++++----------- doc/resources/command_line.rst | 6 ++--- mne_lsl/commands/mne_lsl_player.py | 30 ++++++------------------- mne_lsl/conftest.py | 3 +-- mne_lsl/player/player_lsl.py | 6 ++--- mne_lsl/player/tests/test_player_lsl.py | 6 ++--- mne_lsl/stream/tests/test_stream_lsl.py | 3 +-- 8 files changed, 24 insertions(+), 51 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 58a3418e0..06bb8e82a 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -94,7 +94,7 @@ jobs: python -m pip install --progress-bar off --upgrade pip setuptools wheel python -m pip install --progress-bar off .[test] python -m pip install --progress-bar off --upgrade git+https://github.com/mne-tools/mne-python - python -m pip install --progress-bar off --upgrade --pre --only-binary :all: -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --timeout=180 numpy scipy + python -m pip install --progress-bar off --upgrade --pre --only-binary :all: -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --timeout=180 numpy scipy matplotlib - name: Display system information run: mne_lsl-sys_info --developer - name: Run pytest diff --git a/doc/changes/latest.rst b/doc/changes/latest.rst index 4356b2ca4..ab2080529 100644 --- a/doc/changes/latest.rst +++ b/doc/changes/latest.rst @@ -19,18 +19,11 @@ Version 1.1 =========== -Enhancements ------------- - -- xxx - -Bugs ----- - - Fix flaky tests on CIs (:pr:`168` by `Eric Larson`_ and `Mathieu Scheltienne`_) +- Fix setting channel unit on a :class:`~mne_lsl.lsl.StreamInfo` with integers (:pr:`168` by `Eric Larson`_ and `Mathieu Scheltienne`_) +- Add support for ``timestamp`` :class:`~numpy.ndarray` in a push operation to provide individual timestamp for every sample (:pr:`172` by `Mathieu Scheltienne`_) +- Improve type-hints, including LSL scalar types for :class:`~numpy.ndarray` (:pr:`175` by `Mathieu Scheltienne`_) +- Add support for the environment variable ``PYLSL_LIB`` to specify the path to a user-defined ``liblsl`` (:pr:`176` by `Mathieu Scheltienne`_) - Fix re-download of existing ``liblsl`` on macOS and test ``liblsl`` fetching (:pr:`176` by `Mathieu Scheltienne`_) - -API and behavior changes ------------------------- - -- xxx +- Make LSL utilities module private (:pr:`177` by `Mathieu Scheltienne`_) +- Match argument order between ``BasePlayer`` and :class:`~mne_lsl.player.PlayerLSL` (:pr:`178` by `Mathieu Scheltienne`_) diff --git a/doc/resources/command_line.rst b/doc/resources/command_line.rst index f48969e55..17dc904b0 100644 --- a/doc/resources/command_line.rst +++ b/doc/resources/command_line.rst @@ -20,12 +20,10 @@ with the command: With the arguments: * ``file`` (mandatory): :term:`file-like `, file to stream. -* ``-type``, ``--type`` (optional, default ``lsl``): type of stream to mock, among - (``lsl``,) -* ``-n``, ``--name`` (optional, default ``MNE-LSL-Player``): :class:`str`, name of the - LSL stream. * ``-c``, ``--chunk_size`` (optional, default ``16``): :class:`int`, number of samples pushed at once. +* ``-n``, ``--name`` (optional, default ``MNE-LSL-Player``): :class:`str`, name of the + LSL stream. StreamViewer ------------ diff --git a/mne_lsl/commands/mne_lsl_player.py b/mne_lsl/commands/mne_lsl_player.py index 29f8513d9..db2b8c1ea 100644 --- a/mne_lsl/commands/mne_lsl_player.py +++ b/mne_lsl/commands/mne_lsl_player.py @@ -15,11 +15,12 @@ def run(): help="path to the File to stream via LSL.", ) parser.add_argument( - "-t", - "--type", - type=str, - help="type of mock stream (supported: lsl).", - default="lsl", + "-c", + "--chunk_size", + type=int, + metavar="int", + help="number of samples pushed at once via LSL.", + default=16, ) parser.add_argument( "-n", @@ -29,25 +30,8 @@ def run(): help="name of the stream displayed by LSL.", default="MNE-LSL-Player", ) - parser.add_argument( - "-c", - "--chunk_size", - type=int, - metavar="int", - help="number of samples pushed at once via LSL.", - default=16, - ) - args = parser.parse_args() - - if args.type.lower().strip() == "lsl": - player = PlayerLSL(args.fname, args.name, args.chunk_size) - else: - raise ValueError( - "Argument 'type' could not be interpreted as a known player. " - f"Supported values are (lsl,). '{args.type}' is invalid." - ) - + player = PlayerLSL(args.fname, args.chunk_size, args.name) player.start() input(">> Press ENTER to stop replaying data \n") player.stop() diff --git a/mne_lsl/conftest.py b/mne_lsl/conftest.py index 43553ba3d..353a511d1 100644 --- a/mne_lsl/conftest.py +++ b/mne_lsl/conftest.py @@ -114,6 +114,5 @@ def mock_lsl_stream(fname, request): # nest the PlayerLSL import to first write the temporary LSL configuration file from mne_lsl.player import PlayerLSL # noqa: E402 - name = f"P_{request.node.name}" - with PlayerLSL(fname, name) as player: + with PlayerLSL(fname, name=f"P_{request.node.name}") as player: yield player diff --git a/mne_lsl/player/player_lsl.py b/mne_lsl/player/player_lsl.py index 6f5cde58b..1a14cb9a4 100644 --- a/mne_lsl/player/player_lsl.py +++ b/mne_lsl/player/player_lsl.py @@ -24,12 +24,12 @@ class PlayerLSL(BasePlayer): fname : path-like Path to the file to re-play as a mock LSL stream. MNE-Python must be able to load the file with :func:`mne.io.read_raw`. - name : str | None - Name of the mock LSL stream. If ``None``, the name ``MNE-LSL-Player`` is used. chunk_size : int ``≥ 1`` Number of samples pushed at once on the :class:`~mne_lsl.lsl.StreamOutlet`. If these chunks are too small then the thread-based timing might not work properly. + name : str | None + Name of the mock LSL stream. If ``None``, the name ``MNE-LSL-Player`` is used. Notes ----- @@ -39,7 +39,7 @@ class PlayerLSL(BasePlayer): """ def __init__( - self, fname: Union[str, Path], name: Optional[str] = None, chunk_size: int = 64 + self, fname: Union[str, Path], chunk_size: int = 64, name: Optional[str] = None ) -> None: super().__init__(fname, chunk_size) check_type(name, (str, None), "name") diff --git a/mne_lsl/player/tests/test_player_lsl.py b/mne_lsl/player/tests/test_player_lsl.py index 836c56a87..7f87df715 100644 --- a/mne_lsl/player/tests/test_player_lsl.py +++ b/mne_lsl/player/tests/test_player_lsl.py @@ -21,7 +21,7 @@ def test_player(caplog, fname, raw, close_io): """Test a working and valid player.""" name = "Player-test_player" - player = Player(fname, name) + player = Player(fname, name=name) assert "OFF" in player.__repr__() streams = resolve_streams(timeout=0.1) assert len(streams) == 0 @@ -76,7 +76,7 @@ def test_player_context_manager(fname): name = "Player-test_player_context_manager" streams = resolve_streams(timeout=0.1) assert len(streams) == 0 - with Player(fname, name): + with Player(fname, name=name): streams = resolve_streams(timeout=0.1) assert len(streams) == 1 assert streams[0].name == name @@ -100,7 +100,7 @@ def test_player_invalid_arguments(fname): def test_player_stop_invalid(fname): """Test stopping a player that is not started.""" - player = Player(fname, "Player-test_stop_player_invalid") + player = Player(fname, name="Player-test_stop_player_invalid") with pytest.raises(RuntimeError, match="The player is not started"): player.stop() player.start() diff --git a/mne_lsl/stream/tests/test_stream_lsl.py b/mne_lsl/stream/tests/test_stream_lsl.py index 1f577336c..930fcd2d8 100644 --- a/mne_lsl/stream/tests/test_stream_lsl.py +++ b/mne_lsl/stream/tests/test_stream_lsl.py @@ -63,8 +63,7 @@ def _mock_lsl_stream_int(_integer_raw, request): # nest the PlayerLSL import to first write the temporary LSL configuration file from mne_lsl.player import PlayerLSL # noqa: E402 - name = f"P_{request.node.name}" - with PlayerLSL(_integer_raw, name) as player: + with PlayerLSL(_integer_raw, name=f"P_{request.node.name}") as player: yield player