Metadata-Version: 2.4
Name: blank-line-after-blocks
Version: 0.1.3
Summary: A Python formatter to automatically add blank lines after if/for/while/with/try blocks
Author-email: Your Name <your.email@example.com>
Maintainer-email: Your Name <your.email@example.com>
License: MIT
Project-URL: Homepage, https://github.com/jsh9/blank-line-after-blocks
Project-URL: Repository, https://github.com/jsh9/blank-line-after-blocks.git
Project-URL: Issues, https://github.com/jsh9/blank-line-after-blocks/issues
Project-URL: Changelog, https://github.com/jsh9/blank-line-after-blocks/blob/main/CHANGELOG.md
Keywords: formatter,code-style,blank-lines,python
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Code Generators
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: jupyter-notebook-parser>=0.1.4
Requires-Dist: click>=8.0
Provides-Extra: dev
Requires-Dist: pytest>=6.0; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: tox; extra == "dev"
Provides-Extra: lint
Requires-Dist: flake8>=5.0; extra == "lint"
Requires-Dist: flake8-bugbear; extra == "lint"
Requires-Dist: flake8-comprehensions; extra == "lint"
Requires-Dist: flake8-eradicate; extra == "lint"
Requires-Dist: flake8-broken-line; extra == "lint"
Requires-Dist: flake8-quotes; extra == "lint"
Requires-Dist: flake8-debugger; extra == "lint"
Requires-Dist: flake8-length; extra == "lint"
Requires-Dist: flake8-clean-block; extra == "lint"
Requires-Dist: flake8-indent-in-def; extra == "lint"
Requires-Dist: flake8-picky-parentheses; extra == "lint"
Requires-Dist: flake8-implicit-str-concat; extra == "lint"
Requires-Dist: flake8-return; extra == "lint"
Requires-Dist: flake8-docstrings; extra == "lint"
Provides-Extra: format
Requires-Dist: muff; extra == "format"
Dynamic: license-file

# blank-line-after-blocks

A Python formatter to automatically add blank lines after if/for/while/with/try
blocks to improve code readability.

## Installation

```bash
pip install blank-line-after-blocks
```

## Usage

### Command Line

```bash
# Format Python files
blank-line-after-blocks file1.py file2.py

# Format with exclude patterns (regex - use | for multiple patterns)
blank-line-after-blocks --exclude "tests/|_generated\.py$" src/

# Format Jupyter notebooks
blank-line-after-blocks-jupyter notebook1.ipynb notebook2.ipynb

# Format notebooks with exclude patterns (regex)
blank-line-after-blocks-jupyter --exclude "notebooks/generated/" notebooks/
```

### Pre-commit Hook

Add this to your `.pre-commit-config.yaml`:

```yaml
repos:
  - repo: https://github.com/jsh9/blank-line-after-blocks
    rev: <LATEST_TAG>
    hooks:
      - id: blank-line-after-blocks
      - id: blank-line-after-blocks-jupyter
```

#### Pre-commit with exclude patterns

```yaml
repos:
  - repo: https://github.com/jsh9/blank-line-after-blocks
    rev: <LATEST_TAG>
    hooks:
      - id: blank-line-after-blocks
        args: ["--exclude", "tests/|_generated\.py$"]
      - id: blank-line-after-blocks-jupyter
        args: ["--exclude", "notebooks/generated/"]
```

### Configuration File

You can also configure exclude patterns in `pyproject.toml`:

```toml
[tool.blank-line-after-blocks]
exclude = [
    "tests/",            # Exclude all files in tests directory
    "_generated\.py$",   # Exclude files ending with _generated.py
    "vendor/",           # Exclude all files in vendor directory
    "build/",            # Exclude build directory
]
```

**Note**: CLI `--exclude` options take precedence over configuration file
settings.

## What it does

This tool automatically adds one blank line after the end of:

- `if` statements
- `for` loops
- `while` loops
- `with` statements
- `try`/`except`/`finally` blocks

This improves code readability by providing visual separation between blocks
and subsequent code.

## Examples

### Basic if and for blocks

```diff
  if condition:
      do_something()
+
  next_statement()

  for item in items:
      process(item)
+
  final_step()
```

### Try/except blocks with context managers

```diff
  def process_files(filenames):
      results = []
      for filename in filenames:
          try:
              with open(filename) as f:
                  data = json.load(f)
+
              results.append(data)
          except FileNotFoundError:
              print(f'File {filename} not found')
          except json.JSONDecodeError:
              print(f'Invalid JSON in {filename}')
+
      return results
```

### Nested blocks in class methods

```diff
  class TestClass:
      def method(self):
          try:
              if self.condition():
                  with self.get_context():
                      self.do_work()
+
                  self.cleanup()
+
          except Exception as e:
              self.handle_error(e)
+
          print('method complete')
```
