pyproject: add configuration for autopep8

This adds pyproject.toml, needed to configure defaults for autopep8.

The file is auto-discovered in a similar way to .clang-format, other
tools could be configured here too. For now just configure autopep8 so
this can be enabled in IDE's without causing unexpected edits such as
wrapping lines over 80 columns in width.

Now autopep8 can be used from the root directory by running: autopep8 .

This uses multiple-jobs to run autopep8 over all Python scripts except
paths that are explicitly ignored in exclude defined by pyproject.toml.

Reviewed By: mont29, brecht, sybren

Ref D14686
This commit is contained in:
Campbell Barton 2022-04-19 15:50:35 +10:00
parent 2547c3c70c
commit 30acc5f9cd
2 changed files with 59 additions and 0 deletions

View File

@ -34,6 +34,15 @@ indent_style = space
indent_size = 2
max_line_length = 99
# Tom's Obvious Minimal Language
[*.toml]
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4
max_line_length = 120
# reStructuredText
[*.rst]
charset = utf-8

50
pyproject.toml Normal file
View File

@ -0,0 +1,50 @@
# SPDX-License-Identifier: GPL-2.0-or-later
[tool.autopep8]
# Configuratuion for `autopep8`, allowing the command: autopep8 .
# to reformat all source files.
#
# NOTE: the settings defined here map directly to commmand line arguments
# which will override these settings when passed in to autopep8.
max_line_length = 120
ignore = [
# Info: Use `isinstance()` instead of comparing types directly.
# Why disable? Changes code logic, in rare cases we want to compare exact types.
"E721",
# Info: Fix bare except.
# Why disable? Disruptive, leave our exceptions alone.
"E722",
# Info: Fix module level import not at top of file.
# Why disable? Re-ordering imports is disruptive and breaks some scripts
# that need to check if a module has already been loaded in the case of reloading.
"E402",
# Info: Fix various deprecated code (via lib2to3)
# Why disable? Does nothing besides incorrectly adding a duplicate import,
# could be reported as a bug except this is likely to be removed soon, see:
# https://github.com/python/cpython/issues/84540.
"W690",
]
# Exclude:
# - `./extern/` because it's maintained separately.
# - `./release/scripts/addons*` & `./source/tools/` because they are external repositories
# which can contain their own configuration and be handled separately.
# - `./release/scripts/modules/rna_manual_reference.py` because it's a generated data-file.
exclude = """
./extern/*,
./release/scripts/addons/*,
./release/scripts/addons_contrib/*,
./release/scripts/modules/rna_manual_reference.py,
./source/tools/*,
"""
# Match CPU count.
jobs = 0
# Format files in-place.
in_place = true
# Format directories recursively (except for excluded paths).
recursive = true