Skip to content

Commit

Permalink
Match argument order between BasePlayer and PlayerLSL (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
mscheltienne authored Nov 20, 2023
1 parent 6b274b8 commit 70a76ac
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 6 additions & 13 deletions doc/changes/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`_)
6 changes: 2 additions & 4 deletions doc/resources/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ with the command:
With the arguments:

* ``file`` (mandatory): :term:`file-like <python:file object>`, 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
------------
Expand Down
30 changes: 7 additions & 23 deletions mne_lsl/commands/mne_lsl_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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()
3 changes: 1 addition & 2 deletions mne_lsl/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions mne_lsl/player/player_lsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand All @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions mne_lsl/player/tests/test_player_lsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions mne_lsl/stream/tests/test_stream_lsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 70a76ac

Please sign in to comment.