rapidyaml 0.0.post2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rapidyaml-0.0.post2/LICENSE.txt +20 -0
- rapidyaml-0.0.post2/MANIFEST.in +36 -0
- rapidyaml-0.0.post2/Makefile +105 -0
- rapidyaml-0.0.post2/PKG-INFO +366 -0
- rapidyaml-0.0.post2/README.md +343 -0
- rapidyaml-0.0.post2/changelog/current.md +5 -0
- rapidyaml-0.0.post2/cpp/CMakeLists.txt +176 -0
- rapidyaml-0.0.post2/cpp/CONTRIBUTING.md +18 -0
- rapidyaml-0.0.post2/cpp/LICENSE.txt +20 -0
- rapidyaml-0.0.post2/cpp/README.md +842 -0
- rapidyaml-0.0.post2/cpp/api/CMakeLists.txt +172 -0
- rapidyaml-0.0.post2/cpp/api/ryml.i +1043 -0
- rapidyaml-0.0.post2/cpp/cmake/uninstall.cmake +24 -0
- rapidyaml-0.0.post2/cpp/compat.cmake +11 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/CMakeLists.txt +152 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/LICENSE-BOOST.txt +26 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/LICENSE.txt +20 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/README.md +389 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/ConfigurationTypes.cmake +120 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/CreateSourceGroup.cmake +31 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/Doxyfile.full.in +2566 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/Doxyfile.in +2566 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/ExternalProjectUtils.cmake +215 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/FindD3D12.cmake +75 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/FindDX12.cmake +76 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/GetFlags.cmake +53 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/GetNames.cmake +51 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/LICENSE.txt +20 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/PVS-Studio.cmake +275 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/PatchUtils.cmake +25 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/PrintVar.cmake +27 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/README.md +25 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/TargetArchitecture.cmake +188 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/Toolchain-Arm-ubuntu.cmake +29 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/Toolchain-Armv7.cmake +84 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/Toolchain-PS4.cmake +73 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/Toolchain-XBoxOne.cmake +93 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/amalgamate_utils.py +230 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/c4CatSources.cmake +105 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/c4Doxygen.cmake +128 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/c4DoxygenConfig.cmake +24 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/c4GetTargetPropertyRecursive.cmake +186 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/c4Project.cmake +3803 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/c4StaticAnalysis.cmake +161 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/c4stlAddTarget.cmake +5 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/compat/c4/gcc-4.8.hpp +72 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/compat/gtest_gcc-4.8.patch +97 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/cmake/requirements_doc.txt +3 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/compat.cmake +16 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/allocator.hpp +409 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/base64.cpp +226 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/base64.hpp +141 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/bitmask.hpp +339 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/blob.hpp +72 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/c4_pop.hpp +19 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/c4_push.hpp +37 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/c4core.natvis +168 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/char_traits.cpp +10 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/char_traits.hpp +98 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/charconv.hpp +2673 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/common.hpp +14 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/compiler.hpp +120 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/config.hpp +38 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/cpu.hpp +205 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/ctor_dtor.hpp +464 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/dump.hpp +838 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/enum.hpp +283 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/error.cpp +237 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/error.hpp +437 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/export.hpp +18 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/ext/debugbreak/COPYING +23 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/ext/debugbreak/GNUmakefile +28 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/ext/debugbreak/HOW-TO-USE-DEBUGBREAK-GDB-PY.md +33 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/ext/debugbreak/README.md +127 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/ext/debugbreak/debugbreak-gdb.py +183 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/ext/debugbreak/debugbreak.h +175 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/ext/fast_float.hpp +39 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/ext/fast_float_all.h +4885 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/ext/rng/rng.hpp +205 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/ext/sg14/README.md +1 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/ext/sg14/inplace_function.h +356 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/format.cpp +64 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/format.hpp +1058 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/gcc-4.8.hpp +72 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/hash.hpp +98 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/language.cpp +17 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/language.hpp +372 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/memory_resource.cpp +340 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/memory_resource.hpp +562 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/memory_util.cpp +34 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/memory_util.hpp +783 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/platform.hpp +46 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/preprocessor.hpp +123 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/restrict.hpp +51 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/span.hpp +529 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/std/span.hpp +121 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/std/span_fwd.hpp +82 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/std/std.hpp +12 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/std/std_fwd.hpp +11 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/std/string.hpp +90 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/std/string_fwd.hpp +59 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/std/string_view.hpp +67 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/std/tuple.hpp +184 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/std/vector.hpp +92 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/std/vector_fwd.hpp +70 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/substr.hpp +2349 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/substr_fwd.hpp +18 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/szconv.hpp +69 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/type_name.hpp +127 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/types.hpp +507 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/unrestrict.hpp +17 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/utf.cpp +114 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/utf.hpp +73 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/version.cpp +25 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/version.hpp +22 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/windows.hpp +10 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/windows_pop.hpp +41 -0
- rapidyaml-0.0.post2/cpp/ext/c4core/src/c4/windows_push.hpp +102 -0
- rapidyaml-0.0.post2/cpp/ext/testbm.cmake +4 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/common.cpp +314 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/common.hpp +625 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/detail/checks.hpp +200 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/detail/dbgprint.hpp +125 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/detail/print.hpp +183 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/detail/stack.hpp +294 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/emit.def.hpp +1563 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/emit.hpp +1061 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/error.def.hpp +386 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/error.hpp +765 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/escape_scalar.hpp +202 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/event_handler_stack.hpp +195 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/event_handler_tree.hpp +793 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/export.hpp +18 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/filter_processor.hpp +540 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/fwd.hpp +24 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/node.cpp +30 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/node.hpp +1673 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/node_type.cpp +228 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/node_type.hpp +281 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/parse.cpp +146 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/parse.hpp +324 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/parse_engine.def.hpp +8361 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/parse_engine.hpp +756 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/parser_state.hpp +193 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/preprocess.cpp +113 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/preprocess.hpp +97 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/reference_resolver.cpp +329 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/reference_resolver.hpp +88 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/std/map.hpp +46 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/std/std.hpp +8 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/std/string.hpp +9 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/std/vector.hpp +59 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/tag.cpp +322 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/tag.hpp +83 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/tree.cpp +2024 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/tree.hpp +1549 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/version.cpp +27 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/version.hpp +25 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/writer.hpp +194 -0
- rapidyaml-0.0.post2/cpp/src/c4/yml/yml.hpp +16 -0
- rapidyaml-0.0.post2/cpp/src/ryml-gdbtypes.py +391 -0
- rapidyaml-0.0.post2/cpp/src/ryml.hpp +11 -0
- rapidyaml-0.0.post2/cpp/src/ryml.natvis +304 -0
- rapidyaml-0.0.post2/cpp/src/ryml_std.hpp +6 -0
- rapidyaml-0.0.post2/cpp/src_extra/c4/yml/extra/event_handler_ints.cpp +100 -0
- rapidyaml-0.0.post2/cpp/src_extra/c4/yml/extra/event_handler_ints.hpp +1376 -0
- rapidyaml-0.0.post2/cpp/src_extra/c4/yml/extra/event_handler_testsuite.cpp +48 -0
- rapidyaml-0.0.post2/cpp/src_extra/c4/yml/extra/event_handler_testsuite.hpp +859 -0
- rapidyaml-0.0.post2/cpp/src_extra/c4/yml/extra/ints_to_testsuite.cpp +207 -0
- rapidyaml-0.0.post2/cpp/src_extra/c4/yml/extra/ints_to_testsuite.hpp +69 -0
- rapidyaml-0.0.post2/cpp/src_extra/c4/yml/extra/ints_utils.cpp +131 -0
- rapidyaml-0.0.post2/cpp/src_extra/c4/yml/extra/ints_utils.hpp +38 -0
- rapidyaml-0.0.post2/cpp/src_extra/c4/yml/extra/string.hpp +421 -0
- rapidyaml-0.0.post2/pyproject.toml +30 -0
- rapidyaml-0.0.post2/requirements.txt +8 -0
- rapidyaml-0.0.post2/setup.cfg +4 -0
- rapidyaml-0.0.post2/setup.py +144 -0
- rapidyaml-0.0.post2/src/rapidyaml.egg-info/PKG-INFO +366 -0
- rapidyaml-0.0.post2/src/rapidyaml.egg-info/SOURCES.txt +182 -0
- rapidyaml-0.0.post2/src/rapidyaml.egg-info/dependency_links.txt +1 -0
- rapidyaml-0.0.post2/src/rapidyaml.egg-info/requires.txt +1 -0
- rapidyaml-0.0.post2/src/rapidyaml.egg-info/top_level.txt +1 -0
- rapidyaml-0.0.post2/src/ryml/__init__.py +2 -0
- rapidyaml-0.0.post2/src/ryml/version.py +34 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2018, Joao Paulo Magalhaes <dev@jpmag.me>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the "Software"),
|
|
5
|
+
to deal in the Software without restriction, including without limitation
|
|
6
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
7
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
|
8
|
+
Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included
|
|
11
|
+
in all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
14
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
18
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
19
|
+
DEALINGS IN THE SOFTWARE.
|
|
20
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# MANIFEST.in must be in root directory.
|
|
2
|
+
# See https://github.com/pypa/setuptools/issues/2615
|
|
3
|
+
# examples: https://www.reddit.com/r/Python/comments/40s8qw/simplify_your_manifestin_commands/
|
|
4
|
+
|
|
5
|
+
prune .github
|
|
6
|
+
prune bm/
|
|
7
|
+
graft cpp
|
|
8
|
+
prune cpp/.github
|
|
9
|
+
prune cpp/.gitignore
|
|
10
|
+
prune cpp/.gitmodules
|
|
11
|
+
prune cpp/bm
|
|
12
|
+
prune cpp/changelog
|
|
13
|
+
prune cpp/doc
|
|
14
|
+
prune cpp/ext/c4core/.github
|
|
15
|
+
prune cpp/ext/c4core/bm
|
|
16
|
+
prune cpp/ext/c4core/changelog
|
|
17
|
+
prune cpp/ext/c4core/cmake/bm-xp/
|
|
18
|
+
prune cpp/ext/c4core/src/c4/ext/fast_float/
|
|
19
|
+
prune cpp/ext/c4core/src/c4/ext/debugbreak/test/
|
|
20
|
+
prune cpp/ext/c4core/doc
|
|
21
|
+
prune cpp/ext/c4core/test
|
|
22
|
+
prune cpp/ext/c4core/tools
|
|
23
|
+
prune cpp/img
|
|
24
|
+
prune cpp/samples
|
|
25
|
+
prune cpp/test
|
|
26
|
+
prune cpp/tools
|
|
27
|
+
prune test/
|
|
28
|
+
|
|
29
|
+
global-exclude *tbump.toml
|
|
30
|
+
global-exclude *.clang-tidy
|
|
31
|
+
global-exclude *.git
|
|
32
|
+
global-exclude *.gitignore
|
|
33
|
+
global-exclude *.gitmodules
|
|
34
|
+
global-exclude *.lgtm.yml
|
|
35
|
+
global-exclude *.readthedocs.yaml
|
|
36
|
+
global-exclude *ROADMAP.md
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
# Use bash even on Windows
|
|
5
|
+
SHELL := /bin/bash
|
|
6
|
+
|
|
7
|
+
PACKAGE_NAME = rapidyaml
|
|
8
|
+
PYPI_TEST_USER = jpmag
|
|
9
|
+
# PYPI_TEST = --repository-url https://test.pypi.org/legacy/
|
|
10
|
+
PYPI_TEST = --repository testpypi
|
|
11
|
+
|
|
12
|
+
# On Windows the activate script is stored in a different location.
|
|
13
|
+
ACTIVATE_SCRIPT := venv/bin/activate
|
|
14
|
+
ifeq ($(OS),Windows_NT)
|
|
15
|
+
ACTIVATE_SCRIPT := venv/Scripts/activate
|
|
16
|
+
endif
|
|
17
|
+
|
|
18
|
+
# How to invoke python
|
|
19
|
+
PYTHON := python
|
|
20
|
+
# How to invoke pytest
|
|
21
|
+
PYTEST := $(PYTHON) -m pytest -vvv -s
|
|
22
|
+
|
|
23
|
+
ACTIVATE = [[ -e $(ACTIVATE_SCRIPT) ]] && source $(ACTIVATE_SCRIPT);
|
|
24
|
+
|
|
25
|
+
.PHONY: all
|
|
26
|
+
all: build
|
|
27
|
+
|
|
28
|
+
.PHONY: upload-test
|
|
29
|
+
upload-test: $(ACTIVATE_SCRIPT)
|
|
30
|
+
$(MAKE) clean
|
|
31
|
+
$(MAKE) build-sdist
|
|
32
|
+
${ACTIVATE} twine upload ${PYPI_TEST} dist/*
|
|
33
|
+
|
|
34
|
+
.PHONY: upload
|
|
35
|
+
upload: $(ACTIVATE_SCRIPT)
|
|
36
|
+
$(MAKE) clean
|
|
37
|
+
$(MAKE) build-sdist
|
|
38
|
+
${ACTIVATE} twine upload --verbose dist/*
|
|
39
|
+
|
|
40
|
+
# testpypi accumulates test releases and regularly reaches the 10GB
|
|
41
|
+
# size limit; use this target to clear the test releases
|
|
42
|
+
# see:
|
|
43
|
+
# https://pypi.org/project/pypi-cleanup/
|
|
44
|
+
.PHONY: clear_testpypi
|
|
45
|
+
clear-testpypi: $(ACTIVATE_SCRIPT)
|
|
46
|
+
${ACTIVATE} pypi-cleanup -t https://test.pypi.org -u $(PYPI_TEST_USER) -p $(PACKAGE_NAME) --leave-most-recent-only --do-it --yes
|
|
47
|
+
|
|
48
|
+
.PHONY: clean
|
|
49
|
+
clean:
|
|
50
|
+
rm -rvf dist *.egg-info
|
|
51
|
+
rm -rvf build .egg*
|
|
52
|
+
rm -rvf ryml/*.so ryml/ryml.py ryml/include ryml/lib
|
|
53
|
+
|
|
54
|
+
.PHONY: venv-clean
|
|
55
|
+
venv-clean:
|
|
56
|
+
rm -rf venv
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
$(ACTIVATE_SCRIPT): requirements.txt Makefile
|
|
60
|
+
make venv
|
|
61
|
+
@touch $(ACTIVATE_SCRIPT)
|
|
62
|
+
|
|
63
|
+
.PHONY: venv
|
|
64
|
+
venv:
|
|
65
|
+
virtualenv --python=python3 --always-copy venv
|
|
66
|
+
# Packaging tooling.
|
|
67
|
+
${ACTIVATE} pip install -U pip
|
|
68
|
+
# Setup requirements.
|
|
69
|
+
${ACTIVATE} pip install -v -r requirements.txt
|
|
70
|
+
|
|
71
|
+
.PHONY: build-sdist
|
|
72
|
+
build-sdist: | $(ACTIVATE_SCRIPT)
|
|
73
|
+
${ACTIVATE} pip show build
|
|
74
|
+
${ACTIVATE} $(PYTHON) -m build --sdist --outdir $(PWD)/dist
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
.PHONY: build-wheel
|
|
78
|
+
build-wheel: | $(ACTIVATE_SCRIPT)
|
|
79
|
+
rm -rf dist
|
|
80
|
+
$(MAKE) build-sdist
|
|
81
|
+
@ls -l dist/*.tar.gz
|
|
82
|
+
${ACTIVATE} pip wheel -v dist/*.tar.gz --wheel-dir $(PWD)/dist
|
|
83
|
+
|
|
84
|
+
.PHONY: build
|
|
85
|
+
build: build-sdist build-wheel
|
|
86
|
+
|
|
87
|
+
.PHONY: check
|
|
88
|
+
check: | $(ACTIVATE_SCRIPT)
|
|
89
|
+
$(MAKE) clean
|
|
90
|
+
$(MAKE) build-wheel
|
|
91
|
+
${ACTIVATE} twine check dist/*.whl
|
|
92
|
+
|
|
93
|
+
.PHONY: install
|
|
94
|
+
install: | $(ACTIVATE_SCRIPT)
|
|
95
|
+
${ACTIVATE} $(PYTHON) setup.py install
|
|
96
|
+
|
|
97
|
+
.PHONY: test
|
|
98
|
+
test: | $(ACTIVATE_SCRIPT)
|
|
99
|
+
${ACTIVATE} pip install -v -e .
|
|
100
|
+
${ACTIVATE} $(PYTHON) -c "from ryml.version import version as v; print('Installed version:', v)"
|
|
101
|
+
${ACTIVATE} $(PYTEST) test
|
|
102
|
+
|
|
103
|
+
.PHONY: version
|
|
104
|
+
version: | $(ACTIVATE_SCRIPT)
|
|
105
|
+
${ACTIVATE} $(PYTHON) setup.py --version
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rapidyaml
|
|
3
|
+
Version: 0.0.post2
|
|
4
|
+
Summary: Parse and emit YAML, and do it fast. Python wrapper for the C++ library
|
|
5
|
+
Home-page: https://github.com/biojppm/rapidyaml-python
|
|
6
|
+
Author: Joao Paulo Magalhaes
|
|
7
|
+
Author-email: Joao Paulo Magalhaes <dev@jpmag.me>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/biojppm/rapidyaml-python
|
|
10
|
+
Project-URL: Issues, https://github.com/biojppm/rapidyaml-python/issues
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.6
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE.txt
|
|
16
|
+
Requires-Dist: deprecation
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: home-page
|
|
19
|
+
Dynamic: license
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
Dynamic: requires-dist
|
|
22
|
+
Dynamic: requires-python
|
|
23
|
+
|
|
24
|
+
# Rapid YAML - Python package
|
|
25
|
+
|
|
26
|
+
[](https://github.com/biojppm/rapidyaml/blob/master/LICENSE.txt)
|
|
27
|
+
[](https://pypi.org/project/rapidyaml/)
|
|
28
|
+
|
|
29
|
+
Or ryml, for short. ryml is [a C++ library to parse and emit
|
|
30
|
+
YAML](https://github.com/biojppm/rapidyaml), and do it fast, on
|
|
31
|
+
everything from x64 to bare-metal chips without operating system. This
|
|
32
|
+
repo contains the rapidyaml python package, which was previously in
|
|
33
|
+
the original repo (up to [release 0.11.0](https://github.com/biojppm/rapidyaml/releases/tag/v0.11.0)).
|
|
34
|
+
|
|
35
|
+
This python wrapper exposes only the index-based low-level C++ API,
|
|
36
|
+
which works with node indices and string views. This API is blazing
|
|
37
|
+
fast, but you may find it hard to use: it does not build a python
|
|
38
|
+
structure of dicts/seqs/scalars (that's up to you), and all the
|
|
39
|
+
scalars are untyped strings. With that said, it is really fast,
|
|
40
|
+
and once you have the tree you can still walk over the tree to create
|
|
41
|
+
the native python structure.
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Performance
|
|
46
|
+
|
|
47
|
+
Here are some results for a [timeit benchmark](bm/bm_parse.py)
|
|
48
|
+
comparing ryml against [PyYaml](https://pyyaml.org/) and
|
|
49
|
+
[ruamel.yaml](https://yaml.readthedocs.io/en/latest/) (and note you
|
|
50
|
+
can use this script with your YAML files!). ryml parses quicker by
|
|
51
|
+
generally 100x and up to 400x:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
+----------------------------------------+-------+----------+----------+-----------+
|
|
55
|
+
| style_seqs_blck_outer1000_inner100.yml | count | time(ms) | avg(ms) | avg(MB/s) |
|
|
56
|
+
+----------------------------------------+-------+----------+----------+-----------+
|
|
57
|
+
| parse:RuamelYamlParse | 1 | 4564.812 | 4564.812 | 0.173 |
|
|
58
|
+
| parse:PyYamlParse | 1 | 2815.426 | 2815.426 | 0.280 |
|
|
59
|
+
| parse:RymlParseInArena | 38 | 588.024 | 15.474 | 50.988 |
|
|
60
|
+
| parse:RymlParseInArenaReuse | 38 | 466.997 | 12.289 | 64.202 |
|
|
61
|
+
| parse:RymlParseInPlace | 38 | 579.770 | 15.257 | 51.714 |
|
|
62
|
+
| parse:RymlParseInPlaceReuse | 38 | 462.932 | 12.182 | 64.765 |
|
|
63
|
+
+----------------------------------------+-------+----------+----------+-----------+
|
|
64
|
+
```
|
|
65
|
+
(Note that the parse timings above are somewhat biased towards ryml, because
|
|
66
|
+
it does not perform any type conversions in Python-land: return types
|
|
67
|
+
are merely `memoryviews` to the source buffer, possibly copied to the tree's
|
|
68
|
+
arena).
|
|
69
|
+
|
|
70
|
+
As for emitting, the improvement can be as high as 3000x:
|
|
71
|
+
```
|
|
72
|
+
+----------------------------------------+-------+-----------+-----------+-----------+
|
|
73
|
+
| style_maps_blck_outer1000_inner100.yml | count | time(ms) | avg(ms) | avg(MB/s) |
|
|
74
|
+
+----------------------------------------+-------+-----------+-----------+-----------+
|
|
75
|
+
| emit_yaml:RuamelYamlEmit | 1 | 18149.288 | 18149.288 | 0.054 |
|
|
76
|
+
| emit_yaml:PyYamlEmit | 1 | 2683.380 | 2683.380 | 0.365 |
|
|
77
|
+
| emit_yaml:RymlEmitToNewBuffer | 88 | 861.726 | 9.792 | 99.976 |
|
|
78
|
+
| emit_yaml:RymlEmitReuse | 88 | 437.931 | 4.976 | 196.725 |
|
|
79
|
+
+----------------------------------------+-------+-----------+-----------+-----------+
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
## Examples
|
|
84
|
+
|
|
85
|
+
### Parsing a file
|
|
86
|
+
|
|
87
|
+
Here's a quick example (this is a unit test at [test/test_ex_read.py](test/test_ex_read.py)):
|
|
88
|
+
|
|
89
|
+
```yaml
|
|
90
|
+
import ryml
|
|
91
|
+
|
|
92
|
+
def test_read_yaml():
|
|
93
|
+
yaml = b"{HELLO: a, foo: b, bar: c, baz: d, seq: [0, 1, 2, 3]}"
|
|
94
|
+
|
|
95
|
+
# ryml holds only views to the parsed yaml source (following the C++ library).
|
|
96
|
+
#
|
|
97
|
+
# parse_in_place() parses directly the input buffer,
|
|
98
|
+
# so this requires the user to keep the input buffer
|
|
99
|
+
# alive while using the tree.
|
|
100
|
+
#
|
|
101
|
+
# parse_in_arena() copies the input buffer to
|
|
102
|
+
# an arena in the tree, then parses the copy.
|
|
103
|
+
# This is safer, so let's use it here:
|
|
104
|
+
tree = ryml.parse_in_arena(yaml)
|
|
105
|
+
|
|
106
|
+
# The returned tree has the following structure:
|
|
107
|
+
#
|
|
108
|
+
# [node 0] root, map
|
|
109
|
+
# ` [node 1] "HELLO": "a"
|
|
110
|
+
# ` [node 2] "foo": "b"
|
|
111
|
+
# ` [node 3] "bar": "c"
|
|
112
|
+
# ` [node 4] "baz": "d"
|
|
113
|
+
# ` [node 5] "seq":
|
|
114
|
+
# ` [node 6] "0"
|
|
115
|
+
# ` [node 7] "1"
|
|
116
|
+
# ` [node 8] "2"
|
|
117
|
+
# ` [node 9] "3"
|
|
118
|
+
#
|
|
119
|
+
# let's now do some assertions (keeping this structure in mind):
|
|
120
|
+
assert tree.size() == 10
|
|
121
|
+
assert tree.root_id() == 0
|
|
122
|
+
assert tree.is_root(0)
|
|
123
|
+
assert tree.is_map(0)
|
|
124
|
+
assert tree.is_keyval(1)
|
|
125
|
+
assert tree.is_seq(5)
|
|
126
|
+
assert tree.is_val(6)
|
|
127
|
+
# use bytes or str objects for queries
|
|
128
|
+
assert tree.find_child(0, b"HELLO") == 1
|
|
129
|
+
assert tree.find_child(0, "HELLO") == 1
|
|
130
|
+
assert tree.find_child(0, b"foo") == 2
|
|
131
|
+
assert tree.find_child(0, "foo") == 2
|
|
132
|
+
assert tree.find_child(0, b"seq") == 5
|
|
133
|
+
assert tree.find_child(0, "seq") == 5
|
|
134
|
+
assert tree.key(1) == b"HELLO"
|
|
135
|
+
assert tree.val(1) == b"a"
|
|
136
|
+
assert tree.key(2) == b"foo"
|
|
137
|
+
assert tree.val(2) == b"b"
|
|
138
|
+
assert tree.find_child(0, b"seq") == 5
|
|
139
|
+
assert tree.find_child(0, "seq") == 5
|
|
140
|
+
# hierarchy:
|
|
141
|
+
assert tree.first_child(0) == 1
|
|
142
|
+
assert tree.last_child(0) == 5
|
|
143
|
+
assert tree.next_sibling(1) == 2
|
|
144
|
+
assert tree.first_sibling(5) == 1
|
|
145
|
+
assert tree.last_sibling(1) == 5
|
|
146
|
+
assert tree.first_child(5) == 6
|
|
147
|
+
assert tree.last_child(5) == 9
|
|
148
|
+
# to loop over children:
|
|
149
|
+
expected = [b"0", b"1", b"2", b"3"]
|
|
150
|
+
for i, ch in enumerate(ryml.children(tree, 5)):
|
|
151
|
+
assert tree.val(ch) == expected[i]
|
|
152
|
+
# to loop over siblings:
|
|
153
|
+
expected = [b"HELLO", b"foo", b"bar", b"baz", b"seq"]
|
|
154
|
+
for i, sib in enumerate(ryml.siblings(tree, 5)):
|
|
155
|
+
assert tree.key(sib) == expected[i]
|
|
156
|
+
# to walk over all elements
|
|
157
|
+
visited = [False] * tree.size()
|
|
158
|
+
for node_id, indentation_level in ryml.walk(tree):
|
|
159
|
+
visited[node_id] = True
|
|
160
|
+
assert False not in visited
|
|
161
|
+
# NOTE about encoding!
|
|
162
|
+
k = tree.key(5)
|
|
163
|
+
assert isinstance(k, memoryview)
|
|
164
|
+
#print(k) # '<memory at 0x7f80d5b93f48>'
|
|
165
|
+
assert k == b"seq" # ok, as expected
|
|
166
|
+
assert k != "seq" # not ok - NOTE THIS!
|
|
167
|
+
assert str(k) != "seq" # not ok
|
|
168
|
+
assert str(k, "utf8") == "seq" # ok again
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
### Creating and emitting a tree
|
|
173
|
+
|
|
174
|
+
Here are some examples on how to create trees programatically (this is a unit test at [test/test_ex_write.py](test/test_ex_write.py)):
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
import ryml
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
# all the tests below create this tree
|
|
181
|
+
expected_yaml = '{HELLO: a,foo: b,bar: c,baz: d,seq: [0,1,2,3]}'
|
|
182
|
+
expected_json = '{"HELLO": "a","foo": "b","bar": "c","baz": "d","seq": [0,1,2,3]}'
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
# helper to create map children nodes
|
|
186
|
+
def _append_keyval(tree: ryml.Tree, node_id: int, key, val, flags=0):
|
|
187
|
+
child_id = tree.append_child(node_id)
|
|
188
|
+
tree.to_keyval(child_id, key, val, flags)
|
|
189
|
+
return child_id
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
# helper to create seq children nodes
|
|
193
|
+
def _append_val(tree: ryml.Tree, node_id: int, val, flags=0):
|
|
194
|
+
child_id = tree.append_child(node_id)
|
|
195
|
+
tree.to_val(child_id, val, flags)
|
|
196
|
+
return child_id
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def test_create_tree():
|
|
200
|
+
tree = ryml.Tree()
|
|
201
|
+
root_id = tree.root_id()
|
|
202
|
+
tree.to_map(root_id, ryml.FLOW_SL) # set the root node as a map,
|
|
203
|
+
# with FLOW_SL style (flow, single line)
|
|
204
|
+
_append_keyval(tree, root_id, "HELLO", "a")
|
|
205
|
+
_append_keyval(tree, root_id, "foo", "b")
|
|
206
|
+
_append_keyval(tree, root_id, "bar", "c")
|
|
207
|
+
_append_keyval(tree, root_id, "baz", "d")
|
|
208
|
+
seq_id = tree.append_child(root_id)
|
|
209
|
+
tree.to_seq(seq_id, "seq", ryml.FLOW_SL) # append a sequence
|
|
210
|
+
_append_val(tree, seq_id, "0")
|
|
211
|
+
_append_val(tree, seq_id, "1")
|
|
212
|
+
_append_val(tree, seq_id, "2")
|
|
213
|
+
_append_val(tree, seq_id, "3")
|
|
214
|
+
# check that this tree is emitted as expected
|
|
215
|
+
_check_emits(tree)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
# BEWARE! The tree is pointing at the memory of the scalars!
|
|
219
|
+
#
|
|
220
|
+
# If you are using dynamic strings for scalars, you must be sure to
|
|
221
|
+
# hold onto them while using the tree!
|
|
222
|
+
#
|
|
223
|
+
# Because explicitly managing lifetimes is generally hard or
|
|
224
|
+
# cumbersome to do in python, ryml provides you a tree.to_arena()
|
|
225
|
+
# helper to do this: it copies the scalar to the tree's arena, which
|
|
226
|
+
# will fix any lifetime issues.
|
|
227
|
+
#
|
|
228
|
+
# Here's an example:
|
|
229
|
+
def test_create_tree_dynamic():
|
|
230
|
+
# let's now programmatically create the same tree as above:
|
|
231
|
+
tree = ryml.Tree()
|
|
232
|
+
root_id = tree.root_id()
|
|
233
|
+
tree.to_map(root_id, ryml.FLOW_SL) # set the root node as a map,
|
|
234
|
+
# with FLOW_SL style (flow, single line)
|
|
235
|
+
# utility function to create a dynamic string and store it in the tree:
|
|
236
|
+
def ds(s: str):
|
|
237
|
+
# make a dynamic copy (using f-string to force creation a
|
|
238
|
+
# different string object)
|
|
239
|
+
dyn = f"_{s}_"[1:-1]
|
|
240
|
+
# ...serialize the copy in the tree's arena
|
|
241
|
+
saved = tree.to_arena(dyn)
|
|
242
|
+
return saved
|
|
243
|
+
# now we use ds() with each scalar, making it safer
|
|
244
|
+
_append_keyval(tree, root_id, ds("HELLO"), ds("a"))
|
|
245
|
+
_append_keyval(tree, root_id, ds("foo"), ds("b"))
|
|
246
|
+
_append_keyval(tree, root_id, ds("bar"), ds("c"))
|
|
247
|
+
_append_keyval(tree, root_id, ds("baz"), ds("d"))
|
|
248
|
+
seq_id = tree.append_child(root_id)
|
|
249
|
+
tree.to_seq(seq_id, ds("seq"), ryml.FLOW_SL) # append a sequence
|
|
250
|
+
_append_val(tree, seq_id, ds("0"))
|
|
251
|
+
_append_val(tree, seq_id, ds("1"))
|
|
252
|
+
_append_val(tree, seq_id, ds("2"))
|
|
253
|
+
_append_val(tree, seq_id, ds("3"))
|
|
254
|
+
# check that this tree is emitted as expected
|
|
255
|
+
_check_emits(tree)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
# But note you don't need to use tree.to_arena(); you can save the
|
|
259
|
+
# dynamic scalars for example by keeping them in a tree. But then you
|
|
260
|
+
# must take care of the lifetimes!
|
|
261
|
+
#
|
|
262
|
+
# Here's an example:
|
|
263
|
+
def test_create_tree_dynamic_explicit_save():
|
|
264
|
+
# let's now programmatically create the same tree as above:
|
|
265
|
+
tree = ryml.Tree()
|
|
266
|
+
root_id = tree.root_id()
|
|
267
|
+
tree.to_map(root_id, ryml.FLOW_SL) # set the root node as a map,
|
|
268
|
+
# with FLOW_SL style (flow, single line)
|
|
269
|
+
# this time we'll use a list to save the scalars. It works because
|
|
270
|
+
# both `tree` and `saved_scalars` are defined and used in the same
|
|
271
|
+
# scope. But it would fail if `saved_scalars` went out of scope
|
|
272
|
+
# before ending the use of `tree`, eg if tree was returned from
|
|
273
|
+
# this function but `saved_scalars` were not.
|
|
274
|
+
saved_scalars = []
|
|
275
|
+
# utility function to create a dynamic string and store it:
|
|
276
|
+
def ds(s: str):
|
|
277
|
+
# make a dynamic copy (using f-string to force creation a
|
|
278
|
+
# different string object)
|
|
279
|
+
dyn = f"_{s}_"[1:-1]
|
|
280
|
+
# save the string in the list
|
|
281
|
+
saved_scalars.append(dyn)
|
|
282
|
+
return dyn
|
|
283
|
+
# now we use ds() with each scalar, making it safer
|
|
284
|
+
_append_keyval(tree, root_id, ds("HELLO"), ds("a"))
|
|
285
|
+
_append_keyval(tree, root_id, ds("foo"), ds("b"))
|
|
286
|
+
_append_keyval(tree, root_id, ds("bar"), ds("c"))
|
|
287
|
+
_append_keyval(tree, root_id, ds("baz"), ds("d"))
|
|
288
|
+
seq_id = tree.append_child(root_id)
|
|
289
|
+
tree.to_seq(seq_id, ds("seq"), ryml.FLOW_SL) # append a sequence
|
|
290
|
+
_append_val(tree, seq_id, ds("0"))
|
|
291
|
+
_append_val(tree, seq_id, ds("1"))
|
|
292
|
+
_append_val(tree, seq_id, ds("2"))
|
|
293
|
+
_append_val(tree, seq_id, ds("3"))
|
|
294
|
+
# check that this tree is emitted as expected
|
|
295
|
+
_check_emits(tree)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def test_create_tree_bytes():
|
|
299
|
+
# ryml also works with bytes scalars
|
|
300
|
+
tree = ryml.Tree()
|
|
301
|
+
root_id = tree.root_id()
|
|
302
|
+
tree.to_map(root_id, ryml.FLOW_SL) # set the root node as a map,
|
|
303
|
+
# with FLOW_SL style (flow, single line)
|
|
304
|
+
_append_keyval(tree, root_id, b"HELLO", b"a")
|
|
305
|
+
_append_keyval(tree, root_id, b"foo", b"b")
|
|
306
|
+
_append_keyval(tree, root_id, b"bar", b"c")
|
|
307
|
+
_append_keyval(tree, root_id, b"baz", b"d")
|
|
308
|
+
seq_id = tree.append_child(root_id)
|
|
309
|
+
tree.to_seq(seq_id, b"seq", ryml.FLOW_SL) # append a sequence
|
|
310
|
+
_append_val(tree, seq_id, b"0")
|
|
311
|
+
_append_val(tree, seq_id, b"1")
|
|
312
|
+
_append_val(tree, seq_id, b"2")
|
|
313
|
+
_append_val(tree, seq_id, b"3")
|
|
314
|
+
# check that this tree is emitted as expected
|
|
315
|
+
_check_emits(tree)
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def test_create_tree_memoryview():
|
|
319
|
+
# ryml also works with memoryview scalars
|
|
320
|
+
tree = ryml.Tree()
|
|
321
|
+
root_id = tree.root_id()
|
|
322
|
+
tree.to_map(root_id, ryml.FLOW_SL) # set the root node as a map,
|
|
323
|
+
# with FLOW_SL style (flow, single line)
|
|
324
|
+
def s(scalar: bytes):
|
|
325
|
+
return memoryview(scalar)
|
|
326
|
+
_append_keyval(tree, root_id, s(b"HELLO"), s(b"a"))
|
|
327
|
+
_append_keyval(tree, root_id, s(b"foo"), s(b"b"))
|
|
328
|
+
_append_keyval(tree, root_id, s(b"bar"), s(b"c"))
|
|
329
|
+
_append_keyval(tree, root_id, s(b"baz"), s(b"d"))
|
|
330
|
+
seq_id = tree.append_child(root_id)
|
|
331
|
+
tree.to_seq(seq_id, s(b"seq"), ryml.FLOW_SL) # append a sequence
|
|
332
|
+
_append_val(tree, seq_id, s(b"0"))
|
|
333
|
+
_append_val(tree, seq_id, s(b"1"))
|
|
334
|
+
_append_val(tree, seq_id, s(b"2"))
|
|
335
|
+
_append_val(tree, seq_id, s(b"3"))
|
|
336
|
+
# check that this tree is emitted as expected
|
|
337
|
+
_check_emits(tree)
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
# this function shows several different ways of emitting from an
|
|
341
|
+
# existing tree (and tests that the results are as expected).
|
|
342
|
+
def _check_emits(tree: ryml.Tree):
|
|
343
|
+
# emit_yaml() and emit_json() return a str object
|
|
344
|
+
out_yaml = ryml.emit_yaml(tree)
|
|
345
|
+
out_json = ryml.emit_json(tree)
|
|
346
|
+
assert isinstance(out_yaml, str)
|
|
347
|
+
assert isinstance(out_json, str)
|
|
348
|
+
assert out_yaml == expected_yaml
|
|
349
|
+
assert out_json == expected_json
|
|
350
|
+
# if it is really important, you can emit to existing buffers:
|
|
351
|
+
len_yaml = ryml.compute_yaml_length(tree) #
|
|
352
|
+
len_json = ryml.compute_json_length(tree)
|
|
353
|
+
buf_yaml = bytearray(len_yaml)
|
|
354
|
+
buf_json = bytearray(len_json)
|
|
355
|
+
out_yaml = ryml.emit_yaml_in_place(tree, buf_yaml)
|
|
356
|
+
out_json = ryml.emit_json_in_place(tree, buf_json)
|
|
357
|
+
assert isinstance(out_yaml, memoryview)
|
|
358
|
+
assert isinstance(out_json, memoryview)
|
|
359
|
+
assert out_yaml.tobytes().decode('utf8') == expected_yaml
|
|
360
|
+
assert out_json.tobytes().decode('utf8') == expected_json
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
------
|
|
364
|
+
## License
|
|
365
|
+
|
|
366
|
+
ryml is permissively licensed under the [MIT license](LICENSE.txt).
|