autopep8_format_paths: replace environment variable with argument

This commit is contained in:
Campbell Barton
2022-04-28 20:26:20 +10:00
parent ab775cf235
commit c1586ae295

View File

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