Skip to content

v0.1.0 - beta

Latest

Choose a tag to compare

@Shorzinator Shorzinator released this 23 Jun 00:13

✨ path-comment-hook v0.1.0 - Initial Public Release! ✨

We are thrilled to announce the first public release of path-comment-hook! 🎉

path-comment-hook (or simply pch) is a Python CLI tool and pre-commit hook designed to automatically add (or check for) a comment at the top of your source files, indicating the file's relative path within the project. This aids in code navigation and understanding context, especially in larger projects or when viewing files outside of an IDE.

This v0.1.0 release lays the foundation for path-comment-hook, providing robust core functionality and essential configuration options.

Why path-comment-hook?

  • 🧭 Better Navigation: Instantly know which file you're viewing in code reviews, logs, or snippets.
  • 📝 Context Awareness: No more guessing file locations when viewing code outside your IDE.
  • 🔧 Zero Effort: Set it once in pre-commit and forget about it.
  • ⚡ Fast: Multiprocessing support handles large codebases efficiently.

Key Features in v0.1.0:

  • Automated Header Injection:
    • Intelligently adds path comments to a wide range of file types.
    • Preserves existing file content, line endings (CRLF/LF), and handles various encodings (UTF-8 default with chardet fallback).
    • Ensures safe file operations with atomic writes.
  • User-Friendly CLI (path-comment-hook / pch):
    • Includes a convenient pch alias for quicker command-line usage.
    • --check mode: Verifies headers without modifying files, ideal for CI environments.
    • --all flag: Recursively discovers and processes files throughout your project.
    • Informative progress bars during processing.
  • Flexible Configuration (pyproject.toml):
    • Easily define file/directory exclusion patterns using exclude_globs.
    • Customize comment styles for different file extensions via custom_comment_map (e.g., # {_path_} for Python, // {_path_} for JavaScript).
  • Performance-Minded:
    • Utilizes multiprocessing (ThreadPoolExecutor) for significantly faster processing of multiple files.
  • Seamless Pre-commit Integration:
    • Designed to be a frictionless part of your development workflow.
  • Project Quality:
    • Built with a focus on code quality, including type safety (Mypy), linting (Ruff), and security scanning (Bandit).
    • Continuous Integration (CI) via GitHub Actions ensures stability.

Quick Example:

Before:

def calculate_tax(amount, rate):
    return amount * rate

After running pch --all (or via pre-commit):

# src/utils/tax_calculator.py
def calculate_tax(amount, rate):
    return amount * rate

Supported File Types:

Out of the box, path-comment-hook supports many common file types, including:

  • Python (.py) → # path/to/file.py
  • JavaScript/TypeScript (.js, .ts, .jsx, .tsx) → // path/to/file.js
  • C/C++ (.c, .cpp, .h, .hpp) → // path/to/file.cpp
  • Shell Scripts (.sh, .bash) → # path/to/script.sh
  • YAML/TOML (.yaml, .yml, .toml) → # path/to/config.yaml
  • And more! Plus, you can easily define custom comment styles for any file type via configuration. See Supported File Types in our documentation for a more comprehensive list. (Adjust link if needed)

Installation:

You can install path-comment-hook directly from PyPI:

=== "pip"

pip install path-comment-hook

=== "pipx (recommended for CLI tools)"

pipx install path-comment-hook

=== "Poetry"

poetry add --group dev path-comment-hook

Getting Started:

  1. Install path-comment-hook.
  2. Add it to your project's .pre-commit-config.yaml:
    repos:
      - repo: https://github.com/shouryamaheshwari/path-comment-hook
        rev: v0.1.0 # Make sure to use this version or the latest
        hooks:
          - id: path-comment
  3. Run it on your project:
    • Via pre-commit (e.g., on commit, or manually): pre-commit run path-comment --all-files
    • Or directly using the CLI: pch --all (or path-comment-hook --all)

For detailed usage and configuration, please visit our Documentation Site.

What's Next?

This is just the beginning! We plan to:

  • Continuously improve test coverage and add more comprehensive Windows testing.
  • Enhance and expand our documentation.
  • Listen to your feedback for future features and improvements!

We encourage you to try path-comment-hook in your projects. Please report any bugs, suggest features, or ask questions on our GitHub Issues page.

Acknowledgments:

Special thanks to the pre-commit community and early testers who provided valuable feedback during development.

Verification:

SHA256 checksums for release artifacts are provided below for verification.