Skip to main content

Git diff handling in Python.

Project description

fugit

Fugit Logo

PyPI pdm-managed pre-commit.ci status Supported Python versions license Pydantic v2 Documentation

Git diff handling in Python

sed fugit interea fugit irreparabile tempus

(“meanwhile, the irreplaceable time escapes”)

Motivation

Accessing structured diffs in a Git repository remains challenging, even with tools like GitPython. This issue is especially pronounced when dealing with large diff sets, such as those generated during transitions between linters (e.g., from Black to Ruff). Currently, without a straightforward programmatic solution, understanding the essence of these diffs requires cumbersome manual effort.

Before writing this library I explored fast parsing approaches (Pydantic's integration with Rust's regex crate in particular) and reviewed GitPython internals, as well as its pitfalls.

fugit simplifies access to git diffs, and will help you avoid the covert hazards in GitPython's API.

Installation

pip install fugit

Usage

Use fugit on the command line as a replacement to git diff:

fugit
usage: fugit [-h] [--repo REPO] [--revision REVISION] [-c [CHANGE_TYPE ...]]
             [-q] [-p] [-n] [--version]

Configure input filtering and output display.

options:
  -h, --help            show this help message and exit
  --repo REPO           The repo whose git diff is to be computed.
                        (type: Path, default: .)
  --revision REVISION   Specify the commit for comparison with the index. Use "HEAD" to
                        refer to the latest branch commit, or "HEAD~{$n}" (e.g. "HEAD~1")
                        to indicate a specific number of commits before the latest.
                        (type: str, default: HEAD)
  -c [CHANGE_TYPE ...], --change-type [CHANGE_TYPE ...]
                        Change types to filter diffs for.
                        (type: str, default: ['A', 'C', 'D', 'M', 'R', 'T', 'U', 'X', 'B'])
  -q, --quiet           (default: False)
  -p, --plain           (default: False)
  -n, --no-pager        (default: False)
  --version             show program's version number and exit

Or the Python interface:

from fugit import diff

diff(repo="/path/to/your/repo", quiet=True)

Development

  • To set up pre-commit hooks (to keep the CI bot happy) run pre-commit install-hooks so all git commits trigger the pre-commit checks. I use Conventional Commits. This runs black, flake8, autopep8, pyupgrade, etc.

  • To set up a dev env, I first create a new conda environment and use it in PDM with which python > .pdm-python. To use virtualenv environment instead of conda, skip that. Run pdm install and a .venv will be created if no Python binary path is found in .pdm-python.

  • To run tests, run pdm run python -m pytest and the PDM environment will be used to run the test suite.

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

fugit-0.3.3.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

fugit-0.3.3-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file fugit-0.3.3.tar.gz.

File metadata

  • Download URL: fugit-0.3.3.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.11.1 CPython/3.11.5

File hashes

Hashes for fugit-0.3.3.tar.gz
Algorithm Hash digest
SHA256 a61d3e68d7e70231b2ac04d21d65202ff1844efbc79e709d14a9af85cc8d5bb3
MD5 d32087a284928e3e0af2d566ed4708c5
BLAKE2b-256 5f0d0d4b3307421d501d69eff49bdcba3ff08410c627f7d156f0fc46ea880af4

See more details on using hashes here.

File details

Details for the file fugit-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: fugit-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.11.1 CPython/3.11.5

File hashes

Hashes for fugit-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 00aa5d18f65f2e1d6e6fbeab8aa8831e022af7f1e06138c26bf804113630427e
MD5 e0e1f6512a5fd147721f770538d0ef8a
BLAKE2b-256 15136e0f4e468114a11f8bb700cc5d31afdf42e6de2ffa37db47cfeae722fd30

See more details on using hashes here.

Supported by

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