From 3e242e661f70ee32c7a37b0f818875497b625cec Mon Sep 17 00:00:00 2001 From: David Lechner Date: Mon, 11 Aug 2025 18:51:54 -0500 Subject: [PATCH] cli: Fix piping .py file from stdin. When we fixed explicit text encoding for text files, we accidentally changed one NamedTemporaryFile to text mode. Change it back to binary mode. Fixes: https://github.com/pybricks/support/issues/2325 --- CHANGELOG.md | 3 +++ pybricksdev/cli/__init__.py | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 035716c..7d74946 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Fixed piping text files to `pybricksdev run` from stdin. + ## [2.0.0] - 2025-08-10 ### Added diff --git a/pybricksdev/cli/__init__.py b/pybricksdev/cli/__init__.py index bdc5feb..a2383c0 100644 --- a/pybricksdev/cli/__init__.py +++ b/pybricksdev/cli/__init__.py @@ -68,9 +68,7 @@ def _get_script_path(file: TextIO) -> ContextManager[PathLike]: @contextlib.contextmanager def temp_context(): try: - with NamedTemporaryFile( - suffix=".py", delete=False, encoding="utf-8" - ) as temp: + with NamedTemporaryFile("wb", suffix=".py", delete=False) as temp: temp.write(file.buffer.read()) yield temp.name