pyyaml

Cygwin - How to install ansible?

杀马特。学长 韩版系。学妹 提交于 2019-12-02 23:59:19
How to get / install ansible using Cygwin? I tried the following steps but it's didn't work during bullet 5 (while running " python setup.py install "). Steps taken from: Taken from https://servercheck.in/blog/running-ansible-within-windows 1) Download and install Cygwin, with at least the following packages selected (you can select the packages during the install process): libyaml libyaml-devel curl python (2.7.x) python-crypto python-openssl python-paramiko python-setuptools git (2.1.x) vim openssh openssl openssl-devel 2) Download and install PyYAML and Jinja2, as they're not available via

pyyaml: dumping without tags

こ雲淡風輕ζ 提交于 2019-12-02 16:04:29
I have >>> import yaml >>> yaml.dump(u'abc') "!!python/unicode 'abc'\n" But I want >>> import yaml >>> yaml.dump(u'abc', magic='something') 'abc\n' What magic param forces no tagging? You can use safe_dump instead of dump . Just keep in mind that it won't be able to represent arbitrary Python objects then. Also, when you load the YAML, you will get a str object instead of unicode . How about this: def unicode_representer(dumper, uni): node = yaml.ScalarNode(tag=u'tag:yaml.org,2002:str', value=uni) return node yaml.add_representer(unicode, unicode_representer) This seems to make dumping unicode

New PyYAML version breaks on most custom python objects - RepresenterError

早过忘川 提交于 2019-12-02 01:35:04
问题 About 5 hours ago, version 4.1.0 was released. It is breaking my unit tests. Here is a clean MVCE displaying this: Version 3.12: >>> import numpy as np >>> import yaml >>> x = np.int64(2) >>> yaml.dump(x, Dumper=yaml.Dumper) '!!python/object/apply:numpy.core.multiarray.scalar\n- !!python/object/apply:numpy.dtype\n args: [i8, 0, 1]\n state: !!python/tuple [3, <, null, null, null, -1, -1, 0]\n- !!binary |\n AgAAAAAAAAA=\n' Version 4.1.0 : >>> import numpy as np >>> import yaml >>> x = np.int64

New PyYAML version breaks on most custom python objects - RepresenterError

偶尔善良 提交于 2019-12-01 23:42:47
About 5 hours ago, version 4.1.0 was released. It is breaking my unit tests. Here is a clean MVCE displaying this: Version 3.12: >>> import numpy as np >>> import yaml >>> x = np.int64(2) >>> yaml.dump(x, Dumper=yaml.Dumper) '!!python/object/apply:numpy.core.multiarray.scalar\n- !!python/object/apply:numpy.dtype\n args: [i8, 0, 1]\n state: !!python/tuple [3, <, null, null, null, -1, -1, 0]\n- !!binary |\n AgAAAAAAAAA=\n' Version 4.1.0 : >>> import numpy as np >>> import yaml >>> x = np.int64(2) >>> yaml.dump(x, Dumper=yaml.Dumper) Traceback (most recent call last): File "<stdin>", line 1, in

how to keep null value in yaml file while dumping though ruamel.yaml

走远了吗. 提交于 2019-12-01 18:11:32
I have YAML file site.yaml : Kvm_BLOCK: ip_address: 10.X.X.X property: null server_type: zone loaded and then dumped with: ruamel.yaml.dump(site_yaml, new_file, Dumper=ruamel.yaml.RoundTripDumper) it becomes Kvm_BLOCK: ip_address: 10.X.X.X property: server_type: zone how to retain this null value in property block The null value in YAML 1.2 (constructed as Python's None ) can be represented as null , Null , NULL and ~ , as specified here . Additionally : Nodes with empty content are interpreted as if they were plain scalars with an empty value. Such nodes are commonly resolved to a “null”

pyyaml and using quotes for strings only

柔情痞子 提交于 2019-12-01 16:15:19
I have the following YAML file: --- my_vars: my_env: "dev" my_count: 3 When I read it with PyYAML and dump it again, I get the following output: --- my_vars: my_env: dev my_count: 3 The code in question: with open(env_file) as f: env_dict = yaml.load(f) print(yaml.dump(env_dict, indent=4, default_flow_style=False, explicit_start=True)) I tried using the default_style parameter: with open(env_file) as f: env_dict = yaml.load(f) print(yaml.dump(env_dict, indent=4, default_flow_style=False, explicit_start=True, default_style='"')) But now I get: --- "my_vars": "my_env": "dev" "my_count": !!int "3

pyyaml and using quotes for strings only

瘦欲@ 提交于 2019-12-01 15:03:47
问题 I have the following YAML file: --- my_vars: my_env: "dev" my_count: 3 When I read it with PyYAML and dump it again, I get the following output: --- my_vars: my_env: dev my_count: 3 The code in question: with open(env_file) as f: env_dict = yaml.load(f) print(yaml.dump(env_dict, indent=4, default_flow_style=False, explicit_start=True)) I tried using the default_style parameter: with open(env_file) as f: env_dict = yaml.load(f) print(yaml.dump(env_dict, indent=4, default_flow_style=False,

Loading document as raw string in yaml with PyYAML

≡放荡痞女 提交于 2019-12-01 14:41:13
问题 I want to parse yaml documents like the following meta-info-1: val1 meta-info-2: val2 --- Plain text/markdown content! jhaha If I load_all this with PyYAML, I get the following >>> list(yaml.load_all(open('index.yml'))) [{'meta-info-1': 'val1', 'meta-info-2': 'val2'}, 'Plain text/markdown content! jhaha'] What I am trying to achieve here is that the yaml file should contain two documents, and the second one is supposed to be interpreted as a single string document, more specifically any large

YAML key consisting of a list of elements

谁说胖子不能爱 提交于 2019-12-01 14:05:05
I need to have a list of elements as a key, so that I can check if several conditions are met. Example (don't know if this is possible and if the syntax is correct): mapping: c_id: [pak, gb]: '4711' [pak, ch]: '4712' [pak]: '4713' d_id: . . . Now I need to know if it is possible to have an approach as in the example. In addition to Anthon's answer, here is how you can do it with PyYaml: mapping: c_id: !!python/tuple [pak, gb]: '4711' !!python/tuple [pak, ch]: '4712' !!python/tuple [pak]: '4713' The trick is to tell PyYaml that you want to load the keys into a tuple (since a list cannot be used

yaml and jinja2 reader

孤街浪徒 提交于 2019-12-01 11:46:42
I would like to be able to read in python a YAML jinja configuration file like using the PyYAML library but I'm receiving errors: {% set name = "abawaca" %} {% set version = "1.00" %} package: name: {{ name }} version: {{ version }} source: fn: {{ name }}-{{ version }}.tar.gz url: https://github.com/CK7/abawaca/archive/v{{ version }}.tar.gz sha256: 57465bb291c3a9af93605ffb11d704324079036205e5ac279601c9e98c467529 build: number: 0 requirements: build: - gcc # [not osx] - llvm # [osx] Your input is not valid YAML, as you can easily check, e.g. here You should first expand the {% %} constructs,