From cfe421c67b8da11a6884392dd3e4ff49ecb7f2d9 Mon Sep 17 00:00:00 2001 From: frey-perez <160774979+frey-perez@users.noreply.github.com> Date: Fri, 30 May 2025 14:06:24 -0400 Subject: [PATCH 1/6] version argument change to is_eager. --- src/wristpy/core/cli.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/wristpy/core/cli.py b/src/wristpy/core/cli.py index c76752d5..f4dbd93f 100644 --- a/src/wristpy/core/cli.py +++ b/src/wristpy/core/cli.py @@ -54,6 +54,13 @@ class NonwearAlgorithms(str, Enum): detach = "detach" +def version_callback(version: bool): + """Check the version independently.""" + if version: + typer.echo(f"Wristpy version: {config.get_version()}") + raise typer.Exit() + + @app.command() def main( input: pathlib.Path = typer.Argument( @@ -122,18 +129,20 @@ def main( help="Determines the level of verbosity. Use -v for info, -vv for debug. " "If -vvv or more, it will be set to debug. " "Default for warning.", + callback=version_callback, ), version: bool = typer.Option( - False, "-V", "--version", help="Show the version and exit." + False, + "-V", + "--version", + help="Show the version and exit.", + callback=version_callback, + is_eager=True, ), ) -> None: """Run wristpy orchestrator with command line arguments.""" from wristpy.core import orchestrator - if version: - typer.echo(f"Wristpy version: {config.get_version()}") - raise typer.Exit() - if verbosity == 0: log_level = logging.WARNING elif verbosity == 1: From cece6b10ee8f54065d3a2eafb6a905c3415c94f5 Mon Sep 17 00:00:00 2001 From: frey-perez <160774979+frey-perez@users.noreply.github.com> Date: Mon, 9 Jun 2025 11:04:56 -0400 Subject: [PATCH 2/6] using callback to run version and exit. --- src/wristpy/core/cli.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/wristpy/core/cli.py b/src/wristpy/core/cli.py index f4dbd93f..4b9709e0 100644 --- a/src/wristpy/core/cli.py +++ b/src/wristpy/core/cli.py @@ -15,6 +15,22 @@ ) +@app.callback(invoke_without_command=True) +def version_check( + version: bool = typer.Option( + False, + "-V", + "--version", + help="Check the current version of wristpy and exist.", + is_eager=True, + ), +) -> None: + """Print current version of wristpy and exit.""" + if version: + typer.echo(f"Wristpy version: {config.get_version()}") + raise typer.Exit() + + class OutputFileType(str, Enum): """Valid output file types for saving data.""" @@ -54,13 +70,6 @@ class NonwearAlgorithms(str, Enum): detach = "detach" -def version_callback(version: bool): - """Check the version independently.""" - if version: - typer.echo(f"Wristpy version: {config.get_version()}") - raise typer.Exit() - - @app.command() def main( input: pathlib.Path = typer.Argument( @@ -129,15 +138,6 @@ def main( help="Determines the level of verbosity. Use -v for info, -vv for debug. " "If -vvv or more, it will be set to debug. " "Default for warning.", - callback=version_callback, - ), - version: bool = typer.Option( - False, - "-V", - "--version", - help="Show the version and exit.", - callback=version_callback, - is_eager=True, ), ) -> None: """Run wristpy orchestrator with command line arguments.""" From e4db66810d0b23c8184f4b3d3e3d6f4bcac0dfee Mon Sep 17 00:00:00 2001 From: frey-perez <160774979+frey-perez@users.noreply.github.com> Date: Mon, 9 Jun 2025 14:45:24 -0400 Subject: [PATCH 3/6] reverting to using callback in option. --- src/wristpy/core/cli.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/wristpy/core/cli.py b/src/wristpy/core/cli.py index 4b9709e0..b88c6cd8 100644 --- a/src/wristpy/core/cli.py +++ b/src/wristpy/core/cli.py @@ -15,22 +15,6 @@ ) -@app.callback(invoke_without_command=True) -def version_check( - version: bool = typer.Option( - False, - "-V", - "--version", - help="Check the current version of wristpy and exist.", - is_eager=True, - ), -) -> None: - """Print current version of wristpy and exit.""" - if version: - typer.echo(f"Wristpy version: {config.get_version()}") - raise typer.Exit() - - class OutputFileType(str, Enum): """Valid output file types for saving data.""" @@ -70,6 +54,13 @@ class NonwearAlgorithms(str, Enum): detach = "detach" +def version_check(version: bool) -> None: + """Print the current version of wristpy and exit.""" + if version: + typer.echo(f"Wristpy version: {config.get_version()}") + raise typer.Exit() + + @app.command() def main( input: pathlib.Path = typer.Argument( @@ -139,6 +130,14 @@ def main( "If -vvv or more, it will be set to debug. " "Default for warning.", ), + version: bool = typer.Option( + False, + "-V", + "--version", + help="Print the current version of wristpy and exit.", + is_eager=True, + callback=version_check, + ), ) -> None: """Run wristpy orchestrator with command line arguments.""" from wristpy.core import orchestrator From eac265868143595a05ea502cd45eff6563d2791b Mon Sep 17 00:00:00 2001 From: frey-perez <160774979+frey-perez@users.noreply.github.com> Date: Tue, 10 Jun 2025 14:30:58 -0400 Subject: [PATCH 4/6] testing --- tests/unit/test_cli.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index a86d916b..758a85ab 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -206,3 +206,30 @@ def test_main_verbosity( create_typer_cli_runner.invoke(cli.app, [str(sample_data_gt3x), verbosity]) assert mock_run.call_args.kwargs["verbosity"] == expected_log_level + + +def test_main_version( + create_typer_cli_runner: testing.CliRunner, +) -> None: + """Test cli version output.""" + result = create_typer_cli_runner.invoke(cli.app, ["--version"]) + + assert result.exit_code == 0 + assert "Wristpy version" in result.output + + +def test_main_version_with_options( + create_typer_cli_runner: testing.CliRunner, + sample_data_gt3x: pathlib.Path, + mocker: pytest_mock.MockerFixture, +) -> None: + """Test other arguments and options are ignored when --version is passed.""" + mock_run = mocker.patch.object(orchestrator, "run") + + result = create_typer_cli_runner.invoke( + cli.app, [str(sample_data_gt3x), "-e", "5", "--version"] + ) + + assert result.exit_code == 0 + assert "Wristpy version" in result.output + mock_run.assert_not_called From a48b1ee2ea25fb10b2a0d7b48a3e7d47634dfc84 Mon Sep 17 00:00:00 2001 From: frey-perez <160774979+frey-perez@users.noreply.github.com> Date: Tue, 10 Jun 2025 14:37:25 -0400 Subject: [PATCH 5/6] removing duplicate code. --- src/wristpy/core/cli.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/wristpy/core/cli.py b/src/wristpy/core/cli.py index d821d443..0ceba9f1 100644 --- a/src/wristpy/core/cli.py +++ b/src/wristpy/core/cli.py @@ -141,10 +141,6 @@ def main( """Run wristpy orchestrator with command line arguments.""" from wristpy.core import orchestrator - if version: - typer.echo(f"Wristpy version: {config.get_version()}") - raise typer.Exit() - log_level = logging.INFO if verbosity: log_level = logging.DEBUG From 3895c6b2d24e1db50cd0392c7c51c5db5c868e8c Mon Sep 17 00:00:00 2001 From: frey-perez <160774979+frey-perez@users.noreply.github.com> Date: Tue, 10 Jun 2025 14:55:08 -0400 Subject: [PATCH 6/6] typo. --- tests/unit/test_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index 85dc5da1..0e901bdf 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -232,4 +232,4 @@ def test_main_version_with_options( assert result.exit_code == 0 assert "Wristpy version" in result.output - mock_run.assert_not_called + mock_run.assert_not_called()