yaml-edit 0.1.0__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.
- yaml_edit-0.1.0/Cargo.lock +233 -0
- yaml_edit-0.1.0/Cargo.toml +17 -0
- yaml_edit-0.1.0/MANIFEST.in +3 -0
- yaml_edit-0.1.0/PKG-INFO +104 -0
- yaml_edit-0.1.0/README.md +86 -0
- yaml_edit-0.1.0/pyproject.toml +36 -0
- yaml_edit-0.1.0/python/yaml_edit/__init__.py +32 -0
- yaml_edit-0.1.0/python/yaml_edit/_yaml_edit.pyi +146 -0
- yaml_edit-0.1.0/python/yaml_edit/py.typed +0 -0
- yaml_edit-0.1.0/python/yaml_edit.egg-info/PKG-INFO +104 -0
- yaml_edit-0.1.0/python/yaml_edit.egg-info/SOURCES.txt +14 -0
- yaml_edit-0.1.0/python/yaml_edit.egg-info/dependency_links.txt +1 -0
- yaml_edit-0.1.0/python/yaml_edit.egg-info/top_level.txt +1 -0
- yaml_edit-0.1.0/setup.cfg +4 -0
- yaml_edit-0.1.0/src/lib.rs +814 -0
- yaml_edit-0.1.0/tests/test_yaml_edit.py +298 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "autocfg"
|
|
7
|
+
version = "1.5.1"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "base64"
|
|
13
|
+
version = "0.22.1"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "cfg-if"
|
|
19
|
+
version = "1.0.4"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "countme"
|
|
25
|
+
version = "3.0.1"
|
|
26
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
+
checksum = "7704b5fdd17b18ae31c4c1da5a2e0305a2bf17b5249300a9ee9ed7b72114c636"
|
|
28
|
+
|
|
29
|
+
[[package]]
|
|
30
|
+
name = "hashbrown"
|
|
31
|
+
version = "0.14.5"
|
|
32
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
33
|
+
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
|
34
|
+
|
|
35
|
+
[[package]]
|
|
36
|
+
name = "heck"
|
|
37
|
+
version = "0.5.0"
|
|
38
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
39
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
40
|
+
|
|
41
|
+
[[package]]
|
|
42
|
+
name = "indoc"
|
|
43
|
+
version = "2.0.7"
|
|
44
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
45
|
+
checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
|
|
46
|
+
dependencies = [
|
|
47
|
+
"rustversion",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[[package]]
|
|
51
|
+
name = "libc"
|
|
52
|
+
version = "0.2.186"
|
|
53
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
54
|
+
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
|
55
|
+
|
|
56
|
+
[[package]]
|
|
57
|
+
name = "memoffset"
|
|
58
|
+
version = "0.9.1"
|
|
59
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
60
|
+
checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
|
|
61
|
+
dependencies = [
|
|
62
|
+
"autocfg",
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
[[package]]
|
|
66
|
+
name = "once_cell"
|
|
67
|
+
version = "1.21.4"
|
|
68
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
69
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
70
|
+
|
|
71
|
+
[[package]]
|
|
72
|
+
name = "portable-atomic"
|
|
73
|
+
version = "1.13.1"
|
|
74
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
75
|
+
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
|
76
|
+
|
|
77
|
+
[[package]]
|
|
78
|
+
name = "proc-macro2"
|
|
79
|
+
version = "1.0.106"
|
|
80
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
81
|
+
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
|
82
|
+
dependencies = [
|
|
83
|
+
"unicode-ident",
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
[[package]]
|
|
87
|
+
name = "pyo3"
|
|
88
|
+
version = "0.23.5"
|
|
89
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
90
|
+
checksum = "7778bffd85cf38175ac1f545509665d0b9b92a198ca7941f131f85f7a4f9a872"
|
|
91
|
+
dependencies = [
|
|
92
|
+
"cfg-if",
|
|
93
|
+
"indoc",
|
|
94
|
+
"libc",
|
|
95
|
+
"memoffset",
|
|
96
|
+
"once_cell",
|
|
97
|
+
"portable-atomic",
|
|
98
|
+
"pyo3-build-config",
|
|
99
|
+
"pyo3-ffi",
|
|
100
|
+
"pyo3-macros",
|
|
101
|
+
"unindent",
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
[[package]]
|
|
105
|
+
name = "pyo3-build-config"
|
|
106
|
+
version = "0.23.5"
|
|
107
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
108
|
+
checksum = "94f6cbe86ef3bf18998d9df6e0f3fc1050a8c5efa409bf712e661a4366e010fb"
|
|
109
|
+
dependencies = [
|
|
110
|
+
"once_cell",
|
|
111
|
+
"target-lexicon",
|
|
112
|
+
]
|
|
113
|
+
|
|
114
|
+
[[package]]
|
|
115
|
+
name = "pyo3-ffi"
|
|
116
|
+
version = "0.23.5"
|
|
117
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
118
|
+
checksum = "e9f1b4c431c0bb1c8fb0a338709859eed0d030ff6daa34368d3b152a63dfdd8d"
|
|
119
|
+
dependencies = [
|
|
120
|
+
"libc",
|
|
121
|
+
"pyo3-build-config",
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
[[package]]
|
|
125
|
+
name = "pyo3-macros"
|
|
126
|
+
version = "0.23.5"
|
|
127
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
128
|
+
checksum = "fbc2201328f63c4710f68abdf653c89d8dbc2858b88c5d88b0ff38a75288a9da"
|
|
129
|
+
dependencies = [
|
|
130
|
+
"proc-macro2",
|
|
131
|
+
"pyo3-macros-backend",
|
|
132
|
+
"quote",
|
|
133
|
+
"syn",
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
[[package]]
|
|
137
|
+
name = "pyo3-macros-backend"
|
|
138
|
+
version = "0.23.5"
|
|
139
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
140
|
+
checksum = "fca6726ad0f3da9c9de093d6f116a93c1a38e417ed73bf138472cf4064f72028"
|
|
141
|
+
dependencies = [
|
|
142
|
+
"heck",
|
|
143
|
+
"proc-macro2",
|
|
144
|
+
"pyo3-build-config",
|
|
145
|
+
"quote",
|
|
146
|
+
"syn",
|
|
147
|
+
]
|
|
148
|
+
|
|
149
|
+
[[package]]
|
|
150
|
+
name = "quote"
|
|
151
|
+
version = "1.0.45"
|
|
152
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
153
|
+
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
|
154
|
+
dependencies = [
|
|
155
|
+
"proc-macro2",
|
|
156
|
+
]
|
|
157
|
+
|
|
158
|
+
[[package]]
|
|
159
|
+
name = "rowan"
|
|
160
|
+
version = "0.16.1"
|
|
161
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
162
|
+
checksum = "417a3a9f582e349834051b8a10c8d71ca88da4211e4093528e36b9845f6b5f21"
|
|
163
|
+
dependencies = [
|
|
164
|
+
"countme",
|
|
165
|
+
"hashbrown",
|
|
166
|
+
"rustc-hash",
|
|
167
|
+
"text-size",
|
|
168
|
+
]
|
|
169
|
+
|
|
170
|
+
[[package]]
|
|
171
|
+
name = "rustc-hash"
|
|
172
|
+
version = "1.1.0"
|
|
173
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
174
|
+
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
|
175
|
+
|
|
176
|
+
[[package]]
|
|
177
|
+
name = "rustversion"
|
|
178
|
+
version = "1.0.22"
|
|
179
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
180
|
+
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
|
181
|
+
|
|
182
|
+
[[package]]
|
|
183
|
+
name = "syn"
|
|
184
|
+
version = "2.0.117"
|
|
185
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
186
|
+
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
|
187
|
+
dependencies = [
|
|
188
|
+
"proc-macro2",
|
|
189
|
+
"quote",
|
|
190
|
+
"unicode-ident",
|
|
191
|
+
]
|
|
192
|
+
|
|
193
|
+
[[package]]
|
|
194
|
+
name = "target-lexicon"
|
|
195
|
+
version = "0.12.16"
|
|
196
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
197
|
+
checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
|
|
198
|
+
|
|
199
|
+
[[package]]
|
|
200
|
+
name = "text-size"
|
|
201
|
+
version = "1.1.1"
|
|
202
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
203
|
+
checksum = "f18aa187839b2bdb1ad2fa35ead8c4c2976b64e4363c386d45ac0f7ee85c9233"
|
|
204
|
+
|
|
205
|
+
[[package]]
|
|
206
|
+
name = "unicode-ident"
|
|
207
|
+
version = "1.0.24"
|
|
208
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
209
|
+
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
|
210
|
+
|
|
211
|
+
[[package]]
|
|
212
|
+
name = "unindent"
|
|
213
|
+
version = "0.2.4"
|
|
214
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
215
|
+
checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
|
|
216
|
+
|
|
217
|
+
[[package]]
|
|
218
|
+
name = "yaml-edit"
|
|
219
|
+
version = "0.2.1"
|
|
220
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
221
|
+
checksum = "5c249044401e064d1f4d7ec0937c343b283e9da13de92298435ff6bf0ad53552"
|
|
222
|
+
dependencies = [
|
|
223
|
+
"base64",
|
|
224
|
+
"rowan",
|
|
225
|
+
]
|
|
226
|
+
|
|
227
|
+
[[package]]
|
|
228
|
+
name = "yaml-edit-py"
|
|
229
|
+
version = "0.1.0"
|
|
230
|
+
dependencies = [
|
|
231
|
+
"pyo3",
|
|
232
|
+
"yaml-edit",
|
|
233
|
+
]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "yaml-edit-py"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
authors = ["Jelmer Vernooij <jelmer@debian.org>"]
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
description = "Python bindings for the yaml-edit lossless YAML parser and editor"
|
|
8
|
+
repository = "https://github.com/jelmer/yaml-edit-py"
|
|
9
|
+
publish = false
|
|
10
|
+
|
|
11
|
+
[lib]
|
|
12
|
+
name = "_yaml_edit"
|
|
13
|
+
crate-type = ["cdylib"]
|
|
14
|
+
|
|
15
|
+
[dependencies]
|
|
16
|
+
pyo3 = { version = "0.23", features = ["extension-module"] }
|
|
17
|
+
yaml-edit = "0.2.1"
|
yaml_edit-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: yaml-edit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lossless YAML parser and editor that preserves formatting, comments, and whitespace
|
|
5
|
+
Author-email: Jelmer Vernooij <jelmer@debian.org>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/jelmer/yaml-edit-py
|
|
8
|
+
Project-URL: Repository, https://github.com/jelmer/yaml-edit-py
|
|
9
|
+
Keywords: yaml,parser,lossless,edit
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Rust
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
15
|
+
Classifier: Topic :: Text Processing :: Markup
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# yaml-edit
|
|
20
|
+
|
|
21
|
+
Python bindings for the [yaml-edit](https://github.com/jelmer/yaml-edit) Rust
|
|
22
|
+
crate: a lossless YAML parser and editor that preserves formatting, comments,
|
|
23
|
+
and whitespace.
|
|
24
|
+
|
|
25
|
+
Unlike most YAML libraries, yaml-edit does not round-trip through a plain data
|
|
26
|
+
model. It keeps the original syntax tree, so edits change only the parts you
|
|
27
|
+
touch and leave everything else - indentation, comment placement, quoting style,
|
|
28
|
+
blank lines - exactly as it was.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```console
|
|
33
|
+
$ pip install yaml-edit
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
A Rust toolchain is required to build from source.
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from yaml_edit import Document
|
|
42
|
+
|
|
43
|
+
doc = Document.parse("name: old-project\nversion: 1.0.0\n")
|
|
44
|
+
doc.set("name", "new-project")
|
|
45
|
+
doc.set("version", "2.0.0")
|
|
46
|
+
print(doc, end="")
|
|
47
|
+
# name: new-project
|
|
48
|
+
# version: 2.0.0
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Edits preserve surrounding formatting and comments:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
doc = Document.parse(
|
|
55
|
+
"# project config\n"
|
|
56
|
+
"name: demo # the name\n"
|
|
57
|
+
"tags:\n"
|
|
58
|
+
" - a\n"
|
|
59
|
+
" - b\n"
|
|
60
|
+
)
|
|
61
|
+
mapping = doc.as_mapping()
|
|
62
|
+
mapping.set("name", "renamed")
|
|
63
|
+
print(doc, end="")
|
|
64
|
+
# # project config
|
|
65
|
+
# name: renamed # the name
|
|
66
|
+
# tags:
|
|
67
|
+
# - a
|
|
68
|
+
# - b
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Working with nested structures:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
doc = Document.parse("servers:\n - web\n - db\n")
|
|
75
|
+
servers = doc.as_mapping().get_sequence("servers")
|
|
76
|
+
servers.push("cache")
|
|
77
|
+
print(doc, end="")
|
|
78
|
+
# servers:
|
|
79
|
+
# - web
|
|
80
|
+
# - db
|
|
81
|
+
# - cache
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Multi-document streams:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from yaml_edit import YamlFile
|
|
88
|
+
|
|
89
|
+
stream = YamlFile.parse("a: 1\n---\nb: 2\n")
|
|
90
|
+
for document in stream.documents():
|
|
91
|
+
print(document.keys())
|
|
92
|
+
# ['a']
|
|
93
|
+
# ['b']
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Supported value types
|
|
97
|
+
|
|
98
|
+
Scalar values passed to `set`, `push`, and `insert` may be `str`, `int`,
|
|
99
|
+
`float`, or `bool`. `None` is rejected because the underlying editor has no way
|
|
100
|
+
to emit a YAML null scalar.
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
Apache-2.0
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# yaml-edit
|
|
2
|
+
|
|
3
|
+
Python bindings for the [yaml-edit](https://github.com/jelmer/yaml-edit) Rust
|
|
4
|
+
crate: a lossless YAML parser and editor that preserves formatting, comments,
|
|
5
|
+
and whitespace.
|
|
6
|
+
|
|
7
|
+
Unlike most YAML libraries, yaml-edit does not round-trip through a plain data
|
|
8
|
+
model. It keeps the original syntax tree, so edits change only the parts you
|
|
9
|
+
touch and leave everything else - indentation, comment placement, quoting style,
|
|
10
|
+
blank lines - exactly as it was.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```console
|
|
15
|
+
$ pip install yaml-edit
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
A Rust toolchain is required to build from source.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from yaml_edit import Document
|
|
24
|
+
|
|
25
|
+
doc = Document.parse("name: old-project\nversion: 1.0.0\n")
|
|
26
|
+
doc.set("name", "new-project")
|
|
27
|
+
doc.set("version", "2.0.0")
|
|
28
|
+
print(doc, end="")
|
|
29
|
+
# name: new-project
|
|
30
|
+
# version: 2.0.0
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Edits preserve surrounding formatting and comments:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
doc = Document.parse(
|
|
37
|
+
"# project config\n"
|
|
38
|
+
"name: demo # the name\n"
|
|
39
|
+
"tags:\n"
|
|
40
|
+
" - a\n"
|
|
41
|
+
" - b\n"
|
|
42
|
+
)
|
|
43
|
+
mapping = doc.as_mapping()
|
|
44
|
+
mapping.set("name", "renamed")
|
|
45
|
+
print(doc, end="")
|
|
46
|
+
# # project config
|
|
47
|
+
# name: renamed # the name
|
|
48
|
+
# tags:
|
|
49
|
+
# - a
|
|
50
|
+
# - b
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Working with nested structures:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
doc = Document.parse("servers:\n - web\n - db\n")
|
|
57
|
+
servers = doc.as_mapping().get_sequence("servers")
|
|
58
|
+
servers.push("cache")
|
|
59
|
+
print(doc, end="")
|
|
60
|
+
# servers:
|
|
61
|
+
# - web
|
|
62
|
+
# - db
|
|
63
|
+
# - cache
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Multi-document streams:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from yaml_edit import YamlFile
|
|
70
|
+
|
|
71
|
+
stream = YamlFile.parse("a: 1\n---\nb: 2\n")
|
|
72
|
+
for document in stream.documents():
|
|
73
|
+
print(document.keys())
|
|
74
|
+
# ['a']
|
|
75
|
+
# ['b']
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Supported value types
|
|
79
|
+
|
|
80
|
+
Scalar values passed to `set`, `push`, and `insert` may be `str`, `int`,
|
|
81
|
+
`float`, or `bool`. `None` is rejected because the underlying editor has no way
|
|
82
|
+
to emit a YAML null scalar.
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
Apache-2.0
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "setuptools-rust>=1.7"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "yaml-edit"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Lossless YAML parser and editor that preserves formatting, comments, and whitespace"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
authors = [{ name = "Jelmer Vernooij", email = "jelmer@debian.org" }]
|
|
13
|
+
keywords = ["yaml", "parser", "lossless", "edit"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Rust",
|
|
19
|
+
"Topic :: Software Development :: Libraries",
|
|
20
|
+
"Topic :: Text Processing :: Markup",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://github.com/jelmer/yaml-edit-py"
|
|
25
|
+
Repository = "https://github.com/jelmer/yaml-edit-py"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.packages.find]
|
|
28
|
+
where = ["python"]
|
|
29
|
+
|
|
30
|
+
[[tool.setuptools-rust.ext-modules]]
|
|
31
|
+
target = "yaml_edit._yaml_edit"
|
|
32
|
+
path = "Cargo.toml"
|
|
33
|
+
binding = "PyO3"
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.package-data]
|
|
36
|
+
yaml_edit = ["py.typed", "*.pyi"]
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Lossless YAML parser and editor.
|
|
2
|
+
|
|
3
|
+
Parse YAML while preserving formatting, comments, and whitespace, then make
|
|
4
|
+
targeted edits that leave the rest of the document untouched.
|
|
5
|
+
|
|
6
|
+
>>> from yaml_edit import Document
|
|
7
|
+
>>> doc = Document.parse("name: old\\nversion: 1.0\\n")
|
|
8
|
+
>>> doc.set("name", "new")
|
|
9
|
+
>>> print(doc, end="")
|
|
10
|
+
name: new
|
|
11
|
+
version: 1.0
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from ._yaml_edit import (
|
|
15
|
+
Document,
|
|
16
|
+
Entry,
|
|
17
|
+
Mapping,
|
|
18
|
+
Node,
|
|
19
|
+
Scalar,
|
|
20
|
+
Sequence,
|
|
21
|
+
YamlFile,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"Document",
|
|
26
|
+
"Entry",
|
|
27
|
+
"Mapping",
|
|
28
|
+
"Node",
|
|
29
|
+
"Scalar",
|
|
30
|
+
"Sequence",
|
|
31
|
+
"YamlFile",
|
|
32
|
+
]
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""Type stubs for the yaml-edit native extension."""
|
|
2
|
+
|
|
3
|
+
from typing import Iterator, Optional, Union
|
|
4
|
+
|
|
5
|
+
ScalarValue = Union[str, int, float, bool]
|
|
6
|
+
|
|
7
|
+
class Node:
|
|
8
|
+
"""A YAML node returned from a getter."""
|
|
9
|
+
|
|
10
|
+
@property
|
|
11
|
+
def kind(self) -> str: ...
|
|
12
|
+
def is_scalar(self) -> bool: ...
|
|
13
|
+
def is_mapping(self) -> bool: ...
|
|
14
|
+
def is_sequence(self) -> bool: ...
|
|
15
|
+
def as_scalar(self) -> Optional[Scalar]: ...
|
|
16
|
+
def as_mapping(self) -> Optional[Mapping]: ...
|
|
17
|
+
def as_sequence(self) -> Optional[Sequence]: ...
|
|
18
|
+
def as_int(self) -> Optional[int]: ...
|
|
19
|
+
def as_float(self) -> Optional[float]: ...
|
|
20
|
+
def as_bool(self) -> Optional[bool]: ...
|
|
21
|
+
def __str__(self) -> str: ...
|
|
22
|
+
|
|
23
|
+
class Scalar:
|
|
24
|
+
"""A scalar YAML value (string, number, boolean)."""
|
|
25
|
+
|
|
26
|
+
def value(self) -> str:
|
|
27
|
+
"""The raw scalar text, preserving any surrounding quotes."""
|
|
28
|
+
|
|
29
|
+
def as_string(self) -> str:
|
|
30
|
+
"""The scalar's value with quotes stripped if present."""
|
|
31
|
+
def is_quoted(self) -> bool: ...
|
|
32
|
+
def unquoted_value(self) -> str: ...
|
|
33
|
+
def is_null(self) -> bool: ...
|
|
34
|
+
def as_int(self) -> Optional[int]: ...
|
|
35
|
+
def as_float(self) -> Optional[float]: ...
|
|
36
|
+
def as_bool(self) -> Optional[bool]: ...
|
|
37
|
+
def set_value(self, value: str) -> None: ...
|
|
38
|
+
def __str__(self) -> str: ...
|
|
39
|
+
|
|
40
|
+
class Entry:
|
|
41
|
+
"""A single key/value entry in a mapping.
|
|
42
|
+
|
|
43
|
+
The fine-grained handle for mappings with repeated keys: each occurrence is
|
|
44
|
+
a distinct entry that can be inspected and mutated individually.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
def key(self) -> Optional[Node]: ...
|
|
48
|
+
def value(self) -> Optional[Node]: ...
|
|
49
|
+
def key_matches(self, key: str) -> bool: ...
|
|
50
|
+
def set_value(self, value: ScalarValue) -> None: ...
|
|
51
|
+
def remove(self) -> None: ...
|
|
52
|
+
|
|
53
|
+
class Mapping:
|
|
54
|
+
"""A YAML mapping (key/value block)."""
|
|
55
|
+
|
|
56
|
+
def __len__(self) -> int: ...
|
|
57
|
+
def is_empty(self) -> bool: ...
|
|
58
|
+
def is_flow_style(self) -> bool: ...
|
|
59
|
+
def contains_key(self, key: str) -> bool: ...
|
|
60
|
+
def __contains__(self, key: str) -> bool: ...
|
|
61
|
+
def get(self, key: str) -> Optional[Node]: ...
|
|
62
|
+
def __getitem__(self, key: str) -> Node: ...
|
|
63
|
+
def get_mapping(self, key: str) -> Optional[Mapping]: ...
|
|
64
|
+
def get_sequence(self, key: str) -> Optional[Sequence]: ...
|
|
65
|
+
def set(self, key: str, value: ScalarValue) -> None: ...
|
|
66
|
+
def __setitem__(self, key: str, value: ScalarValue) -> None: ...
|
|
67
|
+
def remove(self, key: str) -> bool: ...
|
|
68
|
+
def __delitem__(self, key: str) -> None: ...
|
|
69
|
+
def rename_key(self, old_key: str, new_key: str) -> bool: ...
|
|
70
|
+
def clear(self) -> None: ...
|
|
71
|
+
def keys(self) -> list[str]: ...
|
|
72
|
+
def values(self) -> list[Node]: ...
|
|
73
|
+
def items(self) -> list[tuple[str, Node]]: ...
|
|
74
|
+
def __iter__(self) -> Iterator[str]: ...
|
|
75
|
+
def entries(self) -> list[Entry]: ...
|
|
76
|
+
def find_entry(self, key: str) -> Optional[Entry]: ...
|
|
77
|
+
def find_all_entries(self, key: str) -> list[Entry]: ...
|
|
78
|
+
def count_key(self, key: str) -> int: ...
|
|
79
|
+
def remove_nth(self, key: str, n: int) -> bool: ...
|
|
80
|
+
def __str__(self) -> str: ...
|
|
81
|
+
|
|
82
|
+
class Sequence:
|
|
83
|
+
"""A YAML sequence (list)."""
|
|
84
|
+
|
|
85
|
+
def __len__(self) -> int: ...
|
|
86
|
+
def is_empty(self) -> bool: ...
|
|
87
|
+
def is_flow_style(self) -> bool: ...
|
|
88
|
+
def get(self, index: int) -> Optional[Node]: ...
|
|
89
|
+
def __getitem__(self, index: int) -> Node: ...
|
|
90
|
+
def first(self) -> Optional[Node]: ...
|
|
91
|
+
def last(self) -> Optional[Node]: ...
|
|
92
|
+
def push(self, value: ScalarValue) -> None: ...
|
|
93
|
+
def insert(self, index: int, value: ScalarValue) -> None: ...
|
|
94
|
+
def set(self, index: int, value: ScalarValue) -> bool: ...
|
|
95
|
+
def __setitem__(self, index: int, value: ScalarValue) -> None: ...
|
|
96
|
+
def __delitem__(self, index: int) -> None: ...
|
|
97
|
+
def remove(self, index: int) -> Optional[Node]: ...
|
|
98
|
+
def pop(self) -> Optional[Node]: ...
|
|
99
|
+
def clear(self) -> None: ...
|
|
100
|
+
def values(self) -> list[Node]: ...
|
|
101
|
+
def __iter__(self) -> Iterator[Node]: ...
|
|
102
|
+
def __str__(self) -> str: ...
|
|
103
|
+
|
|
104
|
+
class Document:
|
|
105
|
+
"""A single YAML document."""
|
|
106
|
+
|
|
107
|
+
def __init__(self) -> None: ...
|
|
108
|
+
@staticmethod
|
|
109
|
+
def parse(text: str) -> Document: ...
|
|
110
|
+
@staticmethod
|
|
111
|
+
def from_file(path: str) -> Document: ...
|
|
112
|
+
def to_file(self, path: str) -> None: ...
|
|
113
|
+
def is_empty(self) -> bool: ...
|
|
114
|
+
def as_mapping(self) -> Optional[Mapping]: ...
|
|
115
|
+
def as_sequence(self) -> Optional[Sequence]: ...
|
|
116
|
+
def as_scalar(self) -> Optional[Scalar]: ...
|
|
117
|
+
def contains_key(self, key: str) -> bool: ...
|
|
118
|
+
def __contains__(self, key: str) -> bool: ...
|
|
119
|
+
def get(self, key: str) -> Optional[Node]: ...
|
|
120
|
+
def __getitem__(self, key: str) -> Node: ...
|
|
121
|
+
def get_string(self, key: str) -> Optional[str]: ...
|
|
122
|
+
def set(self, key: str, value: ScalarValue) -> None: ...
|
|
123
|
+
def __setitem__(self, key: str, value: ScalarValue) -> None: ...
|
|
124
|
+
def remove(self, key: str) -> bool: ...
|
|
125
|
+
def __delitem__(self, key: str) -> None: ...
|
|
126
|
+
def rename_key(self, old_key: str, new_key: str) -> bool: ...
|
|
127
|
+
def keys(self) -> list[str]: ...
|
|
128
|
+
def __str__(self) -> str: ...
|
|
129
|
+
|
|
130
|
+
class YamlFile:
|
|
131
|
+
"""A YAML stream, which may hold multiple documents and directives."""
|
|
132
|
+
|
|
133
|
+
def __init__(self) -> None: ...
|
|
134
|
+
@staticmethod
|
|
135
|
+
def parse(text: str) -> YamlFile: ...
|
|
136
|
+
@staticmethod
|
|
137
|
+
def from_file(path: str) -> YamlFile: ...
|
|
138
|
+
def __len__(self) -> int: ...
|
|
139
|
+
def is_empty(self) -> bool: ...
|
|
140
|
+
def documents(self) -> list[Document]: ...
|
|
141
|
+
def document(self) -> Optional[Document]: ...
|
|
142
|
+
def ensure_document(self) -> Document: ...
|
|
143
|
+
def push_document(self, document: Document) -> None: ...
|
|
144
|
+
def directives(self) -> list[str]: ...
|
|
145
|
+
def add_directive(self, directive_text: str) -> None: ...
|
|
146
|
+
def __str__(self) -> str: ...
|
|
File without changes
|