AgentSkillsCN

format-python

使用Black格式化Python代码

SKILL.md
--- frontmatter
name: format-python
description: Format Python code with Black

Python Format Skill

📋 Overview

Use Black to automatically format Python code, an uncompromising code formatter:

  • 🎨 Unified style: Automatic team code style consistency
  • Fast execution: Extremely fast formatting speed
  • 🔒 Deterministic: Same code always produces same result
  • 🔧 Zero config: Works out of the box

🔧 Prerequisites

ToolMin VersionCheck CommandInstallation
Python3.8+python --versionpython.org
Black22.0+black --versionpip install black

🚀 Usage

Method 1: AI Assistant

code
"Use format-python to format my code"

Method 2: Run Script Directly

powershell
# Windows
.\.agent\skills\format-python\scripts\format.ps1

# Linux/Mac
./.agent/skills/format-python/scripts/format.sh

Method 3: With Parameters

powershell
# Check without modifying (preview mode)
.\.agent\skills\format-python\scripts\format.ps1 -Check

# Specify directory
.\.agent\skills\format-python\scripts\format.ps1 -Path ".\src"

🎯 What It Formats

  • ✅ Indentation standardization (4 spaces)
  • ✅ Line length limit (default 88 characters)
  • ✅ String quote unification
  • ✅ Bracket and comma normalization
  • ✅ Import statement formatting

⚙️ Configuration

toml
# pyproject.toml
[tool.black]
line-length = 88
target-version = ['py38']
include = '\.pyi?$'
extend-exclude = '''
/(
  \.git
  | \.venv
  | build
  | dist
)/
'''

🔗 Related Resources