Skip to main content

A unicode-resistant replacement for the classic `patch` utility

Project description

FTW Patch

Author: Fitzz TeXnik Welt

Email: FitzzTeXnikWelt@t-online.de

PyPI version Supported Python versions

Documentation Status Code Coverage Doc Coverage Linting: ruff License: GPL v2

Abstract

A unicode-resistant replacement for the classic patch utility. This tool is designed to handle patches reliably, even when dealing with special characters or different file encodings that often cause issues with traditional tools.


Installation

Install ftw-patch easily via pipx:

pipx install ftw-patch

Features

  • Unicode-Safe: Reliable processing of files with special characters and various encodings.
  • Modern Python Support: Fully tested and optimized for Python 3.11 up to the latest version 3.15.
  • Cross-Platform: Works seamlessly on Linux, macOS, and Windows.
  • Configuration Support: Settings can be pre-defined in pyproject.toml or a custom user TOML file.
  • Robust Path Handling: Uses platformdirs to ensure clean and standard-compliant file paths.
  • High Quality: Developed with high test coverage and verified via automated tox builds.
  • Advanced Whitespace Handling: Options to normalize non-leading whitespace or ignore blank line differences.
  • Safety First: Includes a --dry-run mode to simulate changes and automatic backup functionality.

Usage (Command Line Interface)

ftw-patch is primarily used as a command-line tool.

Basic Syntax

ftwpatch [options] patch_file

Key Arguments & Options

  • patch_file: The path to the unified diff or patch file.
  • -h, --help: Show the help message and exit.
  • -p, --strip <count>: Set the number of leading path components to strip from file names before trying to find the file (default: 0).
  • -d, --directory <dir>: Change the working directory to <dir> before starting to look for files to patch.
  • --normalize-ws: Normalize non-leading whitespace (replace spaces/tabs with a single space) in context and patch lines before comparison.
  • --ignore-bl: Ignore differences in the number of consecutive blank lines.
  • --ignore-all-ws: Ignore all whitespace (leading, non-leading, and blank lines). This overrides --normalize-ws and --ignore-bl.
  • --dry-run: Simulate the process without writing any changes to the file system.
  • -b, --backup: Create a backup of each file before applying patches.
  • --backupext <ext>: Extension for backup files (default: .bak). Supports special keywords: date, time, or datetime for ISO 8601 timestamps.
  • --userconfig <path>: Path to a custom user TOML configuration file.

Note: Settings can also be loaded from pyproject.toml under [tool.fitzzftw.patch].

Configuration via pyproject.toml

You can pre-configure ftwpatch in your project's pyproject.toml file. This is useful for setting permanent defaults for your project.

Add a section [tool.fitzzftw.patch] like this:

[tool.fitzzftw.patch]
backup = true
backupext = ".original"
normalize-ws = true
strip = 1

User Configuration and User Config File

If you want to use ftw-patch with the same settings across multiple projects, you can create a central user configuration file. The tool automatically searches for a patch.toml file in your standard user configuration directory.

Standard Locations:

  • Linux: ~/.config/ftw-patch/patch.toml
  • macOS: ~/Library/Application Support/ftw-patch/patch.toml
  • Windows: %AppData%\ftw-patch\patch.toml

Example patch.toml:

# Your personal defaults
backup = true
backupext = ".original"
normalize-ws = true

Note: You can override these defaults at any time by using command-line options or a project-specific pyproject.toml. If you want to use a specific configuration file from a different location, use the --userconfig <path> option.

Licensing

This project uses different licenses for software and documentation:

Software (Code)

The source code of ftw-patch is licensed under the GNU General Public License, Version 2. This allows free use, modification, and integration, provided that the terms of the GPLv2 (such as distributing the source code when you share the software) are met.

Documentation

The documentation (content in the docs/ directory and manuals) is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0).

  • NC (Non-Commercial): Commercial use of the documentation (e.g., selling it as a printed book) is prohibited without express permission.
  • BY / SA: Attribution and sharing under the same conditions are required.

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

ftw_patch-0.5.0.tar.gz (36.1 MB view details)

Uploaded Source

Built Distribution

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

ftw_patch-0.5.0-py3-none-any.whl (66.7 kB view details)

Uploaded Python 3

File details

Details for the file ftw_patch-0.5.0.tar.gz.

File metadata

  • Download URL: ftw_patch-0.5.0.tar.gz
  • Upload date:
  • Size: 36.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ftw_patch-0.5.0.tar.gz
Algorithm Hash digest
SHA256 ac7e470f240c58cb92413f12f63f38e3a73dbb02bed6a74068462e46cc50b56b
MD5 1fe79dc13347b34bff8ccd59a00617d6
BLAKE2b-256 80302b361517d05a97cca401116ab0d6f43da1dbd7fdc80a459a047aad92323c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftw_patch-0.5.0.tar.gz:

Publisher: ci.yml on fitzz-ftw/ftw-patch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ftw_patch-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: ftw_patch-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 66.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ftw_patch-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f1e3f0d84cebca658a0c04d5822d0b7cff6cec0d6ad634c0478da420fae0b750
MD5 4fb5e92bc52b35b5cd5d02190d4e876a
BLAKE2b-256 2c8eaacf621df89bca2e1c6cc663e9feda884ae7037f560b07cd46d84398ed4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftw_patch-0.5.0-py3-none-any.whl:

Publisher: ci.yml on fitzz-ftw/ftw-patch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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