From 649ef0d7c7843df5fc3fe6ff21b7a86488831c3a Mon Sep 17 00:00:00 2001 From: kramstrom Date: Fri, 12 Jul 2024 10:51:36 -0400 Subject: [PATCH] friendly error message when trying modal shell on windows --- modal/cli/run.py | 5 +++++ test/cli_test.py | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/modal/cli/run.py b/modal/cli/run.py index 64ab0f569..f4a1b53e3 100644 --- a/modal/cli/run.py +++ b/modal/cli/run.py @@ -388,6 +388,11 @@ def shell( if not console.is_terminal: raise click.UsageError("`modal shell` can only be run from a terminal.") + if sys.platform in ("cygwin", "win32"): + # sys.platform values + # https://docs.python.org/3/library/sys.html#sys.platform + raise InvalidError("`modal shell` is currently not supported on Windows") + app = App("modal shell") if func_ref is not None: diff --git a/test/cli_test.py b/test/cli_test.py index 04e08f5cd..26e316d6b 100644 --- a/test/cli_test.py +++ b/test/cli_test.py @@ -439,6 +439,19 @@ def test_shell_cmd(servicer, set_env_client, test_dir, mock_shell_pty): assert captured_out == [(1, shell_prompt), (1, expected_output)] +@pytest.mark.parametrize(("platform", "expected_exit_code"), [("win32", 1), ("cygwin", 1), ("linux", 0), ("darwin", 0)]) +def test_shell_cmd_fails_on_windows( + servicer, set_env_client, mock_shell_pty, monkeypatch, platform, expected_exit_code +): + # sys.platform values + # https://docs.python.org/3/library/sys.html#sys.platform + monkeypatch.setattr("sys.platform", platform) + res = _run(["shell"], expected_exit_code=expected_exit_code) + + if expected_exit_code != 0: + assert re.search("Windows", str(res.exception)), "exception message does not match expected string" + + def test_app_descriptions(servicer, server_url_env, test_dir): app_file = test_dir / "supports" / "app_run_tests" / "prints_desc_app.py" _run(["run", "--detach", app_file.as_posix() + "::foo"])