Skip to main content

Source map for YAML files

Project description

YAML Where?

yaml_where calculates source maps for YAML files, allowing you to correlate file locations with elements in YAML documents.

CI

Installation

$ pip install yaml-where

Examples

Mappings

Find the range containg the the key and value of a map entry:

source_map = YAMLWhere.from_string("a: 1\nb: 42")
assert source_map.get("b") == Range(Position(1, 0), Position(1, 5))

Or get the range of just the key:

source_map = YAMLWhere.from_string("a: 1\nb: 42")
assert source_map.get_key("a") == Range(Position(0, 0), Position(0, 1))

Or just the value:

source_map = YAMLWhere.from_string("a: 1\nbb: 42")
assert source_map.get_value("bb") == Range(Position(1, 4), Position(1, 6))

You can also look up nested locations:

yaml = """a:
    b: 42
    c:
        doo: hola
"""
source_map = YAMLWhere.from_string(yaml)
assert source_map.get_key("a", "b") == Range(Position(1, 4), Position(1, 5))
assert source_map.get_key("a", "c") == Range(Position(2, 4), Position(2, 5))
assert source_map.get_key("a", "c", "doo") == Range(Position(3, 8), Position(3, 11))

Sequences

You can also find ranges for sequence elements:

yaml = """[1,
 a, foo,
 
     indented]
"""
source_map = YAMLWhere.from_string(yaml)
assert source_map.get(0) == Range(Position(0, 1), Position(0, 2))
assert source_map.get(1) == Range(Position(1, 1), Position(1, 2))
assert source_map.get(2) == Range(Position(1, 4), Position(1, 7))
assert source_map.get(3) == Range(Position(3, 5), Position(3, 13))

CI/CD

Bump the version like this:

$ bumpversion patch
$ git push --follow-tags

MIT License

Copyright (c) 2024 Sixty North AS

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

yaml_where-0.2.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

yaml_where-0.2.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file yaml_where-0.2.1.tar.gz.

File metadata

  • Download URL: yaml_where-0.2.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for yaml_where-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e2ea8ab3ab3e3d98f8abf789f4cc541fc56028a2d4b4d2c76f907efb89d447b4
MD5 9b4542b7d2954b9c31586efe726ae215
BLAKE2b-256 a978409feabc7baf11e84b7a33367f32861a95764c59f599e6c3554a053a1b80

See more details on using hashes here.

File details

Details for the file yaml_where-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: yaml_where-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for yaml_where-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dda74beed91d320ffb6f7390b3472d93ef5b8cea8e5cadeeaa33cc347664c77b
MD5 676647627ab14ecbf34a76d6325b5f1e
BLAKE2b-256 e2b98852e011e84c4a92944fc9d6e232575cfb519c0b4c44de1fcf4b2aaa310c

See more details on using hashes here.

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