zig-zon 0.2.5__tar.gz → 0.3.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.
- zig-zon-0.3.0/PKG-INFO +176 -0
- {zig-zon-0.2.5 → zig-zon-0.3.0}/build.zig +18 -0
- {zig-zon-0.2.5 → zig-zon-0.3.0}/build.zig.zon +3 -3
- zig-zon-0.3.0/setup.py +124 -0
- zig-zon-0.3.0/setup.zig.json +1 -0
- zig-zon-0.3.0/src/zig_zon.pyi +95 -0
- zig-zon-0.3.0/src/zig_zon.zig +919 -0
- zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8/LICENSE +21 -0
- zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8/README.md +275 -0
- zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8/build.zig +296 -0
- {zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4 → zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8}/build.zig.zon +1 -1
- {zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4 → zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8}/pkg-info.zon +1 -1
- {zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4 → zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8}/src/build/CPython.zig +61 -4
- {zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4 → zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8}/src/build/SDistStep.zig +24 -5
- {zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4 → zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8}/src/build/VenvInstallTest.zig +34 -8
- zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8/src/build/pip_runner.py +153 -0
- {zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4 → zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8}/src/build/python.zig +139 -85
- zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8/src/build/setup_json.zig +34 -0
- zig-zon-0.2.5/PKG-INFO +0 -90
- zig-zon-0.2.5/setup.py +0 -69
- zig-zon-0.2.5/setup.zig.json +0 -1
- zig-zon-0.2.5/src/zig_zon.pyi +0 -5
- zig-zon-0.2.5/src/zig_zon.zig +0 -312
- zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4/README.md +0 -121
- zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4/build.zig +0 -202
- zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4/src/build/setup_json.zig +0 -28
- {zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4 → zig-zon-0.3.0}/LICENSE +0 -0
- {zig-zon-0.2.5 → zig-zon-0.3.0}/pkg-info.zon +0 -0
- {zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4 → zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8}/src/build/Compression.zig +0 -0
- {zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4 → zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8}/src/build/LowerDashString.zig +0 -0
- {zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4 → zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8}/src/build/extract_link_info.py +0 -0
- {zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4 → zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8}/src/build/pkg_info.zig +0 -0
- {zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4 → zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8}/src/build/python-translatec.h +0 -0
- {zig-zon-0.2.5/zig-pkg/zig_python_sdist-0.0.4 → zig-zon-0.3.0/zig-pkg/zig_python_sdist-0.0.8}/src/build/python_allocator.zig +0 -0
zig-zon-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zig-zon
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: a native cpython extension to parse zig object notation strings
|
|
5
|
+
Author-email: Tobias Simetsreiter <dasimmet@gmail.com>
|
|
6
|
+
Maintainer-email: Tobias Simetsreiter <dasimmet@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Keywords: zig,ziglang,cpython,native,sdist,zon
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Project-URL: Homepage, https://codeberg.org/dasimmet/python-zig-zon
|
|
11
|
+
Project-URL: Issues, https://codeberg.org/dasimmet/python-zig-zon/issues
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Zig
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# Python Zig Zon Parser
|
|
20
|
+
|
|
21
|
+
A native python extension built with zig to parse zig-object-notation strings
|
|
22
|
+
into python objects.
|
|
23
|
+
|
|
24
|
+
On PyPi it is only distributed in source, and built during install.
|
|
25
|
+
It therefore needs to download the `ziglang` python package.
|
|
26
|
+
|
|
27
|
+
Depending on your OS, you may need the python development headers
|
|
28
|
+
(e.g. `python3-dev`) installed.
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
install from source on <https://pypi.org/project/zig-zon>:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install zig-zon
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Parsing
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
>>> import zig_zon
|
|
42
|
+
>>> parsed = zig_zon.parse('.{.allyourcode = .are_belong_to_us, .asd = 123}')
|
|
43
|
+
>>> print(parsed)
|
|
44
|
+
{'allyourcode': 'are_belong_to_us', 'asd': 123}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Parsing Options
|
|
48
|
+
|
|
49
|
+
- **`bytes`**: Controls how binary / non-UTF-8 string literals in ZON are handled:
|
|
50
|
+
- `"error"` (default): Non-UTF-8 string literals raise a `UnicodeDecodeError`.
|
|
51
|
+
- `"auto"`: Valid UTF-8 strings are returned as `zig_zon.String` (subclasses `str`); strings containing invalid UTF-8 bytes are returned as `zig_zon.ByteString` (subclasses `bytes`).
|
|
52
|
+
- `"always"`: Always returns `zig_zon.ByteString` for all string literals.
|
|
53
|
+
|
|
54
|
+
or, look at the [test file](https://codeberg.org/dasimmet/python-zig-zon/src/branch/main/src/test_zig_zon.py)
|
|
55
|
+
|
|
56
|
+
## Stringification / Serialization
|
|
57
|
+
|
|
58
|
+
Use `zig_zon.stringify` to serialize Python objects to ZON strings, or `zig_zon.dump` to write directly to a file-like object:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
>>> import zig_zon
|
|
62
|
+
>>> data = {
|
|
63
|
+
... "name": zig_zon.Enum("my_pkg"),
|
|
64
|
+
... "version": "0.1.0",
|
|
65
|
+
... "fingerprint": zig_zon.Hex(0x1234abcd),
|
|
66
|
+
... "dependencies": {
|
|
67
|
+
... "dep1": {
|
|
68
|
+
... "url": "https://example.com/dep1.tar.gz",
|
|
69
|
+
... "hash": "1220...",
|
|
70
|
+
... }
|
|
71
|
+
... },
|
|
72
|
+
... "paths": ["build.zig", "build.zig.zon", "src"],
|
|
73
|
+
... }
|
|
74
|
+
>>> print(zig_zon.stringify(data))
|
|
75
|
+
.{
|
|
76
|
+
.name = .my_pkg,
|
|
77
|
+
.version = "0.1.0",
|
|
78
|
+
.fingerprint = 0x1234abcd,
|
|
79
|
+
.dependencies = .{
|
|
80
|
+
.dep1 = .{
|
|
81
|
+
.url = "https://example.com/dep1.tar.gz",
|
|
82
|
+
.hash = "1220...",
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
.paths = .{
|
|
86
|
+
"build.zig",
|
|
87
|
+
"build.zig.zon",
|
|
88
|
+
"src",
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Write to a file or stream:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
with open("build.zig.zon", "w", encoding="utf-8") as f:
|
|
97
|
+
zig_zon.dump(data, f)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Serialization Options
|
|
101
|
+
|
|
102
|
+
- **`integer_mode`**: Controls integer formatting:
|
|
103
|
+
- `"auto"` (default): Uses `Hex` -> hex (`0x...`), `Integer` -> decimal, plain `int` -> decimal.
|
|
104
|
+
- `"int"`: Always formats integers as decimal.
|
|
105
|
+
- `"hex"`: Always formats integers as hex (`0x...`).
|
|
106
|
+
- `"fallback_int"`: Uses `Hex` -> hex, `Integer` -> decimal, plain `int` -> decimal.
|
|
107
|
+
- `"fallback_hex"`: Uses `Integer` -> decimal, `Hex` -> hex, plain `int` -> hex.
|
|
108
|
+
- `"error"`: Errors out (`TypeError`) if an integer is not a `zig_zon.Integer` or `zig_zon.Hex` subclass.
|
|
109
|
+
- **`dict_as_tuples`** (bool, default `False`): If `True`, converts dictionaries to tuples of key-value tuples (`.{ .{ "key", value }, ... }`) rather than struct notation (`.{ .key = value }`).
|
|
110
|
+
- **`encoding`** (str, default `"utf-8"`): Specifies the encoding used for raw strings (`str`) and encoded strings (`bytes`/`bytearray`).
|
|
111
|
+
- **`whitespace`** (bool, default `True`): If `False`, omits unnecessary whitespace and newlines for compact output.
|
|
112
|
+
|
|
113
|
+
### Supported Python Types for Serialization
|
|
114
|
+
|
|
115
|
+
- `list`, `tuple`, `zig_zon.Tuple`: Serialized as ZON tuples `.{ ... }`.
|
|
116
|
+
- `set`, `frozenset`: Serialized as ZON tuples `.{ ... }`.
|
|
117
|
+
- `namedtuple`: Serialized as ZON structs `.{ .field = value }`.
|
|
118
|
+
- `dict`, `zig_zon.Struct`: Serialized as structs or key-value tuples (with `dict_as_tuples=True`).
|
|
119
|
+
- `str`, `zig_zon.String`: Serialized as string literals `"..."`.
|
|
120
|
+
- `bytes`, `bytearray`: Decoded using `encoding` and serialized as string literals `"..."`.
|
|
121
|
+
- `zig_zon.ByteString`: Serialized directly as binary string literals `"..."` preserving raw byte escapes.
|
|
122
|
+
- `zig_zon.BareEnum`: Serialized as bare enums `.identifier`.
|
|
123
|
+
- `zig_zon.QuotedEnum`: Serialized as quoted enums `.@"identifier"`.
|
|
124
|
+
- `zig_zon.Enum`: Serialized as enum literals (bare or quoted as necessary).
|
|
125
|
+
- `int`, `zig_zon.Integer`, `zig_zon.Hex`: Formatted according to `integer_mode`.
|
|
126
|
+
- `float`, `zig_zon.Float`: Serialized as float literals.
|
|
127
|
+
- `bool`: Serialized as `true` or `false`.
|
|
128
|
+
- `None`: Serialized as `null`.
|
|
129
|
+
|
|
130
|
+
## Supported Zon values and their python type
|
|
131
|
+
|
|
132
|
+
The parser returns custom classes for each Zig type that wrap and subclass standard Python types:
|
|
133
|
+
|
|
134
|
+
- `structs` -> `zig_zon.Struct` (subclasses `dict`)
|
|
135
|
+
- `tuples` -> `zig_zon.Tuple` (subclasses `list`)
|
|
136
|
+
- `integer literals` -> `zig_zon.Integer` (subclasses `int`)
|
|
137
|
+
- `hex literals` -> `zig_zon.Hex` (wraps / subclasses `int`)
|
|
138
|
+
- `float literals` -> `zig_zon.Float` (subclasses `float`)
|
|
139
|
+
- `booleans` -> `bool` (Python built-in `bool` is final and cannot be subclassed)
|
|
140
|
+
- `null` -> `None` (Python `NoneType` is final and cannot be subclassed)
|
|
141
|
+
- `string literals` -> `zig_zon.String` (subclasses `str`)
|
|
142
|
+
- `binary string literals` -> `zig_zon.ByteString` (subclasses `bytes`)
|
|
143
|
+
- `bare enum literals` -> `zig_zon.BareEnum` (subclasses `zig_zon.Enum` -> `str`)
|
|
144
|
+
- `quoted enum literals` -> `zig_zon.QuotedEnum` (subclasses `zig_zon.Enum` -> `str`)
|
|
145
|
+
|
|
146
|
+
Because the custom classes wrap and subclass their respective Python base types, both `isinstance(val, BaseType)` and `isinstance(val, zig_zon.CustomClass)` evaluate to `True`.
|
|
147
|
+
|
|
148
|
+
## Not supported values
|
|
149
|
+
|
|
150
|
+
- `bigint`
|
|
151
|
+
|
|
152
|
+
## How it works
|
|
153
|
+
|
|
154
|
+
The `zig build` commands produces a python source distribution archive ready
|
|
155
|
+
for uploading to Pypi. It includes the sources of [zig-python-sdist](https://codeberg.org/dasimmet/zig-python-sdist)
|
|
156
|
+
and a custom `setup.py` that handles the build of the cpython extension.
|
|
157
|
+
|
|
158
|
+
When you run pip install, the source distribution is downloaded, and since
|
|
159
|
+
this source distribution depends on the `ziglang` python package at build time,
|
|
160
|
+
a `zig build` command is used to compile the extension.
|
|
161
|
+
|
|
162
|
+
## Developing
|
|
163
|
+
|
|
164
|
+
as opposed to other solutions for building cpython extensions in zig,
|
|
165
|
+
i want to develop this using:
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
zig build
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
for linking against the local python installation [zig-python-sdist](https://codeberg.org/dasimmet/zig-python-sdist)
|
|
172
|
+
runs a python script that imports the cpython headers into zig's build cache,
|
|
173
|
+
run `translate-c` on the result and offers a `cpython` module to import
|
|
174
|
+
in our zig code.
|
|
175
|
+
On windows, the extension library is also linked against
|
|
176
|
+
the python runtime static lib and renamed to a `.pyd` file for importing.
|
|
@@ -26,6 +26,7 @@ pub fn build(b: *Build) void {
|
|
|
26
26
|
},
|
|
27
27
|
.extra_pkg_info = @import("pkg-info.zon"),
|
|
28
28
|
.files = &.{
|
|
29
|
+
.{ .src = b.path("LICENSE"), .dest = "LICENSE" },
|
|
29
30
|
.{ .src = b.path("pkg-info.zon"), .dest = "pkg-info.zon" },
|
|
30
31
|
.{ .src = b.path("build.zig.zon"), .dest = "build.zig.zon" },
|
|
31
32
|
.{ .src = b.path("build.zig"), .dest = "build.zig" },
|
|
@@ -115,4 +116,21 @@ pub fn build(b: *Build) void {
|
|
|
115
116
|
b.fmt("src/{s}.pyi", .{lib.name}),
|
|
116
117
|
);
|
|
117
118
|
}
|
|
119
|
+
|
|
120
|
+
const opt_check_fmt = b.option(bool, "check-fmt", "Check formatting without modifying files") orelse false;
|
|
121
|
+
const opt_fmt_check = b.option(bool, "fmt-check", "Check formatting without modifying files") orelse false;
|
|
122
|
+
const check_fmt = opt_check_fmt or opt_fmt_check;
|
|
123
|
+
const fmt_step = b.step("fmt", "Run zig fmt");
|
|
124
|
+
const fmt = b.addFmt(.{
|
|
125
|
+
.paths = &.{
|
|
126
|
+
"src",
|
|
127
|
+
"build.zig",
|
|
128
|
+
"build.zig.zon",
|
|
129
|
+
},
|
|
130
|
+
.check = check_fmt,
|
|
131
|
+
});
|
|
132
|
+
fmt_step.dependOn(&fmt.step);
|
|
133
|
+
if (check_fmt) {
|
|
134
|
+
b.getInstallStep().dependOn(&fmt.step);
|
|
135
|
+
}
|
|
118
136
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
.{
|
|
2
2
|
.name = .python_zig_zon,
|
|
3
3
|
.fingerprint = 0x3d332656a3644fc9,
|
|
4
|
-
.version = "0.
|
|
4
|
+
.version = "0.3.0",
|
|
5
5
|
.minimum_zig_version = "0.16.0",
|
|
6
6
|
.dependencies = .{
|
|
7
7
|
.zig_python_sdist = .{
|
|
8
|
-
.url = "git+https://codeberg.org/dasimmet/zig-python-sdist.git?ref=0.0.
|
|
9
|
-
.hash = "zig_python_sdist-0.0.
|
|
8
|
+
.url = "git+https://codeberg.org/dasimmet/zig-python-sdist.git?ref=0.0.8#3f06dd8177fbba62a68b7f0894b4a3d26cfb9fcf",
|
|
9
|
+
.hash = "zig_python_sdist-0.0.8-wjgdOimGAQBiUtyW-KGTUzlNhuwanlP9ealvenf3vcpw",
|
|
10
10
|
},
|
|
11
11
|
},
|
|
12
12
|
.paths = .{
|
zig-zon-0.3.0/setup.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
from setuptools import setup
|
|
4
|
+
from setuptools.dist import Distribution
|
|
5
|
+
from setuptools.command.bdist_wheel import bdist_wheel
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
import os
|
|
9
|
+
import json
|
|
10
|
+
import glob
|
|
11
|
+
import shutil
|
|
12
|
+
|
|
13
|
+
with open("setup.zig.json") as fd:
|
|
14
|
+
setup_json = json.load(fd)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def mkversion(v, need_release=False):
|
|
18
|
+
'''assembles a dict of semantic version to string'''
|
|
19
|
+
if need_release:
|
|
20
|
+
assert v.get('pre') is None, "cannot use version with pre: " + str(v)
|
|
21
|
+
assert v.get(
|
|
22
|
+
'build') is None, "cannot use version with build: " + str(v)
|
|
23
|
+
return str(v['major']) + '.' + str(
|
|
24
|
+
v['minor']) + '.' + str(v['patch'])
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ZigDistribution(Distribution):
|
|
28
|
+
def has_ext_modules(self):
|
|
29
|
+
return setup_json['has_ext_modules']
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ZigBuildWheel(bdist_wheel):
|
|
33
|
+
def initialize_options(self):
|
|
34
|
+
super().initialize_options()
|
|
35
|
+
if 'py_limited_api' in setup_json and setup_json['py_limited_api']:
|
|
36
|
+
self.py_limited_api = setup_json['py_limited_api']
|
|
37
|
+
|
|
38
|
+
def run(self, *args, **kwargs):
|
|
39
|
+
print("py_limited_api:", self.py_limited_api, file=sys.stderr)
|
|
40
|
+
print("plat_name:", self.plat_name, file=sys.stderr)
|
|
41
|
+
|
|
42
|
+
import ziglang
|
|
43
|
+
zig_exe = os.path.join(
|
|
44
|
+
os.path.dirname(ziglang.__file__), "zig")
|
|
45
|
+
|
|
46
|
+
cwd = os.getcwd()
|
|
47
|
+
print("zig build dir:", cwd, file=sys.stderr)
|
|
48
|
+
print("using zig exe:", zig_exe, file=sys.stderr)
|
|
49
|
+
|
|
50
|
+
extra_build_args = setup_json['build']['args']
|
|
51
|
+
build_cmd = [zig_exe, 'build'] + extra_build_args
|
|
52
|
+
|
|
53
|
+
print("zig build:", build_cmd, file=sys.stderr)
|
|
54
|
+
subprocess.check_call(build_cmd)
|
|
55
|
+
|
|
56
|
+
os.makedirs(self.bdist_dir, exist_ok=True)
|
|
57
|
+
copy_patterns = setup_json['build']['copy_patterns']
|
|
58
|
+
pkg_name = setup_json['name'].replace('-', '_')
|
|
59
|
+
|
|
60
|
+
for item in copy_patterns:
|
|
61
|
+
pattern = item['pattern']
|
|
62
|
+
dest = item.get('dest')
|
|
63
|
+
package_dir = item.get('package_dir', False)
|
|
64
|
+
|
|
65
|
+
if package_dir:
|
|
66
|
+
if dest:
|
|
67
|
+
dest = os.path.join(pkg_name, dest)
|
|
68
|
+
else:
|
|
69
|
+
dest = pkg_name
|
|
70
|
+
elif dest:
|
|
71
|
+
dest = dest.replace('{name}', pkg_name).replace(
|
|
72
|
+
'{package}', pkg_name)
|
|
73
|
+
|
|
74
|
+
artifacts = glob.glob(pattern)
|
|
75
|
+
if len(artifacts) == 0:
|
|
76
|
+
raise Exception(
|
|
77
|
+
'no zig artifacts found in {}/{}'.format(cwd, pattern))
|
|
78
|
+
|
|
79
|
+
for it in artifacts:
|
|
80
|
+
if dest:
|
|
81
|
+
is_dir = (
|
|
82
|
+
dest.endswith('/') or
|
|
83
|
+
dest.endswith('\\') or
|
|
84
|
+
any(c in pattern for c in '*?[]') or
|
|
85
|
+
(os.path.splitext(dest)[
|
|
86
|
+
1] == '' and os.path.splitext(it)[1] != '')
|
|
87
|
+
)
|
|
88
|
+
if is_dir:
|
|
89
|
+
dst = os.path.join(
|
|
90
|
+
self.bdist_dir, dest, os.path.basename(it))
|
|
91
|
+
else:
|
|
92
|
+
dst = os.path.join(self.bdist_dir, dest)
|
|
93
|
+
else:
|
|
94
|
+
dst = os.path.join(self.bdist_dir, os.path.basename(it))
|
|
95
|
+
|
|
96
|
+
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
|
97
|
+
print("cp", it, dst, file=sys.stderr)
|
|
98
|
+
if os.path.isdir(it):
|
|
99
|
+
shutil.copytree(it, dst, dirs_exist_ok=True)
|
|
100
|
+
else:
|
|
101
|
+
shutil.copyfile(it, dst)
|
|
102
|
+
|
|
103
|
+
return super().run(*args, **kwargs)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
options = {}
|
|
107
|
+
if 'py_limited_api' in setup_json and setup_json['py_limited_api']:
|
|
108
|
+
options['bdist_wheel'] = {'py_limited_api': setup_json['py_limited_api']}
|
|
109
|
+
|
|
110
|
+
setup(
|
|
111
|
+
name=setup_json['name'],
|
|
112
|
+
version=mkversion(setup_json['version']),
|
|
113
|
+
cmdclass={'bdist_wheel': ZigBuildWheel},
|
|
114
|
+
options=options,
|
|
115
|
+
install_requires=setup_json['install_requires'] if 'install_requires' in setup_json else None,
|
|
116
|
+
entry_points=setup_json['entry_points'] if 'entry_points' in setup_json else None,
|
|
117
|
+
packages=setup_json['build']['packages'],
|
|
118
|
+
distclass=ZigDistribution,
|
|
119
|
+
setup_requires=[
|
|
120
|
+
"setuptools",
|
|
121
|
+
"wheel",
|
|
122
|
+
"ziglang==" + mkversion(setup_json['zig_version'], need_release=True),
|
|
123
|
+
] + setup_json['build']['requires'],
|
|
124
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"zig_zon","version":{"major":0,"minor":3,"patch":0},"zig_version":{"major":0,"minor":16,"patch":0},"build":{"args":["--fork=zig-pkg/zig_python_sdist-0.0.8","bdist-wheel","-Doptimize=ReleaseSmall"],"requires":[],"packages":[],"copy_patterns":[{"pattern":"zig-out/lib/*","package_dir":false}]},"has_ext_modules":true}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""A native Python extension built with Zig to parse and stringify Zig Object Notation (ZON)."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, IO, Literal, Optional
|
|
4
|
+
|
|
5
|
+
__version__: dict
|
|
6
|
+
__version_str__: str
|
|
7
|
+
__zig_builtin__: dict
|
|
8
|
+
|
|
9
|
+
class Struct(dict):
|
|
10
|
+
"""a zon struct wrapping dict"""
|
|
11
|
+
|
|
12
|
+
class Tuple(list):
|
|
13
|
+
"""a zon tuple wrapping list"""
|
|
14
|
+
|
|
15
|
+
class Integer(int):
|
|
16
|
+
"""a zon integer wrapping int"""
|
|
17
|
+
|
|
18
|
+
class Hex(int):
|
|
19
|
+
"""a zon hex wrapping int"""
|
|
20
|
+
|
|
21
|
+
class Float(float):
|
|
22
|
+
"""a zon float wrapping float"""
|
|
23
|
+
|
|
24
|
+
class String(str):
|
|
25
|
+
"""a zon string wrapping str"""
|
|
26
|
+
|
|
27
|
+
class ByteString(bytes):
|
|
28
|
+
"""a zon bytestring wrapping bytes"""
|
|
29
|
+
|
|
30
|
+
class Enum(str):
|
|
31
|
+
"""a zon enum wrapping str"""
|
|
32
|
+
|
|
33
|
+
class BareEnum(Enum):
|
|
34
|
+
"""a zon bare enum wrapping Enum"""
|
|
35
|
+
|
|
36
|
+
class QuotedEnum(Enum):
|
|
37
|
+
"""a zon quoted enum wrapping Enum"""
|
|
38
|
+
|
|
39
|
+
def parse(
|
|
40
|
+
zon: str,
|
|
41
|
+
bytes: Literal["error", "auto", "always"] = "error",
|
|
42
|
+
) -> Struct | Tuple | Integer | Hex | Float | String | ByteString | BareEnum | QuotedEnum | bool | None:
|
|
43
|
+
"""parse a zon literal to a python object
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
zon: The ZON string to parse.
|
|
47
|
+
bytes: How to handle binary strings ('error', 'auto', or 'always').
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
The parsed Python object with custom subclasses.
|
|
51
|
+
"""
|
|
52
|
+
...
|
|
53
|
+
|
|
54
|
+
def stringify(
|
|
55
|
+
value: Any,
|
|
56
|
+
*,
|
|
57
|
+
integer_mode: Literal["auto", "int", "hex", "fallback_int", "fallback_hex", "error"] = "auto",
|
|
58
|
+
dict_as_tuples: bool = False,
|
|
59
|
+
encoding: str = "utf-8",
|
|
60
|
+
whitespace: bool = True,
|
|
61
|
+
) -> str:
|
|
62
|
+
"""Serialize a Python object to a Zig Object Notation (ZON) formatted string.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
value: The Python object to serialize.
|
|
66
|
+
integer_mode: Formatting mode for integers ('auto', 'int', 'hex', 'fallback_int', 'fallback_hex', 'error').
|
|
67
|
+
dict_as_tuples: If True, serialize dicts as tuples of key-value tuples rather than structs.
|
|
68
|
+
encoding: The encoding used for strings and bytes (default 'utf-8').
|
|
69
|
+
whitespace: If True, emit formatted whitespace; if False, omit unnecessary whitespace.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
The ZON formatted string.
|
|
73
|
+
"""
|
|
74
|
+
...
|
|
75
|
+
|
|
76
|
+
def dump(
|
|
77
|
+
value: Any,
|
|
78
|
+
fp: IO[str],
|
|
79
|
+
*,
|
|
80
|
+
integer_mode: Literal["auto", "int", "hex", "fallback_int", "fallback_hex", "error"] = "auto",
|
|
81
|
+
dict_as_tuples: bool = False,
|
|
82
|
+
encoding: str = "utf-8",
|
|
83
|
+
whitespace: bool = True,
|
|
84
|
+
) -> None:
|
|
85
|
+
"""Serialize a Python object as a Zig Object Notation (ZON) formatted stream to a file-like object.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
value: The Python object to serialize.
|
|
89
|
+
fp: File-like object supporting `.write(str)`.
|
|
90
|
+
integer_mode: Formatting mode for integers ('auto', 'int', 'hex', 'fallback_int', 'fallback_hex', 'error').
|
|
91
|
+
dict_as_tuples: If True, serialize dicts as tuples of key-value tuples rather than structs.
|
|
92
|
+
encoding: The encoding used for strings and bytes (default 'utf-8').
|
|
93
|
+
whitespace: If True, emit formatted whitespace; if False, omit unnecessary whitespace.
|
|
94
|
+
"""
|
|
95
|
+
...
|