Skip to main content

Formatter for functions

Project description

def-form logo
Python function definition formatter

Ruff PyPI version PyPI downloads 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/

Example

You can check your code with check command and see the result

(.venv) user@MacBook-Pro def-form % def-form check test_file.py
Checking test_file.py

                           Configuration                           
 ───────────────────────────────────────────────────────────────── 
  Config Path:       /Users/user/Documents/def-form/pyproject.toml  
  Max Inline Args:   2                                             
  Max Def Length:    100                                           
  Indent Size:       4 spaces                                      
  Show Skipped:      No                                            
  Excluded:          .venv, tests/cases, build                     
 ───────────────────────────────────────────────────────────────── 

Found 1 errors in 1 files

/Users/user/Documents/def-form/test_file.py:19
  • Invalid multiline function parameters indentation (expected 4 spaces)

           Summary           
 ─────────────────────────── 
  Files processed:     1     
  Files with issues:   1     
  Total errors:        1     
  Success rate:        0.0%  
 ─────────────────────────── 

Code style violations found

Or use format

(.venv) user@MacBook-Pro def-form % def-form format test_file.py
Formatting test_file.py

                           Configuration                           
 ───────────────────────────────────────────────────────────────── 
  Config Path:       /Users/user/Documents/def-form/pyproject.toml  
  Max Inline Args:   2                                             
  Max Def Length:    100                                           
  Indent Size:       4 spaces                                      
  Show Skipped:      No                                            
  Excluded:          build, .venv, tests/cases                     
 ───────────────────────────────────────────────────────────────── 

Found 1 errors in 1 files

/Users/user/Documents/def-form/test_file.py:19
  • Invalid multiline function parameters indentation (expected 4 spaces)

           Summary           
 ─────────────────────────── 
  Files processed:     1     
  Files with issues:   1     
  Total errors:        1     
  Success rate:        0.0%  
 ─────────────────────────── 

Formatting completed

Command line options

There is global options

Usage: def-form [OPTIONS] COMMAND [ARGS]...

Options:
  --verbose  Enable verbose output
  --quiet    Disable all output
  --help     Show this message and exit.

Commands:
  check
  format

And specific options for check/format

Usage: def-form format [OPTIONS] [PATH]

Options:
  --config FILE              Path to pyproject.toml configuration file
  --show-skipped             Show skipped files and directories
  --exclude PATH             Paths to exclude from processing
  --indent-size INTEGER      Indent size in spaces (default: 4)
  --max-inline-args INTEGER  Maximum number of inline arguments
  --max-def-length INTEGER   Maximum length of function definition
  --help                     Show this message and exit.

Configuration

Create a pyproject.toml file in your project root:

[tool.def-form]
max_def_length = 100  # Maximum allowed characters in a single-line function definition
max_inline_args = 2   # Maximum number of arguments allowed in inline format
indent_size = 4       # Indent for arguments in spaces
exclude = [           # Files or directories you want to exclude
    '.venv',
    'migrations'
]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

def_form-0.2.0.tar.gz (283.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

def_form-0.2.0-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file def_form-0.2.0.tar.gz.

File metadata

  • Download URL: def_form-0.2.0.tar.gz
  • Upload date:
  • Size: 283.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for def_form-0.2.0.tar.gz
Algorithm Hash digest
SHA256 761e8c199115e7d310c22b576bd6cb76641ade8135492b9416851f1d7b965e98
MD5 1f66b1d6fd9b21977554c58d836a5088
BLAKE2b-256 697b07f78aa01e83dffed318dbaf8440cd698c436011b60e9a042395986a305a

See more details on using hashes here.

File details

Details for the file def_form-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: def_form-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for def_form-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5463b512dc04e7eb820503fc346e028f62adf6e65f25d462990ce065c2a22a4e
MD5 32a8f9fbbb3dd2c75e65b1e2f59ecc4e
BLAKE2b-256 8a2b1eb14b1045f9988203b37daf7db55a3bb73b5adebd08d0da4415d2014780

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page