Skip to content

Replace sys.stderr.write() with print(file=sys.stderr) #1131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions shiny/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/pytest/asyncio_prevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)