Skip to main content

tomlpatch

Do you want to patch your toml file structurally like modifying a nested python dictionary? This is a tool for you.

Description

Sometimes, you want to edit/patch a toml file, but you don't want to use the diff between two source files to patch the toml file since it may introduce conflicts that requires human intervention to resolve. For example, Cargo.toml is used by Rust projects, and this tool can be used to patch the Cargo.toml file with an external JSON file that contains the structural patch information so that you don't need to manually resolve the Cargo.toml file.

Installation

pip install tomlpatch

Usage

tomlpatch original_toml_file patch_json_file

Example

Suppose you have a Cargo.toml file like this:

[package]
name = "my_package"
version = "0.0.1"

liberssl = { version = "0.10.42", default-features = false, features=["vendered"] }
sources = ["s1", "s2"]
targets = ["t1", "t2", "t3"]

And you want to patch the Cargo.toml file with a JSON file like this:

{
  "patch": {
    "package.version": "0.0.2",
    "package.liberssl.features": null
  },
  "extend": {
    "package.sources": ["s4", "s5"]
  },
  "remove": {
    "package.targets": ["t2"]
  }
}

Then you can use the following command to patch the Cargo.toml file:

tomlpatch Cargo.toml patch.json

After the patch, the Cargo.toml file will be like this:

[package]
name = "my_package"
version = "0.0.2"
sources = [
    "s1",
    "s2",
    "s4",
    "s5",
]
targets = [
    "t1",
    "t3",
]

[package.liberssl]
version = "0.10.42"
default-features = false

TODO

  • Switch to tomkit for style preserving patching

Metadata

Release files for tomlpatch 0.2.0

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

Source distribution (sdist)

Source distribution for tomlpatch 0.2.0
File Size Uploaded
tomlpatch-0.2.0.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tomlpatch 0.2.0
File Interpreter ABI Platform
tomlpatch-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.0 kB

Release files / tomlpatch-0.2.0.tar.gz

Download URL tomlpatch-0.2.0.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
06d0ddfa0926c62ce79102c029b7470a3fe7bb88421e58d10e21b1269404f953
BLAKE2b-256 checksum
How to use checksums
b7a189807aae493395b8e2df42450313ae06a859506ed0bbfe1eadca19db56a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release files / tomlpatch-0.2.0-py3-none-any.whl

Download URL tomlpatch-0.2.0-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2cf62ca99a78ba97eab56f6a68d735c680a74ead99faf97ede82d79abcb7a6d9
BLAKE2b-256 checksum
How to use checksums
4023f31a584d9449a14f6e9e993acd66588b99b35c0e0c1b03ab1309b0876e64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

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