structtype 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.
- structtype-0.1.0/.cibuildwheel.toml +4 -0
- structtype-0.1.0/AGENTS.md +62 -0
- structtype-0.1.0/LICENSE +27 -0
- structtype-0.1.0/MANIFEST.in +8 -0
- structtype-0.1.0/Makefile +93 -0
- structtype-0.1.0/PKG-INFO +80 -0
- structtype-0.1.0/README.md +57 -0
- structtype-0.1.0/pyproject.toml +98 -0
- structtype-0.1.0/setup.cfg +4 -0
- structtype-0.1.0/setup.py +68 -0
- structtype-0.1.0/src/structtype/__init__.py +17 -0
- structtype-0.1.0/src/structtype/__init__.pyi +361 -0
- structtype-0.1.0/src/structtype/_adapter.py +34 -0
- structtype-0.1.0/src/structtype/_core.c +19907 -0
- structtype-0.1.0/src/structtype/_inspect.py +1094 -0
- structtype-0.1.0/src/structtype/_json_schema.py +527 -0
- structtype-0.1.0/src/structtype/_utils.py +382 -0
- structtype-0.1.0/src/structtype/_version.py +24 -0
- structtype-0.1.0/src/structtype/atof.h +439 -0
- structtype-0.1.0/src/structtype/atof_consts.h +675 -0
- structtype-0.1.0/src/structtype/common.h +23 -0
- structtype-0.1.0/src/structtype/itoa.h +190 -0
- structtype-0.1.0/src/structtype/py.typed +0 -0
- structtype-0.1.0/src/structtype/ryu.h +995 -0
- structtype-0.1.0/src/structtype.egg-info/PKG-INFO +80 -0
- structtype-0.1.0/src/structtype.egg-info/SOURCES.txt +45 -0
- structtype-0.1.0/src/structtype.egg-info/dependency_links.txt +1 -0
- structtype-0.1.0/src/structtype.egg-info/top_level.txt +1 -0
- structtype-0.1.0/tests/__init__.py +0 -0
- structtype-0.1.0/tests/unit/__init__.py +0 -0
- structtype-0.1.0/tests/unit/conftest.py +53 -0
- structtype-0.1.0/tests/unit/test_JSONTestSuite.py +335 -0
- structtype-0.1.0/tests/unit/test_adapter.py +122 -0
- structtype-0.1.0/tests/unit/test_check.py +207 -0
- structtype-0.1.0/tests/unit/test_constraints.py +802 -0
- structtype-0.1.0/tests/unit/test_cpylint.py +47 -0
- structtype-0.1.0/tests/unit/test_free_threading.py +59 -0
- structtype-0.1.0/tests/unit/test_inspect.py +898 -0
- structtype-0.1.0/tests/unit/test_json.py +3143 -0
- structtype-0.1.0/tests/unit/test_msgspec.py +113 -0
- structtype-0.1.0/tests/unit/test_pydantic.py +136 -0
- structtype-0.1.0/tests/unit/test_raw.py +141 -0
- structtype-0.1.0/tests/unit/test_schema.py +1434 -0
- structtype-0.1.0/tests/unit/test_struct.py +2578 -0
- structtype-0.1.0/tests/unit/test_struct_meta.py +601 -0
- structtype-0.1.0/tests/unit/test_utils.py +210 -0
- structtype-0.1.0/tests/unit/utils.py +71 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# structtype — AGENTS.md
|
|
2
|
+
|
|
3
|
+
## Project
|
|
4
|
+
|
|
5
|
+
Fast struct validation + JSON serialization for Python.
|
|
6
|
+
Core is a monolithic C extension (`src/structtype/_core.c`, ~20K lines).
|
|
7
|
+
No runtime deps.
|
|
8
|
+
|
|
9
|
+
## Setup
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
uv sync --frozen
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Commands
|
|
16
|
+
|
|
17
|
+
All commands go through `make`.
|
|
18
|
+
|
|
19
|
+
| Task | Command |
|
|
20
|
+
|---|---|
|
|
21
|
+
| Unit tests (reinstall + last-failed) | `make test-lf` |
|
|
22
|
+
| Targeted tests | `uv run --reinstall pytest tests/unit/test_json.py -k test_something` |
|
|
23
|
+
| Coverage | `make test-cov` |
|
|
24
|
+
| Build docs | `make docs` |
|
|
25
|
+
| Format | `make format` |
|
|
26
|
+
| Lint | `make ruff-check` |
|
|
27
|
+
| Type check | `make type-check` |
|
|
28
|
+
| All checks | `make check` |
|
|
29
|
+
|
|
30
|
+
## Conventions
|
|
31
|
+
|
|
32
|
+
- **88-char lines**, formatted with `ruff format`
|
|
33
|
+
- `ruff check` with rules `E`, `F`, `I`, `W`
|
|
34
|
+
- Private modules/functions prefixed with `_`
|
|
35
|
+
- C code uses `ms_`/`MS_` prefix
|
|
36
|
+
- Type stubs (`.pyi`) alongside public modules
|
|
37
|
+
- Sentinel values: `NODEFAULT`, `UNSET`, `_NoDefault`, `UnsetType`
|
|
38
|
+
|
|
39
|
+
## Key API
|
|
40
|
+
|
|
41
|
+
- `structtype.Struct` — base class with config options (frozen, tag, rename, etc.)
|
|
42
|
+
- `structtype.Field` — field constraints (gt, ge, lt, le, min_length, etc.)
|
|
43
|
+
- `structtype.Raw` — lazy JSON passthrough
|
|
44
|
+
- `structtype._inspect.type_info()` / `multi_type_info()` — type introspection
|
|
45
|
+
|
|
46
|
+
### Struct Methods
|
|
47
|
+
|
|
48
|
+
- `obj.struct_dump_json()` — serialize to JSON bytes
|
|
49
|
+
- `obj.struct_dump()` — convert to built-in Python types
|
|
50
|
+
- `obj.struct_to_dict()` — shallow field dict
|
|
51
|
+
- `obj.struct_to_tuple()` — shallow field tuple
|
|
52
|
+
- `obj.struct_force_setattr(name, value)` — set attr on frozen struct
|
|
53
|
+
- `obj.struct_check()` — validate field values against types + constraints
|
|
54
|
+
- `cls.struct_validate_json(buf)` — deserialize from JSON
|
|
55
|
+
- `cls.struct_validate_jsonln(buf)` — deserialize newline-delimited JSON to a list of structs
|
|
56
|
+
- `cls.struct_dump_jsonln(items)` — serialize a list of structs as newline-delimited JSON
|
|
57
|
+
- `cls.struct_validate(obj)` — convert built-in types to struct
|
|
58
|
+
|
|
59
|
+
## Gotchas
|
|
60
|
+
|
|
61
|
+
- `pytest-randomly` shuffles test order
|
|
62
|
+
- `make test-lf` reinstalls the C extension before running (last-failed first)
|
structtype-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Copyright (c) 2026, Wolfgang Langner
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
15
|
+
may be used to endorse or promote products derived from this software
|
|
16
|
+
without specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
.DEFAULT_GOAL := help
|
|
2
|
+
SOURCE_DIR = ./src
|
|
3
|
+
PY_VERSIONS = 3.10 3.11 3.12 3.13 3.14 3.14t 3.15 3.15t
|
|
4
|
+
export UV_MANAGED_PYTHON ?= 1
|
|
5
|
+
|
|
6
|
+
##@ Build
|
|
7
|
+
.PHONY: build
|
|
8
|
+
build: ## Build
|
|
9
|
+
uv build
|
|
10
|
+
|
|
11
|
+
.PHONY: docs
|
|
12
|
+
docs: ## build docs
|
|
13
|
+
rm -rf .doctrees site
|
|
14
|
+
uv run --group docs sphinx-build -d .doctrees -b html docs site --fail-on-warning
|
|
15
|
+
|
|
16
|
+
##@ Quality
|
|
17
|
+
.PHONY: test-cov
|
|
18
|
+
test-cov: ## Run tests with coverage
|
|
19
|
+
uv run pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=structtype
|
|
20
|
+
|
|
21
|
+
.PHONY: test-lf
|
|
22
|
+
test-lf: ## Run tests in current Python
|
|
23
|
+
uv run --reinstall pytest --lf
|
|
24
|
+
|
|
25
|
+
.PHONY: test-all
|
|
26
|
+
test-all: ## Run tests in all supporte Python versions
|
|
27
|
+
for py_v in $(PY_VERSIONS); do \
|
|
28
|
+
uv run --isolated -p $$py_v pytest; \
|
|
29
|
+
done
|
|
30
|
+
|
|
31
|
+
.PHONY: check
|
|
32
|
+
check: ## Run all checks
|
|
33
|
+
-uvx ty check ${SOURCE_DIR}
|
|
34
|
+
uvx ruff check ${SOURCE_DIR}
|
|
35
|
+
|
|
36
|
+
.PHONY: ruff-check
|
|
37
|
+
ruff-check: ## Lint using ruff
|
|
38
|
+
uvx ruff check ${SOURCE_DIR}
|
|
39
|
+
|
|
40
|
+
.PHONY: type-check
|
|
41
|
+
type-check: ## Type check with
|
|
42
|
+
-uvx ty check ${SOURCE_DIR}
|
|
43
|
+
uvx pyrefly check ${SOURCE_DIR}
|
|
44
|
+
|
|
45
|
+
.PHONY: format
|
|
46
|
+
format: ## Format files using ruff format
|
|
47
|
+
uvx ruff format ${SOURCE_DIR}
|
|
48
|
+
|
|
49
|
+
##@ Benchmark
|
|
50
|
+
.PHONY: bench
|
|
51
|
+
bench: ## run benchmarks
|
|
52
|
+
uv run --group bench benchmarks/bench_compare.py
|
|
53
|
+
uv run --group bench benchmarks/bench_libs.py
|
|
54
|
+
|
|
55
|
+
##@ Utility
|
|
56
|
+
.PHONY: clean
|
|
57
|
+
clean: ## Delete all temporary files
|
|
58
|
+
rm -rf .pytest_cache
|
|
59
|
+
rm -rf **/.pytest_cache
|
|
60
|
+
rm -rf .mypy_cache
|
|
61
|
+
rm -rf .ruff_cache
|
|
62
|
+
rm -rf __pycache__
|
|
63
|
+
rm -rf **/__pycache__
|
|
64
|
+
rm -rf build
|
|
65
|
+
rm -rf dist
|
|
66
|
+
rm -f .coverage
|
|
67
|
+
|
|
68
|
+
.PHONY: install
|
|
69
|
+
install: install-uv ## Install virtual environment
|
|
70
|
+
uv sync --frozen
|
|
71
|
+
|
|
72
|
+
.PHONY: install-uv
|
|
73
|
+
install-uv: ## Install uv
|
|
74
|
+
@command -v uv >/dev/null 2>&1 || curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
75
|
+
|
|
76
|
+
.PHONY: update-uv
|
|
77
|
+
update-uv: ## Update uv
|
|
78
|
+
uv self update
|
|
79
|
+
|
|
80
|
+
.PHONY: update-lock
|
|
81
|
+
update-lock: ## Update lockfile
|
|
82
|
+
uv lock --upgrade
|
|
83
|
+
|
|
84
|
+
.PHONY: update-python
|
|
85
|
+
update-python: ## Reinstall managed Python versions to latest release
|
|
86
|
+
for py_v in $(PY_VERSIONS); do \
|
|
87
|
+
uv python install --reinstall $$py_v ; \
|
|
88
|
+
done
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
.PHONY: help
|
|
92
|
+
help: ## Display this help
|
|
93
|
+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make <target>\033[36m\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: structtype
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fast Struct type with validation and JSON serialization for Python.
|
|
5
|
+
Maintainer-email: Wolfgang Langner <tds333@mailbox.org>
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
7
|
+
Project-URL: Homepage, https://github.com/tds333/structtype
|
|
8
|
+
Project-URL: Issue Tracker, https://github.com/tds333/structtype/issues
|
|
9
|
+
Project-URL: Source, https://github.com/tds333/structtype
|
|
10
|
+
Keywords: JSON,schema,serialization,struct,validation
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: WebAssembly :: Emscripten
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# structtype
|
|
25
|
+
|
|
26
|
+
Fast Struct type with validation + JSON serialization for Python.
|
|
27
|
+
|
|
28
|
+
- **High performance** — 5-60x faster than dataclasses, attrs, or pydantic for common operations
|
|
29
|
+
- **Schema validation** — familiar Python type annotations, enforced at decode time
|
|
30
|
+
- **No runtime dependencies** — built on a monolithic C extension based on msgspec
|
|
31
|
+
- **Rich type support** — nested Structs, dataclasses, TypedDicts, enums, UUID, Decimal, datetime, and more
|
|
32
|
+
- **JSON Schema generation** — auto-generate JSON Schema 2020-12 / OpenAPI 3.1 specs
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install structtype
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
uv add structtype
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Requires Python ≥ 3.10.
|
|
45
|
+
|
|
46
|
+
## Quick Example
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from structtype import Struct
|
|
50
|
+
|
|
51
|
+
class User(Struct):
|
|
52
|
+
name: str
|
|
53
|
+
groups: set[str] = set()
|
|
54
|
+
email: str | None = None
|
|
55
|
+
|
|
56
|
+
alice = User("alice", groups={"admin", "engineering"})
|
|
57
|
+
|
|
58
|
+
# Serialize to JSON
|
|
59
|
+
alice.struct_dump_json()
|
|
60
|
+
# b'{"name":"alice","groups":["admin","engineering"],"email":null}'
|
|
61
|
+
|
|
62
|
+
# Deserialize and validate
|
|
63
|
+
User.struct_validate_json(
|
|
64
|
+
b'{"name":"alice","groups":["admin","engineering"],"email":null}'
|
|
65
|
+
)
|
|
66
|
+
# User(name='alice', groups={"admin", "engineering"}, email=None)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Documentation
|
|
70
|
+
|
|
71
|
+
Full documentation is available at **https://tds333.github.io/structtype/**.
|
|
72
|
+
|
|
73
|
+
## Benchmarks
|
|
74
|
+
|
|
75
|
+
structtype is as fast as msgspec and about 3-5x faster than pydantic.
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
New BSD. See the [License File](LICENSE).
|
|
80
|
+
The core is based on the work of Jim Crist-Harif from msgspec.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# structtype
|
|
2
|
+
|
|
3
|
+
Fast Struct type with validation + JSON serialization for Python.
|
|
4
|
+
|
|
5
|
+
- **High performance** — 5-60x faster than dataclasses, attrs, or pydantic for common operations
|
|
6
|
+
- **Schema validation** — familiar Python type annotations, enforced at decode time
|
|
7
|
+
- **No runtime dependencies** — built on a monolithic C extension based on msgspec
|
|
8
|
+
- **Rich type support** — nested Structs, dataclasses, TypedDicts, enums, UUID, Decimal, datetime, and more
|
|
9
|
+
- **JSON Schema generation** — auto-generate JSON Schema 2020-12 / OpenAPI 3.1 specs
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install structtype
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
uv add structtype
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requires Python ≥ 3.10.
|
|
22
|
+
|
|
23
|
+
## Quick Example
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from structtype import Struct
|
|
27
|
+
|
|
28
|
+
class User(Struct):
|
|
29
|
+
name: str
|
|
30
|
+
groups: set[str] = set()
|
|
31
|
+
email: str | None = None
|
|
32
|
+
|
|
33
|
+
alice = User("alice", groups={"admin", "engineering"})
|
|
34
|
+
|
|
35
|
+
# Serialize to JSON
|
|
36
|
+
alice.struct_dump_json()
|
|
37
|
+
# b'{"name":"alice","groups":["admin","engineering"],"email":null}'
|
|
38
|
+
|
|
39
|
+
# Deserialize and validate
|
|
40
|
+
User.struct_validate_json(
|
|
41
|
+
b'{"name":"alice","groups":["admin","engineering"],"email":null}'
|
|
42
|
+
)
|
|
43
|
+
# User(name='alice', groups={"admin", "engineering"}, email=None)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Documentation
|
|
47
|
+
|
|
48
|
+
Full documentation is available at **https://tds333.github.io/structtype/**.
|
|
49
|
+
|
|
50
|
+
## Benchmarks
|
|
51
|
+
|
|
52
|
+
structtype is as fast as msgspec and about 3-5x faster than pydantic.
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
New BSD. See the [License File](LICENSE).
|
|
57
|
+
The core is based on the work of Jim Crist-Harif from msgspec.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "structtype"
|
|
3
|
+
description = "Fast Struct type with validation and JSON serialization for Python."
|
|
4
|
+
readme = "README.md"
|
|
5
|
+
requires-python = ">=3.10"
|
|
6
|
+
license = "BSD-3-Clause"
|
|
7
|
+
license-files = [
|
|
8
|
+
"LICENSE",
|
|
9
|
+
]
|
|
10
|
+
maintainers = [
|
|
11
|
+
{ name = "Wolfgang Langner", email = "tds333@mailbox.org" },
|
|
12
|
+
]
|
|
13
|
+
keywords = [
|
|
14
|
+
"JSON",
|
|
15
|
+
"schema",
|
|
16
|
+
"serialization",
|
|
17
|
+
"struct",
|
|
18
|
+
"validation",
|
|
19
|
+
]
|
|
20
|
+
classifiers = [
|
|
21
|
+
"Development Status :: 4 - Beta",
|
|
22
|
+
"Environment :: WebAssembly :: Emscripten",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Programming Language :: Python :: 3.14",
|
|
28
|
+
"Programming Language :: Python :: 3.15",
|
|
29
|
+
]
|
|
30
|
+
dependencies = []
|
|
31
|
+
dynamic = [
|
|
32
|
+
"version",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/tds333/structtype"
|
|
37
|
+
"Issue Tracker" = "https://github.com/tds333/structtype/issues"
|
|
38
|
+
Source = "https://github.com/tds333/structtype"
|
|
39
|
+
|
|
40
|
+
[dependency-groups]
|
|
41
|
+
dev = [
|
|
42
|
+
"attrs",
|
|
43
|
+
"coverage",
|
|
44
|
+
"msgspec",
|
|
45
|
+
"pydantic; python_version < '3.15'",
|
|
46
|
+
"pytest>=9",
|
|
47
|
+
"pytest-coverage>=0.0",
|
|
48
|
+
]
|
|
49
|
+
bench = [
|
|
50
|
+
"cattrs==25.3.0",
|
|
51
|
+
"mashumaro==3.17",
|
|
52
|
+
"msgspec",
|
|
53
|
+
"orjson==3.11.4",
|
|
54
|
+
"pydantic==2.12.4",
|
|
55
|
+
"pysimdjson==7.0.2",
|
|
56
|
+
"python-rapidjson==1.22",
|
|
57
|
+
"requests",
|
|
58
|
+
"ujson==5.11.0",
|
|
59
|
+
]
|
|
60
|
+
docs = [
|
|
61
|
+
"furo",
|
|
62
|
+
"ipython",
|
|
63
|
+
"myst-parser",
|
|
64
|
+
"sphinx",
|
|
65
|
+
"sphinx-copybutton",
|
|
66
|
+
"sphinx-design",
|
|
67
|
+
]
|
|
68
|
+
hooks = [
|
|
69
|
+
"codespell==2.4.1",
|
|
70
|
+
"prek>=0.2.13",
|
|
71
|
+
"ruff==0.15.16",
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
[build-system]
|
|
75
|
+
requires = [
|
|
76
|
+
"setuptools>=80",
|
|
77
|
+
"setuptools-scm>=8",
|
|
78
|
+
]
|
|
79
|
+
build-backend = "setuptools.build_meta"
|
|
80
|
+
|
|
81
|
+
[tool.setuptools]
|
|
82
|
+
packages = ["structtype"]
|
|
83
|
+
|
|
84
|
+
[tool.setuptools.package-dir]
|
|
85
|
+
"" = "src"
|
|
86
|
+
|
|
87
|
+
[tool.setuptools.exclude-package-data]
|
|
88
|
+
structtype = [
|
|
89
|
+
"*.c",
|
|
90
|
+
"*.h",
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
[tool.setuptools_scm]
|
|
94
|
+
version_file = "src/structtype/_version.py"
|
|
95
|
+
parentdir_prefix_version = "structtype-"
|
|
96
|
+
|
|
97
|
+
[tool.uv.config-settings]
|
|
98
|
+
editable_mode = "compat"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import platform
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from setuptools import setup
|
|
6
|
+
from setuptools.extension import Extension
|
|
7
|
+
|
|
8
|
+
# Check for 32-bit windows builds, which currently aren't supported. We can't
|
|
9
|
+
# rely on `platform.architecture` here since users can still run 32-bit python
|
|
10
|
+
# builds on 64 bit architectures.
|
|
11
|
+
if sys.platform == "win32" and sys.maxsize == (2**31 - 1):
|
|
12
|
+
import textwrap
|
|
13
|
+
|
|
14
|
+
error = """
|
|
15
|
+
====================================================================
|
|
16
|
+
`structtype` currently doesn't support 32-bit Python windows builds.
|
|
17
|
+
====================================================================
|
|
18
|
+
"""
|
|
19
|
+
print(textwrap.dedent(error))
|
|
20
|
+
exit(1)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
SANITIZE = os.environ.get("STRUCTTYPE_SANITIZE", False)
|
|
24
|
+
COVERAGE = os.environ.get("STRUCTTYPE_COVERAGE", False)
|
|
25
|
+
DEBUG = os.environ.get("STRUCTTYPE_DEBUG", SANITIZE or COVERAGE)
|
|
26
|
+
|
|
27
|
+
extra_compile_args = []
|
|
28
|
+
extra_link_args = []
|
|
29
|
+
if SANITIZE:
|
|
30
|
+
extra_compile_args.extend(["-fsanitize=address", "-fsanitize=undefined"])
|
|
31
|
+
extra_link_args.extend(["-lasan", "-lubsan"])
|
|
32
|
+
if COVERAGE:
|
|
33
|
+
extra_compile_args.append("--coverage")
|
|
34
|
+
extra_link_args.append("-lgcov")
|
|
35
|
+
if DEBUG:
|
|
36
|
+
extra_compile_args.extend(["-O0", "-g", "-UNDEBUG"])
|
|
37
|
+
elif sys.platform != "win32":
|
|
38
|
+
extra_compile_args.extend(["-g0"])
|
|
39
|
+
if sys.platform == "darwin" and platform.machine().lower() == "arm64":
|
|
40
|
+
extra_compile_args.extend(["-flto=thin"])
|
|
41
|
+
extra_link_args.extend(["-flto=thin"])
|
|
42
|
+
|
|
43
|
+
# from https://py-free-threading.github.io/faq/#im-trying-to-build-a-library-on-windows-but-msvc-says-c-atomic-support-is-not-enabled
|
|
44
|
+
if sys.platform == "win32":
|
|
45
|
+
extra_compile_args.extend(
|
|
46
|
+
[
|
|
47
|
+
"/std:c11",
|
|
48
|
+
"/experimental:c11atomics",
|
|
49
|
+
]
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
libraries = []
|
|
53
|
+
if sys.platform != "win32":
|
|
54
|
+
libraries.append("m")
|
|
55
|
+
|
|
56
|
+
ext_modules = [
|
|
57
|
+
Extension(
|
|
58
|
+
"structtype._core",
|
|
59
|
+
[os.path.join("src", "structtype", "_core.c")],
|
|
60
|
+
libraries=libraries,
|
|
61
|
+
extra_compile_args=extra_compile_args,
|
|
62
|
+
extra_link_args=extra_link_args,
|
|
63
|
+
)
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
setup(
|
|
67
|
+
ext_modules=ext_modules,
|
|
68
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from ._core import (
|
|
2
|
+
NODEFAULT,
|
|
3
|
+
UNSET,
|
|
4
|
+
DecodeError,
|
|
5
|
+
EncodeError,
|
|
6
|
+
Field,
|
|
7
|
+
Raw,
|
|
8
|
+
Struct,
|
|
9
|
+
StructConfig,
|
|
10
|
+
StructMeta,
|
|
11
|
+
UnsetType,
|
|
12
|
+
ValidationError,
|
|
13
|
+
)
|
|
14
|
+
from ._adapter import StructAdapter
|
|
15
|
+
from ._inspect import FieldInfo, fields
|
|
16
|
+
from ._json_schema import json_schema, json_schema_dump, json_schema_components
|
|
17
|
+
from ._version import __version__
|