Skip to main content

Function-level diff tool for Python files between Git refs

Project description

Function Diff

Compare function-level changes in Python files between two Git refs (branches, tags, or SHAs). Reports added, removed, and modified functions/methods—useful for reviews and CI.

Install

pip install function-diff

Requires Python 3.8+ and Git on PATH.

CLI

function-diff <base_ref> <target_ref> [options]

function-diff main feature-branch
function-diff main HEAD --include-added
function-diff main HEAD --repo-path /path/to/repo
function-diff main feature --repo-url https://github.com/user/repo.git
function-diff main HEAD --send-email   # needs EMAIL_* (see below)

function-diff --version
function-diff --help

If you run from a Git checkout and omit --repo-path, the current directory is used when it contains .git. Otherwise set --repo-url or FUNCTION_DIFF_REPO_URL.

Python API

from function_diff import analyze, print_report, build_html_report

report = analyze(None, "main", "feature", repo_path=".")
print_report(report, include_added=True)
html = build_html_report(report, include_added=False)

Email from code: from function_diff.emailer import send_function_diff_email (set EMAIL_USER, EMAIL_PASS, EMAIL_TO; optional EMAIL_FROM, EMAIL_CC, SMTP_HOST, SMTP_PORT).

Environment variables

Variable When Notes
EMAIL_USER --send-email / send_function_diff_email SMTP login
EMAIL_PASS same App password or SMTP secret
EMAIL_TO same Comma-separated recipients
EMAIL_FROM optional From header; default EMAIL_USER (use for Azure “send as”)
EMAIL_CC optional Comma-separated CC
SMTP_HOST optional Default smtp.gmail.com
SMTP_PORT optional Default 587 (STARTTLS)
GITHUB_REPOSITORY optional Shown in HTML email
BASE_REF / TARGET_REF optional Override CLI refs
FUNCTION_DIFF_REPO_URL optional Clone URL when not using --repo-path
GH_PAT private HTTPS clone Use with Git credential helper or embed in clone URL

Gmail: SMTP_HOST=smtp.gmail.com, SMTP_PORT=587.
Azure / Microsoft 365: often SMTP_HOST=smtp.office365.com, SMTP_PORT=587; set EMAIL_USER to the mailbox that authenticates and EMAIL_FROM to the visible sender if they differ.

GitHub Actions (minimal)

- uses: actions/checkout@v4
  with:
    fetch-depth: 0
- uses: actions/setup-python@v5
  with:
    python-version: "3.12"
- run: pip install function-diff
- run: |
    function-diff \
      ${{ github.event.pull_request.base.ref }} \
      ${{ github.event.pull_request.head.ref }} \
      --repo-path ${{ github.workspace }}

For email, pass secrets as EMAIL_USER, EMAIL_PASS, EMAIL_TO, etc., and add --send-email when appropriate.

How it works

Changed .py files between the two refs are diffed at the AST level: top-level functions and class methods (as Class.method) are hashed; decorator or body changes count as modified.

Optional: if zephyr-jira-linker is on PATH, branch names with a Jira key can enrich the email “implementor” field.

Examples

See examples/ and examples/usage_examples.py.

Maintainer docs

Build, publish, and contributing notes: DEVELOPMENT.md. Version history: CHANGELOG.md.

License

MIT — see LICENSE.

Author

Pandiyaraj Karuppasamy — pandiyarajk@live.com · GitHub · PyPI

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

function_diff-0.1.1.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

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

function_diff-0.1.1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file function_diff-0.1.1.tar.gz.

File metadata

  • Download URL: function_diff-0.1.1.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for function_diff-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8ac7ecbb8573f341c94a5d130f4539aafbf356d7e66feaac10fff1fae145138d
MD5 324a83f12b3d6d9ea055e57f05722f9a
BLAKE2b-256 3501e64c8e5489243758f75b4988c4a50d562f1ac9860961fcbc191722614730

See more details on using hashes here.

File details

Details for the file function_diff-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: function_diff-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for function_diff-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f176f85317806c63ccef768a1264da6565d050a5e55c20977ad27cbd9a844cbe
MD5 97d7b9498c4f6ec6b6ea5f17c8b31456
BLAKE2b-256 22e1f8b803c77c6bef82842459a55855c0d04a98e7fc01f9a3b2e303dac0311a

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