Skip to content

Commit 308e6f2

Browse files
committed
Actually emit the API stability warning
1 parent 357a0c8 commit 308e6f2

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/lmstudio/plugin/cli.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ def main(argv: Sequence[str] | None = None) -> int:
4141
parser.print_usage()
4242
print(f"ERROR: Failed to find plugin folder at {plugin_path!r}")
4343
return 1
44-
# TODO: Leave the warning enabled in the dev plugin wrapper
45-
warnings.filterwarnings(
46-
"ignore", ".*the plugin API is not yet stable", FutureWarning
47-
)
4844
log_level = logging.DEBUG if args.debug else logging.INFO
4945
logging.basicConfig(level=log_level)
5046
if sys.platform == "win32":
@@ -61,6 +57,9 @@ def main(argv: Sequence[str] | None = None) -> int:
6157
if not SetConsoleCtrlHandler(None, 0):
6258
print("Failed to enable Ctrl-C events, termination may be abrupt")
6359
if not args.dev:
60+
warnings.filterwarnings(
61+
"ignore", ".*the plugin API is not yet stable", FutureWarning
62+
)
6463
try:
6564
runner.run_plugin(plugin_path, allow_local_imports=True)
6665
except KeyboardInterrupt:

tests/test_plugin_examples.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
_start_child_process,
1818
_PLUGIN_STOP_TIMEOUT,
1919
)
20+
from lmstudio.plugin.runner import _PLUGIN_API_STABILITY_WARNING
21+
2022

2123
_THIS_DIR = Path(__file__).parent.resolve()
2224
_PLUGIN_EXAMPLES_DIR = (_THIS_DIR / "../examples/plugins").resolve()
@@ -110,7 +112,19 @@ def _plugin_case_id(plugin_path: Path) -> str:
110112
@pytest.mark.parametrize("plugin_path", _get_plugin_paths(), ids=_plugin_case_id)
111113
def test_plugin_execution(plugin_path: Path) -> None:
112114
startup_lines, shutdown_lines, stderr_lines = _exec_and_interrupt(plugin_path)
115+
# Stderr should start with the API stability warning...
116+
warning_lines = [
117+
*_PLUGIN_API_STABILITY_WARNING.splitlines(keepends=True),
118+
"\n",
119+
"warnings.warn(_PLUGIN_API_STABILITY_WARNING, FutureWarning)\n",
120+
]
121+
for warning_line in warning_lines:
122+
stderr_line = stderr_lines.pop(0)
123+
assert stderr_line.endswith(warning_line)
124+
# ... and then consist solely of logged information messages
113125
for log_line in stderr_lines:
114126
assert log_line.startswith("INFO:")
127+
# Startup should finish with the notification of how to terminate the dev plugin
115128
assert startup_lines[-1].endswith("Ctrl-C to terminate...\n")
129+
# Shutdown should finish with a graceful shutdown notice from the plugin runner
116130
assert shutdown_lines[-1] == "Plugin execution terminated by console interrupt\n"

0 commit comments

Comments
 (0)