Questions tagged [ruamel.yaml]
ruamel.yaml is a YAML 1.2 loader/dumper library for Python, with round-trip preservation of comments, tags and flow style. It is a superset of the PyYAML package. Use this tag for issues with features or installation of that are ruamel.yaml specific.
0
votes
1answer
36 views
How do I append to a YAML file with python
I have a YAML file called data.yaml:
---
'001':
name: Ben
email: ben@test.com
I would like to have an updated file that looks like this:
---
'001':
name: Ben
email: ben@test.com
'002':
...
1
vote
2answers
23 views
Outputting YAML with Python: incorrect formatting without lists in input
I'm trying to create YAML from Python dictionaries. So far I've tried both PyYAML and ruamel.yaml and both have the same result: if the input dictionary does not contain a list, the output is not ...
1
vote
1answer
33 views
Declare data type to ruamel.yaml so that it can represen/serialize it?
I am using a function from a python library which returns an object with a specific data type. I would like to serialize that object to a yaml file and I would like to use ruamel.yaml. The problem is ...
1
vote
1answer
29 views
How can I use an utf-8 file name retrieved from a YAML file for os.path.isdir()?
I am loading a folder path from a config.yml file. Example name: C:/Users/Name/Desktop/ü which contains an utf-8 character. When I load this path using yaml.load(config) (I am using ruamel.yaml) and ...
1
vote
1answer
29 views
Preserving relative ordering of merge key and explicit keys with ruamel
I'm hoping to use ruamel.yaml to perform some automatic edits against a large human-edited YAML file.
The input file contains merge keys, like so:
foo: &foo
color: red
bar:
name: qux
<&...
1
vote
1answer
37 views
Prettily dump 2D array to YAML in Python
Suppose I have a 2D array defined like so:
import sys
from ruamel.yaml import YAML
yaml = YAML()
yaml.version = (1,2)
def main():
data = {
"foo": [
[1,2,3],
[4,...
1
vote
1answer
28 views
How to prevent ruamel from breaking a line in the middle of a value?
I have two questions!
Is there a way to prevent round_trip_dump or even just a regular dump from breaking a line in the middle of a sentence? Whenever I have a long sentence (i.e. a description) in ...
1
vote
1answer
20 views
How to prevent earlier list values from getting deleted in the edited yaml file?
This is my YAML file (data.yaml):
- Department: "IT"
name: "abcd"
Education: "Bachlore of Engineering"
And I want to edit it as follows:
- Department: "IT"
name: "abcd"
...
0
votes
2answers
83 views
How to read a component in YAML file so that I can edit it's key value using ruamel.yaml?
This is my YAML file (input.yaml):
team_member:
name: Max
hobbies:
- Reading
team_leader:
name: Stuart
hobbies:
- dancing
I want to edit this YAML file to add more values in key '...
1
vote
1answer
98 views
How do I dump an OrderedDict out as a YAML file?
I wrote a simple script that I finally use ruamel.yaml to publish out to a YAML file (example shown below). I used collections.OrderedDict so that I can alphabetically reorder the keys, but even ...
1
vote
1answer
60 views
How to keep comments in ruamel
I need to sort a YAML file with comments. I'm using ruamel.yaml library to keep comments from YAML, but when I do sort items comments are placed in wrong place.
people = """\
# manager of project
- ...
0
votes
0answers
16 views
Workaround for round trip anchor preservation for scalars in ruamel.yaml
I'm trying to load a yaml file and replace particular anchors with new values using ruamel.yaml's round trip functionality but I'm running into issues due to round trips not preserving anchors for ...
0
votes
1answer
22 views
ruamel.yaml: how do I add a new element at the top level, and inside other elements
ruamel.yaml docs are sparse, and I haven't found the responses I needed here.
Contents of my_file.yaml:
desc: "blahblahblah"
Q1: How do I (programmatically) add "size" as an element at the same ...
0
votes
1answer
22 views
Is it possible to dump the yaml file in another directory on same system?
Here is my directory on raspberry pi:
Home
|__pi
|__test1
|__test2
|__ abc.py
I am running a python code (abc.py) that edit and then dump a YAML file. But the file is saved ...
0
votes
0answers
39 views
Python ruamel doesnt preserve format for newline in yaml
My original yaml file contains newlines after dash (-) that I want to preserve after I dump it
# This is my yaml
color_1:
blue:
-
# I want to preserve this newline after the dash
...
1
vote
1answer
50 views
Why I get quotes in the output of yaml file if I use exclamation mark?
I creating a yaml file with name main.yaml but I want output as follows:
# example
Name:
Job: abcd
Addresss: xyz
client_id: 641
test: !include test.yaml # new key
I don’t want quotes in the ...
0
votes
1answer
139 views
Python YAML dumper single quote and double quote issue
I am reading rows from excel file and dumping to YAML file, after dumping i figured out some row are mentioned in single quote, double quote and plain text.
Data without any special characters are ...
1
vote
1answer
27 views
ruamel.yaml ReaderError when trying to load special characters (Non-whitespace controls)
Trying to load the big-list-of-naughty-strings into Python using ruamel.yaml (to test the character set for an API).
Everything was loaded fine except the 2 lines: 115 and 120 (94 and 95 in the json ...
3
votes
1answer
44 views
ruamel condensing comments and injecting 0x07
Given the following code:
from ruamel.yaml import YAML
yaml = YAML()
with open(filename) as f:
z = yaml.load(f)
yaml.dump(z, sys.stdout)
And the following file:
a: >
Hello.<b>
...
1
vote
1answer
40 views
With Python ruamel.yaml, lost anchor when loading in round-trip mode?
When loading a file containing anchors at different nesting levels, the anchor seems lost and the key remains empty.
When loading the following file:
---
Dict1:
- InnerDict: &inner
...
0
votes
2answers
145 views
How to edit a YAML file in python repeatedly using a variable without defining a specific value for the key?
This is my example YAML file,
# Employee records
Developer:
Department: IT
Manager: ABCD
Floor: 2nd
Lab: 4
Support:
Department: General
Manager: XYZ
Floor: 1st
Lab: 1
Martin:
name: ...
1
vote
1answer
51 views
Manually adding items using ruamel CommentedMap()
As a followup to my previous [Loading and dumping multiple yaml files with ruamel.yaml (python) question), I'm trying now to insert items into the tree. I'm using CommentedMaps(), so that I can also ...
2
votes
2answers
83 views
Safe dumping and loading of defaultdict with ruamel.yaml
I'm trying to (de-)serialize classes that have collections.defaultdict properties with ruamel.yaml in Python (3.6+ in my case).
This would be a minimal example that I would like to get to work:
from ...
1
vote
2answers
128 views
Loading and dumping multiple yaml files with ruamel.yaml (python)
Using python 2 (atm) and ruamel.yaml 0.13.14 (RedHat EPEL)
I'm currently writing some code to load yaml definitions, but they are split up in multiple files. The user-editable part contains eg.
...
1
vote
1answer
62 views
how to explicitly write two references in ruamel.yaml
If I have multiple references and when I write them to a YAML file using ruaml.yaml from Python I get:
<<: [*name-name, *help-name]
but instead I would prefer to have
<<: *name-name
&...
1
vote
1answer
16 views
Specific formatting of sequences in YAML
Is it possible to output sequences with ruamel.yaml in the following format:
-
key1: 1
key2: 2
key3: 3
instead of standard
- key1: 1
key2: 2
key3: 3
...and this
- skills:
- Python
...
1
vote
1answer
41 views
Incorrect format (No newline chars) when loading YAML with embedded JSON
I am trying to parse a YAML input from a file:
root: {
children : { key: "test-key", version: "{{ test_version | default( '1.0.0-SNAPSHOT' ) }}"}
}
I am using ruamel.yaml, the section of code ...
1
vote
3answers
138 views
Append duplicate key value pair to nested dictionary in YAML
I am trying to append duplicate key: value pair to a nested dictionary in a YAML file through python script. Following is the snippet of the code which I have written to achieve this:
import click
...
1
vote
1answer
34 views
Use Mypy with Ruamel.yaml
I am attempting to use MyPy with modules that use ruamel.yaml and Mypy cannot find ruamel.yaml even though Python has no problem finding it. I am puzzled because I can't find a module called YAML.py ...
1
vote
1answer
108 views
Preserve CommentedSeq flow_style after in-place assignment
I would like to assign new values to a CommentedSeq object in place to preserve its flow style. However, such an operation leads to TypeError: '<' not supported between instances of 'slice' and '...
1
vote
1answer
35 views
Using ruamel.yaml to print out a list with individual elements singlequoted?
I have a dictionary with a few lists(contains a # of strings).
Example List:
hosts = ['199.168.1.100:1000', '199.168.1.101:1000']
When I try to print this out using ruamel.yaml, the elements show ...
1
vote
1answer
73 views
get comment during iteration in ruamel.yaml
How can I get the comments when I iterate through the YAML object
yaml = YAML()
with open(path, 'r') as f:
yaml_data = yaml.load(f)
for obj in yaml_data:
# how to get the comments here?
...
1
vote
1answer
33 views
How to do round trip yaml while preserving tags without defining constructors
I'm trying to format YAML code without modifying comments, anchors and tags (basically take arbitrary YAML code and force particular indentation and other formatting conventions). To do this, I'm ...
1
vote
1answer
150 views
Dump OrderedDict in a more concise way
I have a YAML document in a file that I need to update with some structured
information, that I get from a library. The order in which keys from this information are dumped is important.
The YAML ...
1
vote
1answer
144 views
Installing GNU Radio using PyBOMBS
I am following the installation instructions on https://github.com/gnuradio/pybombs.
I get the following error message:
→ sudo -H pybombs prefix init ~/prefix -a myprefix -R gnuradio-default
PyBOMBS....
2
votes
1answer
40 views
Updating a yaml file with the contents of another one
Setup:
I have two YAML files: one huge with tags and aliases, and the other one small with some key value pairs from the big one. I'm using python2.7.
Problem:
I want to update values in the big one ...
2
votes
1answer
137 views
Trying to import 'ruamel.yaml' lib results in 'ImportError: No module named ruamel.yaml' Error
I ran a
pip install ruamel.yaml
and when I try to do
import ruamel.yaml
I get an error:
ImportError: No module named ruamel.yaml
python 2.7,
Output of my pip 'freeze':
nose==1.3.7
numpy==1.12....
0
votes
2answers
57 views
How to install ruamel.yaml on a buildroot environment
ruamel.yaml seems to require PIP to install, which is not the default buildroot solution to build and install a Python package.
Is is possible to -at least- install a pure Python version of ruamel....
1
vote
3answers
135 views
Strings containing “ - ” always break onto newline with ruamel.yaml
I'm fairly new to YAML, within a Python 3.7 project, and decided to use ruamel.yaml to get me started. I intend to use it to store metadata associated with some video files.
I am creating YAML files ...
1
vote
2answers
141 views
When ruamel.yaml loads @dataclass from string, __post_init__ is not called
Assume I created a @dataclass class Foo, and added a __post_init__ to perform type checking and processing.
When I attempt to yaml.load a !Foo object, __post_init__ is not called.
from dataclasses ...
0
votes
1answer
63 views
Duplication between YAML.register_class() and yaml_object(yml)()?
While researching ruamel.yaml (https://yaml.readthedocs.io/en/latest/dumpcls.html), I noticed that registering a class can be done using either YAML.register_class() or @yaml_object(yaml). ...
0
votes
1answer
111 views
How to recursively sort YAML using CommentedMap?
There's a good example of sorting at the top level, but how would you recurse the sort at all levels?
This seems to work:
def sort_commentedmap(self, od):
res = ruamel.yaml.comments....
1
vote
1answer
93 views
How to suppress automatic quoting of strings with ruamel.yaml
I am using ruamel.yaml to generate "recipes" for a build tool, which accepts a non-standard superset of yaml. I'm getting some undesirable output, and my searches for how to disable this have come up ...
2
votes
1answer
137 views
ruamel.yaml: clarification on typ and pure=True
I am trying to understand what typ and pure=True mean in the ruamel.yaml Python library.
I've read the documentation here.
So far, I've understood that typ='safe' uses a safe loader which omits YAML ...
0
votes
0answers
165 views
Loading Duplicate Keys in Ruamel Yaml
I want to load duplicate keys in Ruamel Yaml. I have a requirement though. I have to use CLOADER given the huge size of my input load file. Hence I need a Loading Hack to load duplicate keys and their ...
0
votes
1answer
124 views
ruamel - block_seq_indent and indent
I have been struggling with getting my YAML file with correct indentation after using yaml.round_trip_dump. I am trying to figure what is the difference between block_seq_indent and indent. Couldn't ...
1
vote
1answer
53 views
ruamel.yaml.round_trip_dump expected 4 but found 2 (indentation)
Code:
#!/usr/bin/env python2
import sys
import ruamel.yaml
yaml_str = '''
---
project: ''
project_lead: &ptl
name: ''
company: ''
email: ''
id: ''
timezone: ''
...
1
vote
1answer
69 views
Using ruamel.yaml to keep multline strings with same indentation Python
I am trying to make up some YAML files and I am struggling to get the YAML files in a correct format. I am trying to get the strings of the values all be on the same indentation but I cannot seem to ...
1
vote
1answer
80 views
How to install ruamel.yaml w/o native extension
I'd like to install ruamel.yaml on an environment which does not have a compiler, and I do not care about the performances.
What is the proper way to install ruamel.yaml w/o pip trying to build the ...
1
vote
2answers
292 views
Python ruamel.yaml dumps tags with quotes
I'm trying to use ruamel.yaml to modify an AWS CloudFormation template on the fly using python. I added the following code to make the safe_load working with CloudFormation functions such as !Ref. ...