From c1586ae29595713b597c22f6baa08d6cce423767 Mon Sep 17 00:00:00 2001
From: Campbell Barton <ideasman42@gmail.com>
Date: Thu, 28 Apr 2022 20:26:20 +1000
Subject: [PATCH] autopep8_format_paths: replace environment variable with
 argument

---
 utils_maintenance/autopep8_format_paths.py | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/utils_maintenance/autopep8_format_paths.py b/utils_maintenance/autopep8_format_paths.py
index 26e749a..100a308 100644
--- a/utils_maintenance/autopep8_format_paths.py
+++ b/utils_maintenance/autopep8_format_paths.py
@@ -52,15 +52,15 @@ def source_files_from_git(paths, changed_only):
     return [f.decode('ascii') for f in files]
 
 
-def autopep8_ensure_version():
+def autopep8_ensure_version(autopep8_format_cmd_argument):
     global AUTOPEP8_FORMAT_CMD
     autopep8_format_cmd = None
     version_output = None
     # Attempt to use `AUTOPEP8_BIN` passed in from "make format"
     # so the autopep8 distributed with Blender will be used.
-    for is_environ in (True, False):
-        if is_environ:
-            autopep8_format_cmd = os.environ.get("AUTOPEP8_BIN", "")
+    for is_default in (True, False):
+        if is_default:
+            autopep8_format_cmd = autopep8_format_cmd_argument
             if autopep8_format_cmd and os.path.exists(autopep8_format_cmd):
                 pass
             else:
@@ -119,6 +119,13 @@ def argparse_create():
         ),
         required=False,
     )
+    parser.add_argument(
+        "--autopep8-command",
+        dest="autopep8_command",
+        default="autopep8",
+        help="The command to call autopep8.",
+        required=False,
+    )
     parser.add_argument(
         "paths",
         nargs=argparse.REMAINDER,
@@ -129,7 +136,9 @@ def argparse_create():
 
 
 def main():
-    version = autopep8_ensure_version()
+    args = argparse_create().parse_args()
+
+    version = autopep8_ensure_version(args.autopep8_command)
     if version is None:
         print("Unable to detect 'autopep8 --version'")
         sys.exit(1)
@@ -147,8 +156,6 @@ def main():
             (VERSION_MAX_RECOMMENDED[0], VERSION_MAX_RECOMMENDED[1]),
         )
 
-    args = argparse_create().parse_args()
-
     use_default_paths = not (bool(args.paths) or bool(args.changed_only))
 
     paths = compute_paths(args.paths, use_default_paths)
-- 
GitLab