[GRASS-git] [OSGeo/grass] 8586e5: grass.script: Always use env for shutil.which (#5717)

Vaclav Petras noreply at github.com
Thu Jun 5 13:41:40 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/OSGeo/grass
  Commit: 8586e51ba4215392ee61db84bb38a03fb9425a92
      https://github.com/OSGeo/grass/commit/8586e51ba4215392ee61db84bb38a03fb9425a92
  Author: Vaclav Petras <wenzeslaus at gmail.com>
  Date:   2025-06-05 (Thu, 05 Jun 2025)

  Changed paths:
    M python/grass/script/core.py

  Log Message:
  -----------
  grass.script: Always use env for shutil.which (#5717)

Currently, shutil.which is called on Windows to find the executable. However, it does not use the provided env (if any) which leads to the executable not being find if only the env parameter for run_command (and family) contains the runtime setup. This is not a problem on Linux (and probably unix/posix in general), because the Popen call eventually uses the system to find the executable and uses the provided env. However, on Windows, env is not used by the subprocess call. The shutil.which uses the os.environ process, so when the global environment is used, everything still works even on Windows.

This adds the PATH from env to the shutil.which call if it is there, so that it is used to find the exectuable. Additionally, this adds the shutil.which call for all platforms which is considered a best practice, avoiding Bandit's B607: Test for starting a process with a partial path.



To unsubscribe from these emails, change your notification settings at https://github.com/OSGeo/grass/settings/notifications


More information about the grass-commit mailing list