Skip to content

Commit 8d0fa3d

Browse files
committed
the built-in code execution system now uses PATH to locate executables under Windows (closes #41)
1 parent 0786ead commit 8d0fa3d

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## v0.5.0 (dev)
44

5+
* The built-in code execution system now uses PATH to locate executables under
6+
Windows. Previously PATH was ignored under Windows due to the
7+
implementation details of Python's `subprocess.Popen()` (#41).
58
* Added support for Pandoc command-line options `-C` and `--citeproc` (#42).
69
* `rich_output` formats with a `text/*` mime type can now be displayed `raw`,
710
`verbatim`, or `verbatim_or_empty`. For example,

codebraid/codeprocessors/base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import locale
1818
import pathlib
1919
import pkgutil
20+
import platform
2021
import queue
2122
import re
2223
import subprocess
@@ -642,6 +643,14 @@ def _subproc_default(self, *, session, stdin, stage, stage_num, stage_tot_num, c
642643
# backslashes will require extra escaping.
643644
args = shlex.split(cmd)
644645
failed_proc_stderr = 'COMMAND FAILED (missing program or file):\n {0}'.format(cmd).encode('utf8')
646+
if platform.system() == 'Windows':
647+
# Modify args since subprocess.Popen() ignores PATH
648+
# * https://bugs.python.org/issue15451
649+
# * https://bugs.python.org/issue8557
650+
executable = shutil.which(args[0])
651+
if executable is None:
652+
return FailedProcess(args, stdout=b'', stderr=failed_proc_stderr)
653+
args[0] = executable
645654
if stdin is None:
646655
stdin_bytes_or_none = None
647656
else:
@@ -669,6 +678,14 @@ def _subproc_live_output(self, *, session, stdin, stage, stage_num, stage_tot_nu
669678
raise err.CodebraidError('"live_output" is currently not compatible with running a process that requires STDIN')
670679
args = shlex.split(cmd)
671680
failed_proc_stderr = 'COMMAND FAILED (missing program or file):\n {0}'.format(cmd).encode('utf8')
681+
if platform.system() == 'Windows':
682+
# Modify args since subprocess.Popen() ignores PATH
683+
# * https://bugs.python.org/issue15451
684+
# * https://bugs.python.org/issue8557
685+
executable = shutil.which(args[0])
686+
if executable is None:
687+
return FailedProcess(args, stdout=b'', stderr=failed_proc_stderr)
688+
args[0] = executable
672689
# Queue of bytes from stdout and stderr, plus string delims
673690
print_queue = queue.Queue()
674691
hash_bytes = session.hash[:64].encode('utf8')

codebraid/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# -*- coding: utf-8 -*-
22

33
from .fmtversion import get_version_plus_info
4-
__version__, __version_info__ = get_version_plus_info(0, 5, 0, 'dev', 14)
4+
__version__, __version_info__ = get_version_plus_info(0, 5, 0, 'dev', 15)

0 commit comments

Comments
 (0)