Skip to content

TopNik073/def-form

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

def-form

Python function definition formatter

Ruff PyPI PyPI Coverage Status

Overview

def-form is a code formatting tool that focuses specifically on Python function definitions. It helps maintain consistent formatting of function signatures by automatically organizing arguments vertically when they exceed specified thresholds.

Features

  • Automatic argument formatting: Converts inline function arguments to vertical format based on configurable rules
  • CI/CD integration: Provides both format and check commands for use in development pipelines
  • Configuration file support: Uses pyproject.toml for project-specific settings
  • Customizable thresholds: Control when arguments should be formatted vertically

Installation

pip install def-form

Usage

Format code

  • Format all Python files in a directory:
def-form format src/
  • Format a specific file:
def-form format my_module.py

Check code without formatting

  • Check if code follows formatting rules:
def-form check src/

Command line options

def-form format [OPTIONS] [PATH]

Options:
  --max-def-length INTEGER  Maximum length of function definition
  --max-inline-args INTEGER Maximum number of inline arguments
  --indent-size INTEGER     indent size in spaces (default: 4)
  --exclude TEXT            Paths or files to exclude from checking/formatting
  --show-skipped            Show skipped files/directories
  --config TEXT             Path to pyproject.toml configuration file

Configuration

Create a pyproject.toml file in your project root:

[tool.def-form]
max_def_length = 100
max_inline_args = 2
indent_size = 4
exclude = [
    '.venv',
    'migrations'
]

Configuration options

  • max_def_length: Maximum allowed characters in a single-line function definition
  • max_inline_args: Maximum number of arguments allowed in inline format
  • indent_size: Indent for arguments in spaces
  • exclude: Files or directories you want to exclude