bkabrda / anymarkup Goto Github PK
View Code? Open in Web Editor NEWParse or serialize any markup in Python
License: BSD 3-Clause "New" or "Revised" License
Parse or serialize any markup in Python
License: BSD 3-Clause "New" or "Revised" License
When I download the tarball on PyPI, the tests won't run:
test/test_parse.py:13: in <module>
class TestParse(object):
test/test_parse.py:34: in TestParse
(example_ini, example_as_dict),
E NameError: name 'example_ini' is not defined
Hashicorp developed HCL as an alternative to JSON and YAML and allows its use with some of their tools. As some of our tools use anymarkup and interact with some Hashicorp tools, I would like anymarkup to support HCL.
IIUC this code should provide basically the same input regarding value types.
import anymarkup
data = anymarkup.parse_file("file.json", force_types=None)
anymarkup.serialize_file(data, "output.json")
But if you feed this file into it:
http://pastebin.centos.org/27686/
you'll get this:
http://pastebin.centos.org/27691/
The change can be seen in env
object:
"env":[
{ "name": "SERVER_ID", "value": "1" }
],
which changes to
"env": [
{
"name": "SERVER_ID",
"value": 1
}
],
Which then fails to load by openshift/kubernetes parser as it expects value
to be a string. I tried to do the same with plain json.load/json.dump
and it preserves types correctly.
This might be part of the yaml spec, I am not sure. When I have a long key name it can end up wrapping like so:
- ? Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
:
Is there any way to keep that as a single line with standard formatting?
Also, is it possible to select the alternate list format?
Currently, A list will serialize into the format:
attributes:
- itemA
- itemB
- itemC
I would like to be able to have it output in the format:
attributes: [itemA, itemB, itemC]
if possible.
Another weird case:
If my key in python is "3'b000 : 0"
, in the yaml serial it is '3''b000 : 0':
The single quoting seems to be a bit odd to me. I am not sure if this is valid or not.
Is there a function / command to be able to actually detect what format the file is in?
Ex.
print anymarkup.format(content)
"json"
EDIT: Just found _guess_fmt_from_bytes ๐ nvm!
For formats where it's possible, we would like to be able to add comments to files generated by anymarkup.
Hi there, first of all thanks much for anymarkup. It's a great module and I'm using it for quite some time in the KIWI
appliance builder project. Recently there was the request to also support the TOML markup for describing an image description. I added a pull request to support this using anymarkup and its toml backend. You can see the open PR here:
As you can see it would add a new python module dependency to the toml
module because that's how anymarkup
implements support for it. It all works nicely but a review comment was made stating that support for TOML has been
split into tomllib
in the Python 3.11+ standard library for reading, and tomlib-w
for writing.
From that perspective I'd like to ask if you would consider to support the new tomllib
implementation as
alternative backend to support TOML with python 3.11+ ?
For us from the KIWI side this would be great as we don't need to add a dependency to the old toml module
and benefit from features of the new tomllib e.g style and comment preserving
Thanks much
It would be nice if anymarkup could load json5.
JSON5 is a proposed extension to JSON that aims to make it easier for humans to write and maintain by hand. It does this by adding some minimal syntax features directly from ECMAScript 5.
https://github.com/json5/json5
Implementation for Python: https://pypi.python.org/pypi/json5
If anymarkup gets a file-like object, it should just read it and then decide on its contents if extension is missing/is uknown.
First of all, i don't need this, I'm just proposing this on the "nice to have" level.
I think it could help anymarkup to gain more glory.
/usr/bin/anymarkup
Reads from stdin or file, outputs to stdout or file. Has --from
and --to
optional format switches, guesses the format otherwise based on file extension and/or provided content. (Actually when writing to stdout, --to
needs to be mandatory).
All the logic is already there, all this needs is a nice entry point and click.
Imagine the glory of this tool, you could do:
curl http://fedora.portingdb.xyz/stats.json | anymarkup --to yaml | anymarkup --to json
I might provide pull request if you approve the idea.
When you run anymarkup on RHEL7, you get following error
'module' object has no attribute 'PY2'
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.