zs-yaml 0.0.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.
@@ -0,0 +1,75 @@
1
+ name: zs-yaml CI/CD
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ tags:
7
+ - 'v*'
8
+ pull_request:
9
+ branches:
10
+ - main
11
+
12
+ jobs:
13
+ test-build-and-deploy:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v3
17
+ - name: Set up Python
18
+ uses: actions/setup-python@v4
19
+ with:
20
+ python-version: '3.12'
21
+ - name: Install dependencies
22
+ run: |
23
+ python -m pip install --upgrade pip
24
+ pip install build twine setuptools-scm
25
+ - name: Install zs-yaml in dev mode
26
+ run: |
27
+ pip install -e .
28
+ - name: Generate schema API for team example
29
+ run: |
30
+ cd examples/team
31
+ zserio team.zs -withTypeInfoCode -python zs_gen_api
32
+ echo "PYTHONPATH=$PYTHONPATH:$PWD/zs_gen_api" >> $GITHUB_ENV
33
+ - name: Test team example transformation
34
+ run: |
35
+ cd examples/team
36
+ zs-yaml team1.yaml team1_test_out.bin
37
+ if [ $? -eq 0 ]; then
38
+ echo "Transformation successful"
39
+ else
40
+ echo "Transformation failed"
41
+ exit 1
42
+ fi
43
+ - name: Test pyobj_to_yaml functionality
44
+ run: |
45
+ cd examples/team
46
+ python test_pyobj_to_yaml.py
47
+ if [ $? -eq 0 ]; then
48
+ echo "pyobj_to_yaml tests successful"
49
+ else
50
+ echo "pyobj_to_yaml tests failed"
51
+ exit 1
52
+ fi
53
+ - name: Test all conversion functions
54
+ run: |
55
+ cd examples/team
56
+ python test_all_conversions.py
57
+ if [ $? -eq 0 ]; then
58
+ echo "All conversion tests successful"
59
+ else
60
+ echo "Conversion tests failed"
61
+ exit 1
62
+ fi
63
+ - name: Build package
64
+ run: |
65
+ python -m build
66
+ - name: Check distribution
67
+ run: |
68
+ twine check dist/*
69
+ - name: Publish to PyPI
70
+ if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main'
71
+ env:
72
+ TWINE_USERNAME: __token__
73
+ TWINE_PASSWORD: ${{ secrets.KE_PYPI_TOKEN }}
74
+ run: |
75
+ twine upload dist/*
@@ -0,0 +1,34 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+
5
+ # Generated version file
6
+ zs_yaml/_version.py
7
+
8
+ # Distribution / packaging
9
+ build/
10
+ dist/
11
+ *.egg-info/
12
+
13
+ # Virtual environments
14
+ env/
15
+ venv/
16
+ ENV/
17
+ .venv/
18
+ .env/
19
+
20
+ # Installer logs
21
+ pip-log.txt
22
+ pip-delete-this-directory.txt
23
+
24
+ # Unit test / coverage reports
25
+ .coverage
26
+ .tox/
27
+ .pytest_cache/
28
+
29
+ # Jupyter Notebook
30
+ .ipynb_checkpoints
31
+
32
+ # System files
33
+ .DS_Store
34
+ Thumbs.db
zs_yaml-0.0.0/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024, NDS e.V. Association
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
zs_yaml-0.0.0/PKG-INFO ADDED
@@ -0,0 +1,308 @@
1
+ Metadata-Version: 2.4
2
+ Name: zs-yaml
3
+ Version: 0.0.0
4
+ Summary: YAML support for zserio
5
+ Author-email: "Navigation Data Standard e.V." <support@nds-association.org>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/ndsev/zs-yaml
8
+ Project-URL: Repository, https://github.com/ndsev/zs-yaml
9
+ Project-URL: Issues, https://github.com/ndsev/zs-yaml/issues
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Build Tools
20
+ Classifier: Topic :: Software Development :: Code Generators
21
+ Requires-Python: >=3.8
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: PyYAML~=6.0
25
+ Requires-Dist: zserio<3,>=2.15.0
26
+ Requires-Dist: zstandard
27
+ Requires-Dist: lz4
28
+ Requires-Dist: brotli
29
+ Dynamic: license-file
30
+
31
+ # `zs-yaml`
32
+
33
+ *Your Easy Path to zserio Test Data*
34
+
35
+ <img src="doc/zs-yaml.png" alt="" height="100">
36
+
37
+ **zs-yaml** adds YAML as a text format to be used with zserio in order to improve the user experience when manually creating or analyzing test data for zserio.
38
+
39
+ - **YAML Format**: Uses YAML's human-readable format instead of JSON as the primary format for editing, making data handling and transformation more intuitive and less cluttered.
40
+ - **Metadata Inclusion**: Automatically includes metadata in the YAML, eliminating the need for users to manually identify the correct type when importing JSON data, ensuring seamless (de-)serialization.
41
+ - **Custom Transformations**: Allows for hooking in custom transformations so that users can work with familiar formats (e.g., dates or coordinate representations) instead of thinking in unfamiliar formats.
42
+
43
+ ## Design Principles
44
+
45
+ 1. **Transparency Over Magic**:
46
+ - Prioritize clear and understandable processes. For example, users can fully render the YAML to see the actual data conforming to the underlying zserio schema.
47
+ - This approach avoids black-box conversions, simplifying debugging and ensuring user confidence in the data.
48
+
49
+ 2. **Accessibility and Simplicity**:
50
+ - Make the tool easy to use and understand, even for beginners.
51
+ - Features are designed with simplicity in mind. For instance, we use string-only templates as one way to keep things straightforward.
52
+
53
+ 3. **Performance for Trusted Sources**:
54
+ - Optimize for performance, assuming trusted YAML sources.
55
+ - Faster processing is crucial for rapid iterations and maintaining workflow.
56
+
57
+ 4. **Flexibility Within Simplicity**:
58
+ - While maintaining a simple core, provide powerful features like YAML imports, built-in and custom transformations, and basic templating.
59
+ - This balance allows for adaptability to various use cases without compromising ease of use.
60
+
61
+ ## Installation
62
+
63
+ Install `zs-yaml` using pip:
64
+
65
+ ```bash
66
+ python -m pip install --upgrade zs-yaml
67
+ ```
68
+
69
+ ## Usage
70
+
71
+ The main entry point for the application is `zs-yaml`. It accepts arguments for specifying the input and output file paths. You can run the application as follows:
72
+
73
+ ```bash
74
+ zs-yaml input.yaml output.bin
75
+ zs-yaml input.bin output.yaml
76
+ ```
77
+
78
+ ### Programmatic Usage
79
+
80
+ In addition to the command-line interface, `zs-yaml` provides the conversion functions for use within Python scripts. In addition to the ones available to the CLI, there are also functions for programmatic use, e.g. `yaml_to_pyobj` for deserializing YAML files to Python objects:
81
+
82
+ ```python
83
+ from zs_yaml.convert import yaml_to_pyobj
84
+
85
+ # Convert a YAML file to a Python object
86
+ # (instance of the zserio object defined by the schema)
87
+ zserio_object = yaml_to_pyobj('input.yaml')
88
+
89
+ # Use the zserio_object as needed in your application
90
+ ```
91
+
92
+ ### Notes
93
+
94
+ - You have to use the exact same order of fields in the YAML as defined by the zserio schema, because zserio expects this.
95
+ - When converting from binary to YAML, the target YAML file must already exist and contain the necessary metadata.
96
+ - The minimal metadata content in the target YAML file should be:
97
+
98
+ ```yaml
99
+ _meta:
100
+ schema_module: <module_name>
101
+ schema_type: <type_name>
102
+ ```
103
+
104
+ ### Initialization Arguments
105
+
106
+ Some Zserio types require additional arguments during initialization, either when deserializing from binary or when creating objects from JSON. To support these types, you can specify initialization arguments in the `_meta` section of your YAML file:
107
+
108
+ ```yaml
109
+ _meta:
110
+ schema_module: <module_name>
111
+ schema_type: <type_name>
112
+ initialization_args:
113
+ - <arg1>
114
+ - <arg2>
115
+ # ... more arguments as needed
116
+ ```
117
+
118
+ **Hint:** At the moment only plain values are supported, although zserio supports also compound values as args.
119
+ Support for these may be added in the future.
120
+
121
+ These arguments will be passed to the appropriate Zserio functions:
122
+ - `zserio.deserialize_from_file()` when converting from binary to YAML
123
+ - `zserio.from_json_file()` when converting from YAML to binary
124
+
125
+ For example:
126
+
127
+ ```yaml
128
+ _meta:
129
+ schema_module: my_schema
130
+ schema_type: MyType
131
+ initialization_args:
132
+ - 0xAB
133
+ - 42
134
+
135
+ # ... rest of your YAML data
136
+ ```
137
+
138
+ In this example, `0xAB` and `42` will be passed as additional arguments to the initialization functions.
139
+
140
+ This feature ensures that types requiring additional initialization parameters can be properly handled in both directions of conversion (YAML to binary and binary to YAML).
141
+
142
+ ## Example
143
+
144
+ ### Zserio Schema Module Creation
145
+
146
+ 1. **Create the Zserio schema**:
147
+ - Create a file named `person.zs` with the following content:
148
+
149
+ ```zserio
150
+ package person;
151
+
152
+ struct Person
153
+ {
154
+ string name;
155
+ string birthdate;
156
+ string birth_location;
157
+ string current_job;
158
+ int32 income;
159
+ RoleExperience experience[];
160
+ };
161
+
162
+ struct RoleExperience
163
+ {
164
+ string role;
165
+ int32 years;
166
+ };
167
+ ```
168
+
169
+ 2. **Compile the Zserio schema and generate Python APIs**:
170
+ - Run the following command to compile the schema and generate Python sources:
171
+
172
+ ```sh
173
+ # Generated sources needs type infos so that 'json <-> bin'
174
+ # conversion works, which is utilized by zs-yaml
175
+ zserio person.zs -withTypeInfoCode -python zs_gen_api
176
+ ```
177
+
178
+ 3. **Ensure that the schema modules are available in the Python environment**:
179
+ - Export the `PYTHONPATH` to include the directory containing the generated Python sources:
180
+
181
+ ```sh
182
+ export PYTHONPATH="zs_gen_api"
183
+ ```
184
+
185
+ ### Use zs-yaml to create data
186
+
187
+ Using **zs-yaml**, you can define the same data in a more human-readable YAML format and include necessary metadata along with a custom transformation for the birthdate:
188
+
189
+ ```yaml
190
+ # 1) Metadata is used to specify the type needed for
191
+ # (de-)serialization and custom transform functions
192
+ # 2) Users are free to use their preferred date format
193
+ # for the birth data as the a normalization function
194
+ # (defined in the referenced `transformations.py`)
195
+ # get invoked.
196
+ # 3) Yaml allows avoiding clutter and adding comments
197
+ # like this one :)
198
+
199
+ _meta:
200
+ schema_module: person.api
201
+ schema_type: Person
202
+ transformation_module: "./transformations.py"
203
+
204
+ name: John Doe
205
+
206
+ birthdate:
207
+ _f: normalize_date
208
+ _a: "01/01/1990"
209
+ birth_location: Springfield, USA
210
+
211
+ current_job: Software Engineer
212
+ income: 75000
213
+
214
+ experience:
215
+ - role: Intern
216
+ years: 1
217
+ - role: Junior Developer
218
+ years: 2
219
+ - role: Senior Developer
220
+ years: 3
221
+ ```
222
+
223
+ #### Example Transformation Module (transformations.py)
224
+
225
+ ```python
226
+ def normalize_date(date_str):
227
+ from datetime import datetime
228
+ for fmt in ("%Y-%m-%d", "%d/%m/%Y", "%m/%d/%Y"):
229
+ try:
230
+ return datetime.strptime(date_str, fmt).strftime("%Y-%m-%d")
231
+ except ValueError:
232
+ pass
233
+ raise ValueError(f"Date {date_str} is not in a recognized format")
234
+ ```
235
+
236
+ #### Creating the Binary Representation
237
+
238
+ After you have installed `zs-yaml`, call `zs-yaml` to convert your YAML file to a binary representation:
239
+
240
+ ```sh
241
+ # Install zs-yaml if not already installed.
242
+
243
+ # Create the binary representation from the YAML file
244
+ zs-yaml person.yaml person.bin
245
+ ```
246
+
247
+ ## Built-in Transformations
248
+
249
+ zs-yaml comes with several built-in transformation functions that can be used in your YAML files. Here's a brief overview of the available functions:
250
+
251
+ - `insert_yaml_as_extern`: Includes external YAML content by transforming it to JSON and using zserio.
252
+ - `insert_yaml`: Inserts YAML content directly from an external file.
253
+ - `repeat_node`: Repeats a specific node a specified number of times.
254
+ - `extract_extern_as_yaml`: Extracts binary data and saves it as an external YAML file.
255
+ - `py_eval`: Allows to write small snippets like `myArray: {_f: py_eval, _a: "list(range(1, 100))"}` to generate the value for a yaml node.
256
+
257
+ For more detailed information about these functions and their usage, please refer to the [built_in_transformations.py](https://github.com/ndsev/zs-yaml/blob/main/zs_yaml/built_in_transformations.py) source file.
258
+
259
+ Note: We plan to implement automatic source documentation generation in a future release, which will provide more comprehensive information about these functions and their parameters.
260
+
261
+ ## Project Structure
262
+
263
+ - `pyproject.toml`: Modern Python project configuration file containing all package metadata and dependencies.
264
+ - `zs_yaml/`: Directory containing the actual `zs-yaml` implementation.
265
+
266
+ ## Release Procedure
267
+
268
+ This project uses automatic version management through `setuptools-scm`, which derives version numbers from git tags:
269
+
270
+ ### Version Numbering
271
+
272
+ - **Tagged releases**: Git tags like `v0.8.1` produce clean version numbers: `0.8.1`
273
+ - **Development versions**: Commits on main branch produce versions like `0.8.1.dev5` (5 commits after v0.8.0)
274
+
275
+ ### Creating a Release
276
+
277
+ 1. **Create a GitHub Release**:
278
+ - Go to the repository's "Releases" page on GitHub
279
+ - Click "Create a new release"
280
+ - Create a new tag (e.g., `v0.9.0`) targeting the main branch
281
+ - Add release notes describing the changes
282
+ - Publish the release
283
+
284
+ 2. **Automatic Publication**:
285
+ - GitHub Actions will automatically:
286
+ - Build the package with the correct version number
287
+ - Run all tests
288
+ - Publish to PyPI if tests pass
289
+
290
+ ### Manual Release (if needed)
291
+
292
+ If you need to create a release locally:
293
+
294
+ ```bash
295
+ # Ensure you're on main with latest changes
296
+ git checkout main
297
+ git pull
298
+
299
+ # Create and push a tag
300
+ git tag -a v0.9.0 -m "Release version 0.9.0"
301
+ git push origin v0.9.0
302
+ ```
303
+
304
+ The CI/CD pipeline will handle the rest automatically.
305
+
306
+ ## Reference
307
+
308
+ This project references the zserio serialization framework. For more information about zserio, visit the [zserio GitHub project](https://github.com/ndsev/zserio).