mk-fg / pretty-yaml Goto Github PK
View Code? Open in Web Editor NEWPyYAML-based module to produce a bit more pretty and readable YAML-serialized data
License: Do What The F*ck You Want To Public License
PyYAML-based module to produce a bit more pretty and readable YAML-serialized data
License: Do What The F*ck You Want To Public License
I wrote a simple wrapper around the yaml library that gives me some additional features:
#
characters (could be comment or a URL anchor)I use it for loading configuration files for my systems. Comments are really helpful for admins who run these systems, as the config file also acts as a source of documentation.
Basically, it is the same philosophy, but aimed at the opposite end - reading YAML files written in a humane fashion.
Would you agree with adding this relaxed reading feature to this module? Here's a draft: ralienpp@cd7de49
Currently, pyaml.dump
defaults to safe=False
. Maybe it could be changed to safe=True
by default (security by default)?
Would there be any noticeable difference from that and do you think safe=True
would limit normal use cases?
If you disagree with changing the default, maybe the docs can be updated to use the safe=True
where possible?
See also: Make load safe_load
Thanks for your nice library!
Given the following test yaml:
# This is a commented YAML file
replica: 1
image:
repository: docker/python
pull: IfNotPresent
imagePullSecrets:
- name: docker-secret
and the following test python:
#!/usr/bin/env python3
from pathlib import Path
import pyaml
from ruamel.yaml import YAML
yaml = YAML()
test_file = Path("./test.yaml")
test_load = yaml.load(test_file)
pyaml.p(test_load)
I get the following error:
Traceback (most recent call last):
File "./test_yaml.py", line 9, in <module>
pyaml.p(test_load)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyaml/__init__.py", line 208, in pprint
dump(data, dst=dst, **dump_kws)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyaml/__init__.py", line 188, in dump
yaml.dump_all( data, buff, Dumper=Dumper,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/yaml/__init__.py", line 278, in dump_all
dumper.represent(data)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/yaml/representer.py", line 27, in represent
node = self.represent_data(data)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/yaml/representer.py", line 58, in represent_data
node = self.yaml_representers[None](self, data)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyaml/__init__.py", line 37, in represent_undefined
elif isinstance(data, OrderedDict): return dumper.represent_odict(data)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyaml/__init__.py", line 29, in represent_odict
node_value = dumper.represent_data(item_value)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/yaml/representer.py", line 58, in represent_data
node = self.yaml_representers[None](self, data)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyaml/__init__.py", line 40, in represent_undefined
return super(PrettyYAMLDumper, dumper).represent_undefined(data)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/yaml/representer.py", line 231, in represent_undefined
raise RepresenterError("cannot represent an object", data)
yaml.representer.RepresenterError: ('cannot represent an object', [ordereddict([('name', 'docker-secret')])])
Given that ruamel is mentioned in the docs for parsing, pyaml should be able to handle the results.
The problem is likely that ruamel creates and uses it's own subclass of OrderedDict:
https://sourceforge.net/p/ruamel-yaml/code/ci/default/tree/constructor.py#l20
https://sourceforge.net/p/ruamel-yaml/code/ci/default/tree/compat.py#l23
pyaml could do something like:
try:
from ruamel.yaml.compat import ordereddict
PrettyYAMLDumper.add_representer(ordereddict, PrettyYAMLDumper.represent_odict)
except ImportError:
pass
Hello.
Your lib uses pyyaml==4.2b4
But it raises a warning in Python 3.7
File "/Users/myrik/.local/share/virtualenvs/esentai-e7Q7McuI/lib/python3.7/site-packages/yaml/__init__.py", line 72, in load
return loader.get_single_data()
File "/Users/myrik/.local/share/virtualenvs/esentai-e7Q7McuI/lib/python3.7/site-packages/yaml/constructor.py", line 37, in get_single_data
return self.construct_document(node)
File "/Users/myrik/.local/share/virtualenvs/esentai-e7Q7McuI/lib/python3.7/site-packages/yaml/constructor.py", line 46, in construct_document
for dummy in generator:
File "/Users/myrik/.local/share/virtualenvs/esentai-e7Q7McuI/lib/python3.7/site-packages/yaml/constructor.py", line 398, in construct_yaml_map
value = self.construct_mapping(node)
File "/Users/myrik/.local/share/virtualenvs/esentai-e7Q7McuI/lib/python3.7/site-packages/yaml/constructor.py", line 204, in construct_mapping
return super().construct_mapping(node, deep=deep)
File "/Users/myrik/.local/share/virtualenvs/esentai-e7Q7McuI/lib/python3.7/site-packages/yaml/constructor.py", line 126, in construct_mapping
if not isinstance(key, collections.Hashable):
File "/Users/myrik/.local/share/virtualenvs/esentai-e7Q7McuI/lib/python3.7/collections/__init__.py", line 52, in __getattr__
DeprecationWarning, stacklevel=2)
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
Hi!
I have some OpenAPI schema definition, that I'm extracting via ApiSpec.
---
x-extension: value
post:
# headline/name of the resource
operationId: users create
summary: Register user
description: |
Imagine all the users living for today
Imagine there's no countries
It isn't hard to do
Nothing to kill or die for
And no religion too
Imagine all the users living life in peace, you
You may say I'm a dreamer
But I'm not the only one
I hope some day you'll join us
And the world will be as one
security:
- APIKeyHeader: []
# this will appear as grouping in the left-side menu
tags:
- Legacy API
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
description: Foo bar
required: true
schema:
$ref: '#/components/schemas/FooBodySchema'
Apispec is doing all the heavy lifting, but I changed the yaml library to pretty-yaml to get rid of the Python type hints.
Given the yaml above, how can I accomplish to receive multiline blocks as a block
description: |
Imagine all the users living for today
Imagine there's no countries
It isn't hard to do
Nothing to kill or die for
And no religion too
and
have single line Strings quoted
schema:
$ref: '#/components/schemas/FooBodySchema'
Currently I'm using
pyaml.dump(my_spec, safe=True, force_embed=False, vspacing=[2, 1], string_val_style='"')
which unfortunately puts the mutline Strings in simple quotes as well.
Thank you :)
In [7]: pyaml.pprint("a")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-768996862cc6> in <module>()
----> 1 pyaml.pprint("a")
/Users/aaronmeurer/Documents/pretty-yaml/pyaml/__init__.py in pprint(*data, **dump_kws)
169 dst = dump_kws.pop('file', dump_kws.pop('dst', sys.stdout))
170 if len(data) == 1: data, = data
--> 171 dump(data, dst=dst, **dump_kws)
172
173 p, _p = pprint, print
/Users/aaronmeurer/Documents/pretty-yaml/pyaml/__init__.py in dump(data, dst, safe, force_embed, vspacing, string_val_style)
161 return buff.getvalue().decode('utf-8')
162 else:
--> 163 dst.write(buff.getvalue())
164
165 def dumps(data, **dump_kws):
TypeError: must be str, not bytes
For escaped input such as
"|\U000F1988\U0002CB8D\U0003176D\xA2\U000E5BCA\xEC\xCB": "\U0001C716\U000E5AE3\x92\
d\x8C\xD9"
which PYYaml does parse.
pretty-yaml produces unescaped output, ie.:
T2�xx.?¯¬: y𭀟Ê�
which PYYaml does not parse.
There is tiny incompatibility with PyYAML:
PyYAML: dump(data, stream=None, ...)
https://github.com/yaml/pyyaml/blob/main/lib/yaml/__init__.py#L248
pretty-yaml: dump(data, dst=None, ...)
https://github.com/mk-fg/pretty-yaml/blob/master/pyaml/__init__.py#L164
As a result:
>>> yaml.dump({}, stream=sys.stdout)
{}
>>> pyaml.dump({}, stream=sys.stdout)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/xxx/.local/lib/python3.10/site-packages/pyaml/__init__.py", line 181, in dump
yaml.dump_all( data, buff, Dumper=Dumper,
TypeError: dump_all() got multiple values for argument 'stream'
I want to force dumping literal for certain string values (aka http://stackoverflow.com/questions/6432605/any-yaml-libraries-in-python-that-support-dumping-of-long-strings-as-block-liter ).
How can I do this with pyaml?
[And thanks for pyaml, it makes much much readable data]
Real simple example:
import pyaml
class Car:
def __init__(self):
self.make = 'Honda'
car = Car()
pyaml.dump(car)
Output:
RepresenterError: ('cannot represent an object', <__main__.Car object at 0x7fe5f1af0c10>)
tested pyaml.dump(car.__dict__)
works fine
tested import yaml; yaml.dump(car)
works fine. output:
'!!python/object:__main__.Car\nmake: Honda\n
(this is the output I would expect...)
What am I missing?
The dict are sorted on dump... but there should be three cases: python2 and python3 until 3.5 should sort. 3.6 and up are ordered dicts by default, so they should NOT be sorted by default anymore IMHO.
I think it may be as simple as replacing a few {foo, bar}
s with set(foo, bar)
- is there any reason why 2.6 isn't supported? As it is, means any project relying on pretty-yaml
has to be 2.7+ also.
>>> print pyaml.dump({'a': 'asldnsa\nasldknsa\n'})
a: |
asldnsa
asldknsa
>>> print pyaml.dump({'a': u'asldnsa\nasldpáknsa\n'})
a: "asldnsa\nasldp\xE1knsa\n"
I tried to read the source and inspect it, but couldn't figure out where is the problem.
Is this solvable? If I know all the values I'm trying to print are UTF-8 strings, not bytes or anything else, is it possible to patch pyaml to allow me to print them beautifully? How?
Using dump with safe set to True causes an error
...
File ".../lib/python2.7/site-packages/pyaml/__init__.py", line 135, in dump
yaml.dump_all([data], buff, Dumper=Dumper, default_flow_style=False, encoding='utf-8')
File ".../lib/python2.7/site-packages/yaml/__init__.py", line 186, in dump_all
explicit_start=explicit_start, explicit_end=explicit_end)
TypeError: __init__() got an unexpected keyword argument 'force_embed'
I tried to apply the formatter to an OpenAPI spec, (ex1.
It appears to me that after running python -m pyaml -r ./juice_users/openapi/openapi.yaml
, the spec is broken and cannot be used anymore with the OpenAPI generator.
Is there something I could do to prevent breaking my spec file?
Given the data:
{'foo': ['bar:', 'baz']}
pyaml serializes this as:
foo:
- bar:
- baz
which then gets deserialized by yaml as:
{'foo': [{'bar': None}, 'baz']}
This is different to the original data. I'm not sure if this is a problem with pyaml, yaml, or something else. The problem is fixed by forcing quotes around "bar:" in the output:
foo:
- "bar:"
- baz
This can be achieved by:
pyaml.dump(data, stream, string_val_style="double-quoted")
Sample code to reproduce the problem:
import yaml
import pyaml
import StringIO
data = {"foo": ["bar:", "baz"]}
print data
stream = StringIO.StringIO()
pyaml.dump(data, stream)
print stream.getvalue()
data2 = yaml.load(stream.getvalue())
print data2
from pyaml import dumps
with open("foobar.yaml", "w") as f2:
x = {}
x["y"] = []
x["y"].append("0.5.1")
x["y"].append("0.51")
x["y"].append("0.7.1")
print(dumps(x, safe=True, indent=1).decode('utf-8'), file=f2)
makes...
y:
- 0.5.1
- '0.51'
- 0.7.1
But it is not clear why one of the list entries is in quotes and the others not.
I just almost started fixing "Quote strings that start with [" but noticed it's been merged as #17 about 6 months ago.
Short-term I can pip-install from source, but could you please release a version with that fix?
Thanks!
Hey hey,
This thing is pretty sweet. I like the fix for the max iterations. Do you think you could push it back up to the package index?
Thanks,
Josh
On Python 3.11, the test suite fails with the 23.5.7 release:
_________________________________________________________ DumpTests.test_enum _________________________________________________________
self = <pyaml.tests.test_dump.DumpTests testMethod=test_enum>
def test_enum(self):
c = test_const.heartbeat
d1 = {'a': c, 'b': c.value, c: 'testx'}
self.assertEqual(d1['a'], d1['b'])
s = pyaml.dump(d1)
d2 = yaml.safe_load(s)
self.assertEqual(d1['a'], d2['a'])
self.assertEqual(d1['a'], c)
self.assertEqual(d1[c], 'testx')
> self.assertIn('a: 123 # test_const.heartbeat', s)
E AssertionError: 'a: 123 # test_const.heartbeat' not found in 'a: 123 # 123\nb: 123\n123: testx\n'
pyaml/tests/test_dump.py:399: AssertionError
The test passes on Python 3.10.
Hi,
Great project....
Just wanted to check if there is a way to input a file, prettify it and then write back to the same file?
Thanks
AWS CloudFormation templates now support YAML, and we're converting a lot of JSON using pyaml and enjoy it, but for one thing:
"Value": {
"Fn::Join": [
"",
[
"apac-",
{
"Ref": "Environment"
},
"-",
{
"Ref": "EnvironmentName"
},
"-",
Here is what the above translates to (via print pyaml.dump(json.load(sys.stdin))):
Value:
Fn::Join:
-
- - apac-
- Ref: Environment
- -
- Ref: EnvironmentName
- -
There are two problems. The first, we need an empty string as the value after "Fn::Join". This may not be a problem with YAML, but AWS won't accept it-- it would be nice to have an option to print empty strings.
The second I think may be a bug-- the lines that read "- -" need the second dash in quotes to clarify that it's not a YAML formatting mark, but actually content.
To use these, we have to manually change to the following:
Value:
Fn::Join:
- ''
- - apac-
- Ref: Environment
- '-'
- Ref: EnvironmentName
- '-'
So, recently I've tried this module to generate .yml files and came across an issue. If a line starts with a percentage sign, then this line ends up unquotted in the generated .yml file:
hello: %world
The problem occurs when you try to load it with yaml.safe_load()
which results in:
found character '%' that cannot start any token
I'm really not sure if it is supposed to be like that (bug or feature?), because I'm not really familiar with this format yet and there might be different specifications, but if former then all we need to change is add % in this line, I think.
Hi,
Using Pip, the pyaml fails to install on Windows 10 with Python 3.6. But if I use Python 3.5, the installation works fine.
> python -m pip install pyaml
Collecting pyaml
Using cached pyaml-17.8.0-py2.py3-none-any.whl
Collecting PyYAML (from pyaml)
Using cached PyYAML-3.12.tar.gz
Building wheels for collected packages: PyYAML
Running setup.py bdist_wheel for PyYAML ... error
Complete output from command C:\Users\code\venv36\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\code\\AppData\\Local\\Temp\\pip-build-pq03dgna\\PyYAML\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\code\AppData\Local\Temp\tmp0t79bxfmpip-wheel- --python-tag cp36:
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\yaml
copying lib3\yaml\composer.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\constructor.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\cyaml.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\dumper.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\emitter.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\error.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\events.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\loader.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\nodes.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\parser.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\reader.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\representer.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\resolver.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\scanner.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\serializer.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\tokens.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\__init__.py -> build\lib.win-amd64-3.6\yaml
running build_ext
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
checking if libyaml is compilable
error: [WinError 3] The system cannot find the path specified: 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\PlatformSDK\\lib'
----------------------------------------
Failed building wheel for PyYAML
Running setup.py clean for PyYAML
Failed to build PyYAML
Installing collected packages: PyYAML, pyaml
Running setup.py install for PyYAML ... error
Complete output from command C:\Users\\code\\venv36\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\code\\AppData\\Local\\Temp\\pip-build-pq03dgna\\PyYAML\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\code\AppData\Local\Temp\pip-pezzmj2e-record\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\code\venv36\include\site\python3.6\PyYAML:
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\yaml
copying lib3\yaml\composer.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\constructor.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\cyaml.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\dumper.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\emitter.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\error.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\events.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\loader.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\nodes.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\parser.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\reader.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\representer.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\resolver.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\scanner.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\serializer.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\tokens.py -> build\lib.win-amd64-3.6\yaml
copying lib3\yaml\__init__.py -> build\lib.win-amd64-3.6\yaml
running build_ext
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
checking if libyaml is compilable
error: [WinError 3] The system cannot find the path specified: 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\PlatformSDK\\lib'
----------------------------------------
Command "C:\Users\code\venv36\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\code\\AppData\\Local\\Temp\\pip-build-pq03dgna\\PyYAML\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\code\AppData\Local\Temp\pip-pezzmj2e-record\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\code\venv36\include\site\python3.6\PyYAML" failed with error code 1 in C:\Users\code\AppData\Local\Temp\pip-build-pq03dgna\PyYAML\
To ensure compatibility with lower versions of Python, please avoid using the ":=" operator in your project, as it is only available in Python 3.8 and higher versions. Please, consider alternative methods to achieve the desired functionality.
I am using pyaml formatter with Neoformater in Neo Vim.
This is my docker-compose.yml
before formatting:
version: 3
services:
web:
build: .
ports:
- 3000:3000
After formatting:
services:
web:
build: .
ports:
- 3000:3000
version: 3
Is there a way for me to prevent it from ordering my keys in alphabet order?
When trying to build 23.5.9, the build installs an empty directory with just an UNKNOWN-0.0.0-py3.10.egg-info
subdir.
On macOS (though this shouldn't matter):
$ /sw/bin/python3.10 setup.py build
running build
$ PYTHONPATH=/sw/build.build/pyaml-py310-23.5.9-1/pyaml-23.5.9/build/lib /sw/bin/python3.10 -m unittest || exit 2
......................
----------------------------------------------------------------------
Ran 22 tests in 0.125s
OK
$ /sw/bin/python3.10 setup.py install --root=/sw/build.build/root-pyaml-py310-23.5.9-1
running install
/sw/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
running build
running install_egg_info
running egg_info
creating UNKNOWN.egg-info
writing UNKNOWN.egg-info/PKG-INFO
writing dependency_links to UNKNOWN.egg-info/dependency_links.txt
writing top-level names to UNKNOWN.egg-info/top_level.txt
writing manifest file 'UNKNOWN.egg-info/SOURCES.txt'
reading manifest file 'UNKNOWN.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
adding license file 'COPYING'
writing manifest file 'UNKNOWN.egg-info/SOURCES.txt'
Copying UNKNOWN.egg-info to /sw/build.build/root-pyaml-py310-23.5.9-1/sw/lib/python3.10/site-packages/UNKNOWN-0.0.0-py3.10.egg-info
running install_scripts
The commands finish cleanly, but the installation directory is empty except for those files inside the UNKNOWN.egg-info directory.
I've also tried with a build
based process, but the results are the same.
pyaml-21.10.1 built and installed fine w/ a full tree.
I am trying to dump a dictionary with a numpy array. It works with yaml
package, but fails here with pyaml
:
dd = dict(a="b", b="c", c=(0,1,2), d= np.r_[4,5,6])
print(yaml.dump(dd, default_flow_style=False))
print("-"*20)
print(pyaml.dump(dd))
...
/usr/local/lib/python3.6/site-packages/pyaml/__init__.py in represent_undefined(dumper, data)
34 elif isinstance(data, OrderedDict): return dumper.represent_odict(data)
35 elif isinstance(data, dict): return dumper.represent_dict(data)
---> 36 return super(PrettyYAMLDumper, dumper).represent_undefined(data)
37
38 def serialize_node(self, node, parent, index):
/usr/local/lib/python3.6/site-packages/yaml/representer.py in represent_undefined(self, data)
227
228 def represent_undefined(self, data):
--> 229 raise RepresenterError("cannot represent an object: %s" % data)
230
231 SafeRepresenter.add_representer(type(None),
RepresenterError: cannot represent an object: [4 5 6]
For example:
(ae.venv)bash-3.2$ python
Python 2.7.12 (default, Nov 7 2016, 14:33:03)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyaml
>>> pyaml.dump({"foo": "1"})
u'foo: 1\n'
Is this intended behavior? The problem is that the data we read back from this sort of YAML is different to what was written.
Are concatenated yaml docs supported? I know that pyyaml
supports them being delimited by three dashes, but I couldn't figure out if this is supported by looking at pretty-yaml's docs.
I can install PyYAML and pyaml but only PyYAML works.
Here I install PyYAML
(vi_sys_pkgs)$ pip install PyYAML
.. ,, ..
.. ,, .. lots of output with warnings but ..
Successfully installed PyYAML
Cleaning up...
PyYAML WORKS
(vi1)$ python3 -c 'import yaml'
(vi1)$ # no output
At this point 'yaml' works when used in python.
Now for pyaml ..
(vi_sys_pkgs)$ pip install pyaml
Downloading/unpacking pyaml
Downloading pyaml-13.07.1.tar.gz
Running setup.py egg_info for package pyaml
Requirement already satisfied (use --upgrade to upgrade): PyYAML in ./lib/python3.3/site-packages (from pyaml)
Installing collected packages: pyaml
Running setup.py install for pyaml
Successfully installed pyaml
Cleaning up...
pyaml DOES NOT WORK
(vi1)$ python3 -c 'import pyaml'
Traceback (most recent call last):
File "", line 1, in
File "/adp/wd/vi1/lib/python3.3/site-packages/pyaml/init.py", line 9, in
def dump(data, dst=unicode, safe=False, force_embed=False, vspacing=None):
NameError: name 'unicode' is not defined
Do you know what may be wrong here?
x = {'a':['hello world', 'hi']}
print(pyaml.dump(x, string_val_style='plain'))
outputs
a:
- 'hello world'
- hi
whereas I was expecting
a:
- hello world
- hi
From the documentation:
Attempt is made to pick more readable string representation styles, depending on the value
It would be nice if the user could provide as an option what the default maxwidth of a line should be. Peeking at the code this seems to be fixed to a constant, aka 120 chars, however in plenty of cases it is desirable to have a different maximum width (my terminal might be smaller or larger).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.