Skip to content
Snippets Groups Projects
Commit a6707661 authored by Campbell Barton's avatar Campbell Barton
Browse files

autopep8_format_paths: support an AUTOPEP8_BIN environment variable

This allows the makefile to pass in the path to the autopep8 in ../lib/*
parent 93a5e1a4
Branches
Tags
No related merge requests found
...@@ -33,8 +33,6 @@ def compute_paths(paths, use_default_paths): ...@@ -33,8 +33,6 @@ def compute_paths(paths, use_default_paths):
"tests", "tests",
) )
else: else:
# Filter out files, this is only done so this utility wont print that it's
# "Operating" on files that will be filtered out later on.
paths = [ paths = [
f for f in paths f for f in paths
if os.path.isfile(f) and f.endswith(extensions) if os.path.isfile(f) and f.endswith(extensions)
...@@ -58,9 +56,17 @@ def autopep8_ensure_version(): ...@@ -58,9 +56,17 @@ def autopep8_ensure_version():
global AUTOPEP8_FORMAT_CMD global AUTOPEP8_FORMAT_CMD
autopep8_format_cmd = None autopep8_format_cmd = None
version_output = None version_output = None
# TODO: search paths. # Attempt to use `AUTOPEP8_BIN` passed in from "make format"
for _ in (None,): # so the autopep8 distributed with Blender will be used.
autopep8_format_cmd = "autopep8" for is_environ in (True, False):
if is_environ:
autopep8_format_cmd = os.environ.get("AUTOPEP8_BIN", "")
if autopep8_format_cmd and os.path.exists(autopep8_format_cmd):
pass
else:
continue
else:
autopep8_format_cmd = "autopep8"
try: try:
version_output = subprocess.check_output((autopep8_format_cmd, "--version")).decode('utf-8') version_output = subprocess.check_output((autopep8_format_cmd, "--version")).decode('utf-8')
except FileNotFoundError as e: except FileNotFoundError as e:
...@@ -77,7 +83,12 @@ def autopep8_ensure_version(): ...@@ -77,7 +83,12 @@ def autopep8_ensure_version():
def autopep8_format(files): def autopep8_format(files):
cmd = [AUTOPEP8_FORMAT_CMD, "--recursive", "--in-place", "--jobs=0"] + files cmd = [*AUTOPEP8_FORMAT_CMD, "--recursive", "--in-place", "--jobs=0"] + files
# Support executing from the module directory because Blender does not distribute the command.
if cmd[0].endswith(".py"):
cmd = [sys.executable, *cmd]
return subprocess.check_output(cmd, stderr=subprocess.STDOUT) return subprocess.check_output(cmd, stderr=subprocess.STDOUT)
...@@ -86,7 +97,10 @@ def argparse_create(): ...@@ -86,7 +97,10 @@ def argparse_create():
# When --help or no args are given, print this help # When --help or no args are given, print this help
usage_text = "Format source code" usage_text = "Format source code"
epilog = "This script runs autopep8 on multiple files/directories" epilog = (
"This script runs autopep8 on multiple files/directories.\n"
"Set AUTOPEP8_BIN environment variable to define the command used to run autopep8."
)
parser = argparse.ArgumentParser(description=usage_text, epilog=epilog) parser = argparse.ArgumentParser(description=usage_text, epilog=epilog)
parser.add_argument( parser.add_argument(
"--changed-only", "--changed-only",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment