A command line tool (and a pre-commit hook) to automatically format haning indentation in Python function definitions to 8 spaces.
Currently, this tool is only designed to work properly after your Python files have been formatted by black or blue.
black and blue both use only 4 spaces as haning indentation in function definitions, which is not aligned with PEP8's recommendation.
Therefore, this tool specifically fixes this 4-space style choice of black and blue.
pip install format-def-indentTo auto-format Python files (.py):
format-def-indent <PATH_THAT_CONTAINS_PYTHON_FILES>Use --help to see documentations of command line arguments.
To auto-format Jupyter notebooks (.ipynb):
format-def-indent-in-jupyter <PATH_THAT_CONTAINS_PYTHON_FILES>To auto-format Python files (.py), put the following into your .pre-commit-config.yaml file. Remember to replace <VERSION> with your version of this tool (such as v0.1.4):
- repo: https://github.com/cyyc1/py-def-indent-formatter
rev: <VERSION>
hooks:
- id: format-def-indentTo auto-format Jupyter notebooks (.ipynb), put the following into your .pre-commit-config.yaml file:
- repo: https://github.com/cyyc1/py-def-indent-formatter
rev: <VERSION>
hooks:
- id: format-def-indent-in-jupyterSee pre-commit for more instructions.
This tool formats the following "before" (red) into "after" (green).
def some_function(
- arg1,
- arg2='test',
- *,
- arg3: int = 2,
- arg4: bool = False,
+ arg1,
+ arg2='test',
+ *,
+ arg3: int = 2,
+ arg4: bool = False,
) -> None:
print(1)or
def some_functions(
- arg1,
- *args,
- **kwargs,
+ arg1,
+ *args,
+ **kwargs,
):
print(1)def some_function(
- arg1, arg2='test', *, arg3: int = 2, arg4: bool = False,
+ arg1, arg2='test', *, arg3: int = 2, arg4: bool = False,
):
print(1)