Skip to main content

Line information for ruamel.yaml.

Project description

ruamel_yaml_line_info

Language Python Versions Code Style Type Checked PEP8 Code Coverage License


Python package PyPI version Conda version PyPI download total Conda download total


Line information for ruamel.yaml.

Quick Start

Using an Alternative Constructor

Instead of:

with open(yaml_path, encoding="utf-8") as fh:
    yaml = ruamel.yaml.YAML(typ="rt").load("".join(fh))

change the import:

with open(yaml_path, encoding="utf-8") as fh:
    yaml = ruamel_yaml_line_info.YAML(typ="rt").load("".join(fh))

and voila!

Example

Consider the following YAML:

foo: bar
block: >
  this is not
  a multiline
  block
single_quote: 'single'
double_quote: "double"

then we can get line and column information with

>>> with open(yaml_path, encoding="utf-8") as fh:
    yaml = ruamel_yaml_line_info.YAML(typ="rt").load("".join(fh))
>>> print(yaml["foo"].lc)
LineCol(0, 5)
>>> print(yaml["block"].lc)
LineCol(1, 7)
>>> print(yaml["single_quote"].lc)
LineCol(5, 14)
>>> print(yaml["double_quote"].lc)
LineCol(6, 14)

where the first value in LineCol is the 0-based line, and the second value in LineCol is the 0-based column.

See the test for more exapmles.

Patching an existing YAML object

If you already have a ruamel.yaml.YAML instance, you can add line numbers with:

with open(yaml_path, encoding="utf-8") as fh:
    yaml = ruamel.yaml.YAML(typ="rt").load("".join(fh))
    yaml = ruamel_yaml_line_info.YAML.with_line_numbers(yaml=yaml)

Recommended Installation

Install the Python package and dependency management tool poetry using official documentation. You must have Python 3.11 or greater available on your system path, which could be managed by mamba, pyenv, or another package manager. Finally, install the dependencies of the project with:

poetry install

To check successful installation, run:

python -c "import ruamel_yaml_line_info"

Installing with Conda

Install the environment manager mamba using official documentation. Create and activate a conda environment with Python 3.11 or greater:

mamba create -c conda-forge -n ruamel_yaml_line_info ruamel-yaml-line-info python=3.11
mamba activate ruamel_yaml_line_info

Alternatively, install into an existing conda environment:

mamba install -n <ENVIRONMENT> -c conda-forge ruamel-yaml-line-info

To check successful installation, run:

python -c "import ruamel_yaml_line_info"

Development and Testing

See the contributing guide for more information.

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

ruamel_yaml_line_info-0.1.4.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ruamel_yaml_line_info-0.1.4-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file ruamel_yaml_line_info-0.1.4.tar.gz.

File metadata

  • Download URL: ruamel_yaml_line_info-0.1.4.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ruamel_yaml_line_info-0.1.4.tar.gz
Algorithm Hash digest
SHA256 8cb81a11671a341693af713c70d0b58e0cee2b39ece4ffb413a333c91edd21f8
MD5 79826d67350af5ca51d2268a6753427e
BLAKE2b-256 85276c0b8435ae920f4c7baeb5d34ff9a64d9306e0baaadf263656fe98876a94

See more details on using hashes here.

Provenance

The following attestation bundles were made for ruamel_yaml_line_info-0.1.4.tar.gz:

Publisher: publish.yml on nh13/ruamel_yaml_line_info

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ruamel_yaml_line_info-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for ruamel_yaml_line_info-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5f168a894f8608edcb2da21feb9cbf207160ea9dbcb40c0e47f5a144faa469f9
MD5 bece07c2fc2e35100f27db9414097b23
BLAKE2b-256 5dfcc42dc4d5f01d66ec70126f9d1c61920adf1466c59855b8dd8fcd813a6f4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ruamel_yaml_line_info-0.1.4-py3-none-any.whl:

Publisher: publish.yml on nh13/ruamel_yaml_line_info

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page