[PATCH 03/31] u_boot_pylib: Make pty optional
Simon Glass
sjg at chromium.org
Tue Apr 25 01:08:08 CEST 2023
This library is not available on Windows. Detect this and work around it
by using a normal pipe.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
scripts/make_pip.sh | 9 +++++++--
tools/u_boot_pylib/cros_subprocess.py | 28 ++++++++++++++++++++++-----
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/scripts/make_pip.sh b/scripts/make_pip.sh
index 4602dcf61c88..bcff65240ba1 100755
--- a/scripts/make_pip.sh
+++ b/scripts/make_pip.sh
@@ -91,7 +91,12 @@ find ${dest} -name __pycache__ -type f -exec rm {} \;
find ${dest} -depth -name __pycache__ -exec rmdir 112 \;
# Remove test files
-rm -rf ${dest}/*test*
+for path in ${dest}/*test*; do
+ echo ${path}
+ if ! [[ "${path}" =~ .*test_util.* ]]; then
+ rm -rf ${path}
+ fi
+done
mkdir ${dir}/tests
cd ${dir}
@@ -108,7 +113,7 @@ echo "Completed build of ${tool}"
# Use --skip-existing to work even if the version is already present
if [ -n "${upload}" ]; then
echo "Uploading from ${dir}"
- python3 -m twine upload ${repo} -u __token__ dist/*
+ python3 -m twine upload ${repo} --verbose -u __token__ dist/*
echo "Completed upload of ${tool}"
fi
diff --git a/tools/u_boot_pylib/cros_subprocess.py b/tools/u_boot_pylib/cros_subprocess.py
index cd614f38a648..35cef7333f3a 100644
--- a/tools/u_boot_pylib/cros_subprocess.py
+++ b/tools/u_boot_pylib/cros_subprocess.py
@@ -16,12 +16,18 @@ progress information and filter output in real time.
import errno
import os
-import pty
import select
import subprocess
import sys
import unittest
+try:
+ import pty
+ HAVE_PTY = True
+except:
+ # For Windows
+ HAVE_PTY = False
+
# Import these here so the caller does not need to import subprocess also.
PIPE = subprocess.PIPE
@@ -74,11 +80,17 @@ class Popen(subprocess.Popen):
stderr_pty = None
if stdout == PIPE_PTY:
- stdout_pty = pty.openpty()
- stdout = os.fdopen(stdout_pty[1])
+ if HAVE_PTY:
+ stdout_pty = pty.openpty()
+ stdout = os.fdopen(stdout_pty[1])
+ else:
+ stdout = PIPE
if stderr == PIPE_PTY:
- stderr_pty = pty.openpty()
- stderr = os.fdopen(stderr_pty[1])
+ if HAVE_PTY:
+ stderr_pty = pty.openpty()
+ stderr = os.fdopen(stderr_pty[1])
+ else:
+ stderr = PIPE
super(Popen, self).__init__(args, stdin=stdin,
stdout=stdout, stderr=stderr, shell=shell, cwd=cwd, env=env,
@@ -156,6 +168,12 @@ class Popen(subprocess.Popen):
Note also that if you set stderr to STDOUT, then stderr will be empty
and the combined output will just be the same as stdout.
"""
+ if not HAVE_PTY:
+ stdout, stderr = self.communicate(input_buf)
+ stdout = self.convert_data(stdout)
+ stderr = self.convert_data(stderr)
+ combined = self.convert_data(stdout + stderr)
+ return (stdout, stderr, combined)
read_set = []
write_set = []
--
2.40.0.634.g4ca3ef3211-goog
More information about the U-Boot
mailing list