Skip to content

Commit 6861a38

Browse files
committed
fix: capture stderr in utils.call when capture_stdout is True
1 parent 5cdddb2 commit 6861a38

File tree

4 files changed

+43
-29
lines changed

4 files changed

+43
-29
lines changed

cibuildwheel/macos.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,23 +278,23 @@ def setup_python(
278278
# Apply our environment after pip is ready
279279
env = environment.as_dictionary(prev_environment=env)
280280

281+
# check what Python version we're on
282+
which_python = call("which", "python", env=env, capture_stdout=True).strip()
283+
print(which_python)
284+
if which_python != str(venv_bin_path / "python"):
285+
msg = "cibuildwheel: python available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it."
286+
raise errors.FatalError(msg)
287+
call("python", "--version", env=env)
288+
281289
# check what pip version we're on
282290
if not use_uv:
283291
assert (venv_bin_path / "pip").exists()
284-
call("which", "pip", env=env)
285-
call("pip", "--version", env=env)
286292
which_pip = call("which", "pip", env=env, capture_stdout=True).strip()
293+
print(which_pip)
287294
if which_pip != str(venv_bin_path / "pip"):
288295
msg = "cibuildwheel: pip available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert pip above it."
289296
raise errors.FatalError(msg)
290-
291-
# check what Python version we're on
292-
call("which", "python", env=env)
293-
call("python", "--version", env=env)
294-
which_python = call("which", "python", env=env, capture_stdout=True).strip()
295-
if which_python != str(venv_bin_path / "python"):
296-
msg = "cibuildwheel: python available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it."
297-
raise errors.FatalError(msg)
297+
call("pip", "--version", env=env)
298298

299299
config_is_arm64 = python_configuration.identifier.endswith("arm64")
300300
config_is_universal2 = python_configuration.identifier.endswith("universal2")

cibuildwheel/pyodide.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,22 @@ def setup_python(
136136

137137
env = environment.as_dictionary(prev_environment=env)
138138

139+
# check what Python version we're on
140+
which_python = call("which", "python", env=env, capture_stdout=True).strip()
141+
print(which_python)
142+
if which_python != str(venv_bin_path / "python"):
143+
msg = "python available on PATH doesn't match our venv instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it."
144+
raise errors.FatalError(msg)
145+
call("python", "--version", env=env)
146+
139147
# check what pip version we're on
140148
assert (venv_bin_path / "pip").exists()
141-
call("which", "pip", env=env)
142-
call("pip", "--version", env=env)
143149
which_pip = call("which", "pip", env=env, capture_stdout=True).strip()
150+
print(which_pip)
144151
if which_pip != str(venv_bin_path / "pip"):
145152
msg = "pip available on PATH doesn't match our venv instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert pip above it."
146153
raise errors.FatalError(msg)
147-
148-
# check what Python version we're on
149-
call("which", "python", env=env)
150-
call("python", "--version", env=env)
151-
which_python = call("which", "python", env=env, capture_stdout=True).strip()
152-
if which_python != str(venv_bin_path / "python"):
153-
msg = "python available on PATH doesn't match our venv instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it."
154-
raise errors.FatalError(msg)
154+
call("pip", "--version", env=env)
155155

156156
log.step("Installing build tools...")
157157
call(

cibuildwheel/util.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,27 @@ def call(
127127
args_ = [str(arg) for arg in args]
128128
# print the command executing for the logs
129129
print("+ " + " ".join(shlex.quote(a) for a in args_))
130-
kwargs: dict[str, Any] = {}
131-
if capture_stdout:
132-
kwargs["universal_newlines"] = True
133-
kwargs["stdout"] = subprocess.PIPE
134-
result = subprocess.run(args_, check=True, shell=IS_WIN, env=env, cwd=cwd, **kwargs)
130+
# workaround platform behaviour differences outlined
131+
# in https://github.com/python/cpython/issues/52803
132+
path = env.get("PATH", None) if env is not None else None
133+
args_[0] = shutil.which(args_[0], path=path) or args_[0]
134+
try:
135+
result = subprocess.run(
136+
args_,
137+
check=True,
138+
shell=IS_WIN,
139+
env=env,
140+
cwd=cwd,
141+
capture_output=capture_stdout,
142+
text=capture_stdout,
143+
)
144+
except subprocess.CalledProcessError as e:
145+
if capture_stdout:
146+
sys.stderr.write(e.stderr)
147+
raise
135148
if not capture_stdout:
136149
return None
150+
sys.stderr.write(result.stderr)
137151
return typing.cast(str, result.stdout)
138152

139153

cibuildwheel/windows.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,22 +302,22 @@ def setup_python(
302302
env = environment.as_dictionary(prev_environment=env)
303303

304304
# check what Python version we're on
305-
call("where", "python", env=env)
306-
call("python", "--version", env=env)
307-
call("python", "-c", "\"import struct; print(struct.calcsize('P') * 8)\"", env=env)
308305
where_python = call("where", "python", env=env, capture_stdout=True).splitlines()[0].strip()
306+
print(where_python)
309307
if where_python != str(venv_path / "Scripts" / "python.exe"):
310308
msg = "python available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it."
311309
raise errors.FatalError(msg)
310+
call("python", "--version", env=env)
311+
call("python", "-c", "\"import struct; print(struct.calcsize('P') * 8)\"", env=env)
312312

313313
# check what pip version we're on
314314
if not use_uv:
315315
assert (venv_path / "Scripts" / "pip.exe").exists()
316316
where_pip = call("where", "pip", env=env, capture_stdout=True).splitlines()[0].strip()
317+
print(where_pip)
317318
if where_pip.strip() != str(venv_path / "Scripts" / "pip.exe"):
318319
msg = "pip available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert pip above it."
319320
raise errors.FatalError(msg)
320-
321321
call("pip", "--version", env=env)
322322

323323
log.step("Installing build tools...")

0 commit comments

Comments
 (0)