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.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: codemod_yaml-0.1.0.tar.gz
  • Upload date:
  • Size: 16.3 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.0.tar.gz
Algorithm Hash digest
SHA256 38bf53fd09a6f665fce84d7261fdc12dbc91a808b56ff997bc5234b1a19acaa2
MD5 25d2fc46d4c05e1207805c3a5af8ccf6
BLAKE2b-256 8c66ad60fe118650556260879ee968c8bbf7461289032702e3feba9d0472daa8

See more details on using hashes here.

Provenance

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

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

Attestations:

File details

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

File metadata

  • Download URL: codemod_yaml-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65ad4628ef95e6ca8a8feb3909c8ef709baf1e6bfd49439f76d0088ac9e717df
MD5 af296a133c8a010139abe4b75bac47f0
BLAKE2b-256 2ceebac9a0af2c603696e4af826cddd1e0a29d76a209daa522fc6438ebb336e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for codemod_yaml-0.1.0-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