diff --git a/build_files/windows/autopep8.cmd b/build_files/windows/autopep8.cmd new file mode 100644 index 00000000000..0d7929b3c25 --- /dev/null +++ b/build_files/windows/autopep8.cmd @@ -0,0 +1,17 @@ +if NOT EXIST %PYTHON% ( + echo python not found, required for this operation + exit /b 1 +) + +set FORMAT_PATHS=%BLENDER_DIR%\tools\utils_maintenance\autopep8_format_paths.py + +for %%a in (%PYTHON%) do ( + set PEP8_LOCATION=%%~dpa\..\lib\site-packages\autopep8.py +) + +REM Use -B to avoid writing __pycache__ in lib directory and causing update conflicts. +REM While we run with --no-subprocess a sub process is still used to get the version +REM information, so we stil have to supply a valid --autopep8-command here. +%PYTHON% -B %FORMAT_PATHS% --autopep8-command "%PEP8_LOCATION%" --no-subprocess %FORMAT_ARGS% + +:EOF diff --git a/build_files/windows/format.cmd b/build_files/windows/format.cmd index d276521d83e..8b47552d26e 100644 --- a/build_files/windows/format.cmd +++ b/build_files/windows/format.cmd @@ -27,4 +27,6 @@ set PATH=%CF_PATH%;%PATH% REM Use -B to avoid writing __pycache__ in lib directory and causing update conflicts. %PYTHON% -B %FORMAT_PATHS% %FORMAT_ARGS% +call "%~dp0\autopep8.cmd" + :EOF diff --git a/scripts/modules/bpy/utils/__init__.py b/scripts/modules/bpy/utils/__init__.py index df34316c94d..a49aef8a905 100644 --- a/scripts/modules/bpy/utils/__init__.py +++ b/scripts/modules/bpy/utils/__init__.py @@ -384,6 +384,7 @@ def script_paths_system_environment(): return [_os.path.normpath(env_system_path)] return [] + def script_paths(*, subdir=None, user_pref=True, check_all=False, use_user=True, use_system_environment=True): """ Returns a list of valid script paths. diff --git a/tools/utils_maintenance/autopep8_format_paths.py b/tools/utils_maintenance/autopep8_format_paths.py index 05ea28e0461..16de5eb2769 100755 --- a/tools/utils_maintenance/autopep8_format_paths.py +++ b/tools/utils_maintenance/autopep8_format_paths.py @@ -30,6 +30,14 @@ from typing import ( VERSION_MIN = (1, 6, 0) VERSION_MAX_RECOMMENDED = (1, 6, 0) AUTOPEP8_FORMAT_CMD = "autopep8" +AUTOPEP8_FORMAT_DEFAULT_ARGS = ( + # Operate on all directories recursively. + "--recursive", + # Update the files in-place. + "--in-place", + # Auto-detect the number of jobs to use. + "--jobs=0", +) BASE_DIR = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "..")) os.chdir(BASE_DIR) @@ -119,13 +127,9 @@ def autopep8_ensure_version(autopep8_format_cmd_argument: str) -> Optional[Tuple def autopep8_format(files: List[str]) -> bytes: cmd = [ AUTOPEP8_FORMAT_CMD, - # Operate on all directories recursively. - "--recursive", - # Update the files in-place. - "--in-place", - # Auto-detect the number of jobs to use. - "--jobs=0", - ] + files + *AUTOPEP8_FORMAT_DEFAULT_ARGS, + *files + ] # Support executing from the module directory because Blender does not distribute the command. if cmd[0].endswith(".py"): @@ -134,6 +138,15 @@ def autopep8_format(files: List[str]) -> bytes: return subprocess.check_output(cmd, stderr=subprocess.STDOUT) +def autopep8_format_no_subprocess(files: List[str]) -> None: + cmd = [ + *AUTOPEP8_FORMAT_DEFAULT_ARGS, + *files + ] + from autopep8 import main + main(argv=cmd) + + def argparse_create() -> argparse.ArgumentParser: parser = argparse.ArgumentParser( @@ -154,6 +167,17 @@ def argparse_create() -> argparse.ArgumentParser: ), required=False, ) + parser.add_argument( + "--no-subprocess", + dest="no_subprocess", + default=False, + action='store_true', + help=( + "Don't use a sub-process, load autopep8 into this instance of Python. " + "Works around 8191 argument length limit on WIN32." + ), + required=False, + ) parser.add_argument( "--autopep8-command", dest="autopep8_command", @@ -216,6 +240,10 @@ def main() -> None: if not files: return + if args.no_subprocess: + autopep8_format_no_subprocess(files) + return + autopep8_format(files)