Skip to main content

pypatch-url

Automatically apply patches to third-party libraries as part of your build.

Now and again, a specific fix is needed for a python package that isn't available from the vendor/community. This project was created to allow a way for us to patch specific python modules during the build process.

pypatch-url is a fork of Sitka Technology Group's PyPatch tool, which itself is a command wrapper based around Anatoly Techtonik's patch.py utility. This fork adds two important features that were already present in the underlying patch.py utility but weren't accessible from the command line:

  1. Path stripping with -p NUM or --strip=NUM to strip leading components from file names (matching the standard Unix patch tool)
  2. URL support to automatically download patches when a URL is specified instead of a local file path

These enhancements were contributed by sfinktah@github.spamtrak.org, although the underlying functionality already existed in Anatoly Techtonik's patch.py library.

Usage

pypatch-url apply custom_diff.patch [library.package]```
With the new options:

pypatch-url apply -p 1 custom_diff.patch [library.package] # Strip one directory level from paths pypatch-url apply https://example.com/patches/fix.patch [library.package] # Download and apply patch

As a part of the work flow:

c:\project\pip install django c:\project\pip install pypatch-url c:\project\pypatch-url apply c:\project\patches\my_auth_fix.patch django.contrib.auth

How it works
------------
pypatch-url applies patches to files relative to the root directory of the named package. So it does have to be installed into the target environment.

For example, if the django package was installed to "C:\Python27\Lib\site-packages\django" and you needed to patch the auth contrib package (django.contrib.auth), your command might look like

pypatch-url apply c:\project\patches\my_auth_fix.patch django.contrib.auth``` and the files named in my_auth_fix.patch would use relative pathing from the package directory:


--- models.py    2013-05-06 15:12:14.212220100 -0700
+++ models.py	2013-05-06 14:36:20.535220100 -0700

If you used

pypatch-url apply c:\project\patches\my_auth_fix.patch django.contrib```
instead, your diff patch would read

--- auth/models.py 2013-05-06 15:12:14.212220100 -0700 +++ auth/models.py 2013-05-06 14:36:20.535220100 -0700

Path Stripping
-------------
The `-p NUM` or `--strip=NUM` option allows you to strip leading path components from file names in the patch. This is especially useful when applying patches created from different directory structures:

pypatch-url apply -p 1 c:\project\patches\my_fix.patch django

This would strip the first directory component from each path in the patch file.

URL Support
----------
You can directly specify a URL instead of a local patch file:

pypatch-url apply https://example.com/patches/fix.patch django

This will automatically download the patch file from the URL and apply it to the specified module.

Build
-----
To build the distributable python package, run 'sdist' from the Project Root Directory.
Recommended: setting the output directory to our Libraries folder

sdist --dist-dir="C:\outputdir"``` This will build the zipped python package that can be installed via pip or easy_install

Other

Information on the Unified Diff format can be found at https://www.gnu.org/software/diffutils/manual/html_node/Unified-Format.html#Unified-Format

Metadata

Release files for pypatch-url 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pypatch-url 1.0.4
File Size Uploaded Provenance Actions
pypatch_url-1.0.4.tar.gz 21.6 kB Without provenance Details for pypatch_url-1.0.4.tar.gz

Release files / pypatch_url-1.0.4.tar.gz

Download URL pypatch_url-1.0.4.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
cd00f60379566c540a47768bd7ad58a0cd44897600394236002ea891688afad6
BLAKE2b-256 checksum
How to use checksums
fda8c73eb61fda02cb9a9a5bbe26913608582fdcf545b26cff4fb57d039f8ec0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Security for pypatch-url 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.4 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page