From 2c13f483bc886d5f5925eb91e1cb936d790906ab Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Thu, 15 Feb 2024 13:05:33 -0600 Subject: [PATCH 1/2] Replace sys.stderr.write() with print(file=sys.stderr) --- shiny/_main.py | 9 +++++---- tests/pytest/asyncio_prevent.py | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/shiny/_main.py b/shiny/_main.py index caf9212ba..bf61f6899 100644 --- a/shiny/_main.py +++ b/shiny/_main.py @@ -314,8 +314,9 @@ def run_app( autoreload_port = _utils.random_port(host=host) if autoreload_port == port: - sys.stderr.write( - "Autoreload port is already being used by the app; disabling autoreload\n" + print( + "Autoreload port is already being used by the app; disabling autoreload\n", + file=sys.stderr, ) reload = False else: @@ -426,10 +427,10 @@ def resolve_app(app: str, app_dir: str | None) -> tuple[str, str | None]: # unfriendly. We should probably throw a custom error that the shiny run # entrypoint knows not to print the stack trace for. if not os.path.exists(module_path): - sys.stderr.write(f"Error: {module_path} not found\n") + print(f"Error: {module_path} not found\n", file=sys.stderr) sys.exit(1) if not os.path.isfile(module_path): - sys.stderr.write(f"Error: {module_path} is not a file\n") + print(f"Error: {module_path} is not a file\n", file=sys.stderr) sys.exit(1) dirname, filename = os.path.split(module_path) module = filename[:-3] if filename.endswith(".py") else filename diff --git a/tests/pytest/asyncio_prevent.py b/tests/pytest/asyncio_prevent.py index 56baf064e..ca5ea36c6 100644 --- a/tests/pytest/asyncio_prevent.py +++ b/tests/pytest/asyncio_prevent.py @@ -33,7 +33,8 @@ def new_event_loop(self): # Doing this instead of "import shiny" so no linter is tempted to remove it importlib.import_module("shiny") - sys.stderr.write( + print( "Success; shiny module loading did not attempt to access an asyncio event " - "loop\n" + "loop\n", + file=sys.stderr, ) From faf550fdcdf18f2bd8e743042c0b7f3930396203 Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Thu, 15 Feb 2024 13:12:55 -0600 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f8748f92..81275deab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fixed `input_task_button` not working in a Shiny module. (#1108) * Fixed several issues with `page_navbar()` styling. (#1124) +### Other changes + +* Replaced use of `sys.stderr.write()` with `print(file=sys.stderr)`, because on some platforms `sys.stderr` can be `None`. (#1131) + + ## [0.7.1] - 2024-02-05 ### Bug fixes