Skip to content

grass.script: Always use env for shutil.which #5717

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions python/grass/script/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,18 @@ def _escape_for_shell(arg):
return arg

def __init__(self, args, **kwargs):
# If env is provided and is not None, use it.
path = kwargs["env"].get("PATH") if kwargs.get("env") else None
cmd = shutil.which(args[0], path=path)
if cmd is None:
raise OSError(_("Cannot find the executable {0}").format(args[0]))
args = [cmd] + args[1:]
if (
sys.platform == "win32"
and isinstance(args, list)
and not kwargs.get("shell")
and kwargs.get("executable") is None
):
cmd = shutil.which(args[0])
if cmd is None:
raise OSError(_("Cannot find the executable {0}").format(args[0]))
args = [cmd] + args[1:]
name, ext = os.path.splitext(cmd)
if ext.lower() not in self._builtin_exts:
kwargs["shell"] = True
Expand Down
Loading