Skip to main content

Lib to modify yaml inplace

Project description

codemod-yaml

This library is for making targeted edits to YAML documents. The core design goal is:

  1. Only change lines with data changes.

While you can't edit all YAML constructs, you can generally replace them and roundtrip them thanks to tree-sitter-yaml.

This was roughly inspired by pyupgrade which combined AST-based parsing with more low-level edits.

Basic Usage

from codemod_yaml import parse
stream = parse(somepath.read_bytes())
if stream["version"] == ["2.7"]:
    stream["version"][:] = ["3.6", "3.13"]
somepath.write_bytes(stream.text)

Supported

[x] round-tripping unedited sections verbatim [x] any valid yaml after where you're editing [x] block maps with string keys [x] block sequences [x] python str/float/list/dict

Version Compat

Usage of this library should work back to 3.7, but development (and mypy compatibility) only on 3.10-3.12. Linting requires 3.12 for full fidelity.

Versioning

This library follows meanver which basically means semver along with a promise to rename when the major version changes.

License

codemod-yaml is copyright Tim Hatch, and licensed under the MIT license. See the LICENSE file for details.

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

codemod_yaml-0.1.1.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

codemod_yaml-0.1.1-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: codemod_yaml-0.1.1.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for codemod_yaml-0.1.1.tar.gz
Algorithm Hash digest
SHA256 075a5db20f602e134a2b818effa0850ee40c750e0c79a187b35d95ac74bd3eb6
MD5 d2068f12e2c72897673c5c83fdba6ef3
BLAKE2b-256 5b2ed98a9c8c78b6b364ce03c0fe5975babde038a80e4b2ae2e07670816b99dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for codemod_yaml-0.1.1.tar.gz:

Publisher: build.yml on advice-animal/codemod-yaml

Attestations:

File details

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

File metadata

  • Download URL: codemod_yaml-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for codemod_yaml-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 97b1088f2cb177b35f849abb18bac06f67cb0617bdd8ed39e042651fa6fca7bf
MD5 c3cf5b0ebd80c034a84588178acb85fa
BLAKE2b-256 08c6b14a1536bc5b98f6509a7aeb35789b9750180e4d8f86b218d78104b1a3f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for codemod_yaml-0.1.1-py3-none-any.whl:

Publisher: build.yml on advice-animal/codemod-yaml

Attestations:

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