Skip to content

Unknown option: -C -- isort/python not respecting current environment PATH value when using subprocess calls #1802

@casch-at

Description

@casch-at

We have compiled a newer git version our self, and added the path to the binary to the PATH env variable, but this modified version of the PATH env gets ignored when using subprocess. After passing the current value of the PATH env variable to the subprocess call(s) the error was gone.

diff --git a/isort/settings.py b/isort/settings.py
index 67c4b793..c03c5585 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -538,7 +538,7 @@ class Config(_Config):
             return bool(_SHEBANG_RE.match(line))
 
     def _check_folder_gitignore(self, folder: str) -> Optional[Path]:
-        env = {"LANG": "C.UTF-8"}
+        env = {"LANG": "C.UTF-8", "PATH": os.getenv("PATH")}
         try:
             topfolder_result = subprocess.check_output(  # nosec # skipcq: PYL-W1510
                 ["git", "-C", folder, "rev-parse", "--show-toplevel"], encoding="utf-8", env=env

An alternative way would be to pass the full path to git as reported by shutil.which("git"). I have seen that there are more subprocess calls to git. So it maybe makes sense to store the value of shutil.which("git") somewhere and use it instead of passing the string "git" to the subprocess calls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions