Giter Club home page Giter Club logo

yaml_converter's Introduction

YAML Converter

Build Status Code Health Code Climate Test Coverage

Bidirectional converter for specific YAML files.

Primary motivation is to have a bidirectional converter for Flow123d input files. However, long term plan is to make it an independent tool for bidirectional conversion of custom YAML file formats.

Requirements

ruamel.yaml

Documentation

PathSet syntax

Modification rules (described further on) are applied to the addresses in the given YAML file that match given PathSet pattern. PathSet pattern is an address like:

/key_a/1/key_b

Following constructs can be used:

'*' character - match any key

'#' character - match any index

'**' - match any sub path (can contain both keys and indices)

'KEY!TAG' - match the KEY only if it have tag TAG. Usefull for custom tags or in combination with '*'.

'(A|B|C)' - match A or B or C. Can be used for both keys and tags.

Tail and value patterns

Single path pattern could be composed from one, two or three patterns seprated by the colon :. The first pattern is always the path pattern, the second is the tail pattern, the third is the value pattern. The tail and value patterns are empty by default.

The tail pattern restricts the modification rule only to the addresses that contains the tail pattern as a subpath. E.g. path pattern x(a|b):y for the YAML file

xa:
  y: 2
xb:
  z: 3  

matches only the address xa as it contains subpath y but does not match the path xb.

The value pattern restricts the modification rule only to the addresses that contains a value which matches the value pattern.

YAML predefined tag names

  • 'null'
  • 'bool'
  • 'int'
  • 'float'
  • 'binary'
  • 'timestamp' - YAML recognize time and date in some format
  • 'omap' - ordered map, used by default by ruamel YAML instead of 'map' coud be required explicitely
  • 'pairs' - ?
  • 'set' - is a mapping where all keys have null value
  • 'str'
  • 'seq'
  • 'map'

Change rules

add_key_to_map(paths, key, value)

set_tag_from_key(paths, key, tag)

manual_change(paths, message_forward, message_backward)

copy_value(new_paths, old_paths)

move_value(new_paths, old_paths)

rename_key(paths, old_key, new_key)

rename_tag(paths, old_tag, new_tag):

replace_value(paths, re_forward, re_backward)

change_value(paths, old_val, new_val)

scale_scalar(paths, multiplicator)

yaml_converter's People

Contributors

dflanderka avatar jbrezmorf avatar

Watchers

 avatar  avatar  avatar

yaml_converter's Issues

Fingerprint specification of versions.

  • Add methods to add (and remove) obligatory paths that a version must have.
  • Generalise version detection from 'flow123d' to any key (specific to version).
  • Copy this version fingerprint from previous version.
  • Remove assert for map type of the root node.

Using this general fingerprint mechanism, we can better detect version of the input file and also
distinguish YAML files that are not in particular format.

Bind comments to values according to indention

Seems that comments are binded to last parsed item in the tree, i.e.

# bid to head of root map
a: 
# bind to 'a' map
  b: 0
  # bind to 'b' key
  c: 1
  # bind to 'c' key
# bind to 'c'
x: 2
# bind to 'x' 

We should try to change this in ruamel.yaml, possibly through some setting of the parser. So that we can move values together with comments.

Own YAML interface

Turn yaml_parser_extra to full interface to the YAML file:

  • the only place to interact with ruaml.yaml directly
  • implementation of support for custom tags
  • iterating through the YAML tree
  • own Node objects to allow data tree inspection and modifications

Unit test for Changes actions

  • test actions on specially crafted YAML files using own YAML interface and test results
    of actions directly for the tree not through resulting file
  • can test more operations independently of ruamel.yaml ability to produce well formated YAMLs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.