cad2d-ir-native
The native code (Rust) of cad2d-ir: a typed form of the IR,
the DXF writer and the entity conversion of the JWW / JWS importer.
cad2d-ir depends on this package and uses it for both. There is no Python
implementation of either next to it (there was one up to 0.17.22; the two were
compared byte for byte before the Python one was removed in 0.18.0).
Install
pip install cad2d-ir
installs this package with it: cad2d-ir pins the cad2d-ir-native of its own
version, and the two are released together. There are wheels for Linux (x86_64
and aarch64, glibc), Windows (x86_64) and macOS (universal2), one for all
Python versions from 3.10 (abi3); elsewhere pip builds the source
distribution, which needs a Rust toolchain.
The package has no dependencies of its own and is not meant to be installed
alone: the DXF writer calls back into cad2d_ir (see "What stays in Python").
Layout
| Path | What |
|---|---|
crates/cad2d-ir-core |
The typed IR (Document, Entity, Shape, …), the conversion to and from the dynamic form of a dict, and the DXF writer (src/dxf/: R12 and R2010) |
crates/cad2d-ir-jww |
JWW and JWS entities (ezjww-core) to the typed IR |
crates/cad2d-ir-py |
The Python bindings as a library: register(module) adds the functions and classes to an extension module |
src/lib.rs |
The extension module cad2d_ir_native._core: cad2d-ir-py and nothing else |
python/cad2d_ir_native |
The Python package: the names of the extension module |
tests/ |
test_native.py (the typed document, and that a dict and the typed IR, a file and the dict of ezjww give the same result), test_dxf_golden.py with golden/ (the DXF of a set of documents, as files), test_text_cells.py (a table of the native code against the codec of Python) |
The crates take ezjww-core from a released tag of the ezjww repository
([workspace.dependencies] in Cargo.toml), so a build needs nothing next to
this repository. To build against a checkout of ezjww instead (a change of
the reader that is not released yet), name it in native/.cargo/config.toml,
which is not committed:
[patch."https://github.com/monozukuri-ai/ezjww"]
ezjww-core = { path = "../../ezjww/crates/ezjww-core" }
--locked fails with such a patch, since Cargo.lock records the tag.
What stays in Python
Each piece of work is done in one place. What needs the codecs and the tables of Python is done there, and the native code asks for it:
- DXF writer: the font of a text style (
cad2d_ir.fonts.style_font), the code page of an R12 file and what a character it cannot store is written as (_select_r12_codepage,_r12_text_planincad2d_ir/codecs/dxf.py), the inline codes ofMTEXTand its lines for R12 (cad2d_ir.mtext), and the view of a viewport (cad2d_ir.layouts.viewport_to_dxf_view). These are a few calls per document, not per entity. - JWW importer: what comes from the header of a file - layers, line types, the
pen table, the metadata and the diagnostics about the document - is made in
cad2d_ir/importers/jww.py, which reads the header withezjww. The native code reads the file itself for the entities. Adictofezjww.read_document(jww_document_to_ir, JWS symbols, a drawing whose strings are UTF-8) is read into the records ofezjww-corefirst (crates/cad2d-ir-py/src/jww_dict.rs) and converted by the same code.
cad2d-ir-core/src/num.rs and pystr.rs write numbers and compare strings
the way Python does (repr of a float, %g, sum, str.casefold): the DXF
text is defined by the Python writer that came first.
Build and test
In a checkout, uv sync at the top of the repository builds this directory
and installs it ([tool.uv.sources] in ../pyproject.toml), and builds it
again when a file here changes. Then:
uv run pytest -q # tests/ and native/tests
cd native
cargo fmt --all --check
cargo clippy --workspace --all-targets --locked -- -D warnings
cargo test -p cad2d-ir-core -p cad2d-ir-jww --locked
Without uv: pip install ./native and then pip install -e ".[jww]" (in
this order: the version cad2d-ir pins is the one just built).
The tests with real drawings read ../../ezjww/jww_samples (EZJWW_SAMPLES
names another directory) and are skipped without it.
Golden files
tests/golden/<name>.json is an IR document; <name>.ac1024.dxf and
<name>.ac1009.dxf are what the writer makes of it, and <name>.report.json
the export diagnostics and the entity map. They are what notices a change of
the writer's output. When the change is meant:
CAD2D_IR_UPDATE_GOLDEN=1 uv run pytest native/tests/test_dxf_golden.py
git diff native/tests/golden # review what changed
A number in a DXF may differ in its last digits between platforms (it comes from the sine and cosine of the platform), and the test allows for that; everything else is compared to the byte.
Release
cad2d-ir and cad2d-ir-native are one release. The root pyproject.toml
defines the release version. From the repository root, update it with:
uv run --no-sync python scripts/set_version.py 0.18.2
This sets the version, generates the exact cad2d-ir-native dependency pin
and the Cargo workspace version, refreshes both lockfiles without requesting
dependency upgrades, and runs the release consistency check. It requires uv
and Cargo; if a command fails, it restores the previous metadata and lockfiles.
Omit the version argument to synchronize after editing the root version.
Versions use the stable X.Y.Z form. The command does not commit, tag or publish.
The native Python package gets its version from Cargo through Maturin's
dynamic metadata, and cad2d_ir.__version__ reads the installed distribution
metadata. Neither needs a separate version edit. CI checks the generated
metadata and lockfiles with python scripts/check_release.py and
tests/test_package_metadata.py.
When the tag of ezjww-core in
native/Cargo.toml changes, the floor of ezjww in the jww and all extras
of pyproject.toml follows it.
Pushing the tag v<version> runs .github/workflows/release.yml: it checks
the versions and the tag, runs the tests, builds cad2d-ir (wheel and source
distribution) and cad2d-ir-native (a wheel on each platform and a source
distribution), installs each native wheel with the cad2d-ir of the release
and runs native/tests on its platform, and publishes all files to PyPI,
cad2d-ir-native first. Run by hand (workflow_dispatch) it does everything
but publish.
Publishing uses PyPI trusted publishing: the repository stores no token, and PyPI accepts the upload because it comes from this workflow. Each of the two projects on PyPI names the same publisher (for a project that does not exist yet, as a pending publisher of the account):
| Field | Value |
|---|---|
| Owner | monozukuri-ai |
| Repository name | cad2d-ir |
| Workflow name | release.yml |
| Environment name | pypi |
Use
The writer and the importer are used through cad2d_ir (ir_to_dxf,
convert_jww_file_to_ir, …). What this package adds is a document that stays
in native code:
from cad2d_ir.importers.base import ImportOptions
from cad2d_ir.importers.jww import import_jww_file
result = import_jww_file("plan.jww", options=ImportOptions(strict=False))
dxf_bytes, export_diagnostics = result.document.to_dxf_bytes()
document = result.document.to_dict() # the dict convert_jww_file_to_ir returns
result.document is a NativeDocument. Its entities do not become Python
objects unless to_dict() is asked for: the entities of a large drawing take
a fraction of the memory of their dicts. NativeDocument.from_dict holds any
IR dict that way, and to_dxf(target_version=..., curve_segments=..., generic_dimensions=..., entity_map=...) writes it with all the options of
ir_to_dxf. to_dxf_bytes() gives the bytes of the DXF R2010 file (UTF-8,
lines ending with CR and LF), the same as dxf_text_to_bytes() makes of the
text.
The few entities a caller has to look at in Python can be read and changed
without the whole document becoming a dict:
for block, index, entity in document.entities_of_kind("IMAGE", without=["data"]):
pixels = document.entity_bytes(block, index, "data") # base64 decoded, or None
document.set_entity_value(block, index, "name", "plan_" + entity["name"])
without leaves keys out of the dicts, and entity_bytes gives the bytes of
a base64 value without the text becoming a Python str: the data of an
embedded image is as large as its file, which can be hundreds of megabytes.
Native code of an application
An application with Rust code of its own that works on the typed IR (a renderer,
an exporter) links cad2d-ir-py into its extension module, calls
cad2d_ir_py::register(module) there and takes a NativeDocument as an
argument of its own functions (NativeDocument::document() is the typed
Document). The classes of two extension modules are different types to Python,
so the application uses the bindings of its own module throughout:
result = import_jww_file("plan.jww", options=..., core=my_app._core)
my_app._core.render(result.document) # a function of the application
core is the extension module whose bindings do the work; it defaults to the
one of this package. Unsupported is an exception the bindings define and
never raise: it is for the native code of such an application, when it
declines a document its Python side can handle in another way.
The typed IR
LINE, CIRCLE, ARC, POINT, ELLIPSE, TEXT, INSERT, HATCH and
LWPOLYLINE are structs. Every other entity, and every value that is not of
the type the schema gives it, stays dynamic and converts back unchanged, so a
document is the same dict after NativeDocument.from_dict(...).to_dict().
Two things are not kept as they came: a tuple is a list afterwards, and
the halves of a surrogate pair held as two code points are the character they
stand for (a half alone is U+FFFD) - Rust has no such string.
NativeDocument.from_dict raises TypeError for a value JSON does not have
(bytes, a set, a key that is no str), which it could not give back. The
writer, which only reads, passes over such a value where it is not what is
written.
A dict that ir_to_dxf hands over is converted for the writer alone: one
entity at a time (the dynamic form of an entity, every key and value an object
of its own, is several kilobytes and exists for one entity only), and without
what the writer never reads - the source of an entity, and the metadata of
the kinds that are written from their fields (dxf::reads_entity_key). An
imported drawing carries both on every entity, and without them an entity is
about a hundred bytes. NativeDocument keeps everything; the two are written
the same (tests/test_native.py).
Measurements
Taken with 0.17.22, when both implementations existed: JWW drawings of lines
only (synthetic), one process per run, JWW import and DXF R2010 export, the
same DXF for the first two columns. ezjww is ezjww.write_dxf_with_report,
whose output is a different DXF.
| JWW | Python (removed in 0.18.0) | native | ezjww |
|---|---|---|---|
| 0.7 MB | 0.58 s, 64 MB | 0.16 s, 46 MB | 0.05 s, 31 MB |
| 3.6 MB | 2.69 s, 195 MB | 0.33 s, 96 MB | 0.15 s, 70 MB |
| 9.4 MB | 7.08 s, 467 MB | 0.72 s, 199 MB | 0.47 s, 155 MB |
| 15 MB | 11.08 s, 709 MB | 1.04 s, 282 MB | 0.66 s, 218 MB |
Metadata
Release files for cad2d-ir-native 0.19.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cad2d_ir_native-0.19.2.tar.gz | 167.5 kB | Without provenance | Details for cad2d_ir_native-0.19.2.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| cad2d_ir_native-0.19.2-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details for cad2d_ir_native-0.19.2-cp310-abi3-win_amd64.whl |
| cad2d_ir_native-0.19.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details for cad2d_ir_native-0.19.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| cad2d_ir_native-0.19.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details for cad2d_ir_native-0.19.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| cad2d_ir_native-0.19.2-cp310-abi3-macosx_10_12_universal2.macosx_10_12_x86_64.macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64 | Details for cad2d_ir_native-0.19.2-cp310-abi3-macosx_10_12_universal2.macosx_10_12_x86_64.macosx_11_0_arm64.whl |
Total release size: 5.2 MB
Release files / cad2d_ir_native-0.19.2.tar.gz
| Download URL | cad2d_ir_native-0.19.2.tar.gz |
|---|---|
| Size | 167.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b1ad68b09d5c9eb6d1adb1e811027a06fc9fa6b5e2c67c152f777e2e64b219b5
|
|
BLAKE2b-256 checksum How to use checksums |
a9768353161e7b324430a597ee9edcfb6ef5f4db190cbe1f09f5c0da21302178
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cad2d_ir_native-0.19.2-cp310-abi3-win_amd64.whl
| Download URL | cad2d_ir_native-0.19.2-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 936.2 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
d0b8d118fe34e6b26fca2b8c075e8114990230b0920d20725c7cd14158a12631
|
|
BLAKE2b-256 checksum How to use checksums |
8da94487003e34e858efbf9e1195d9092eac4a225002f1cfee3a1906e6596b90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cad2d_ir_native-0.19.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | cad2d_ir_native-0.19.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
145cbdcb1e9b10314128ff5fdcd51afd918caa72dbb22433c2b1ea4f71280a3e
|
|
BLAKE2b-256 checksum How to use checksums |
67d8ea0ab694ab304dd809392379ba64b757e3631500a3e60fd6236a574c568f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cad2d_ir_native-0.19.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | cad2d_ir_native-0.19.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
c696d4c29d8179c7db219607a402192866b54ebd392e8c2885b6096a9f4f4d8d
|
|
BLAKE2b-256 checksum How to use checksums |
8818c2eeffd7d690039fbbbdc3e6c0da6013481c1c7bab19f469b46b379f3968
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cad2d_ir_native-0.19.2-cp310-abi3-macosx_10_12_universal2.macosx_10_12_x86_64.macosx_11_0_arm64.whl
| Download URL | cad2d_ir_native-0.19.2-cp310-abi3-macosx_10_12_universal2.macosx_10_12_x86_64.macosx_11_0_arm64.whl |
|---|---|
| Size | 2.0 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
923df7d8a4c249b9663201175d1ce82ffe2ec4bdddf252eeda27b05c257b7b38
|
|
BLAKE2b-256 checksum How to use checksums |
93636e43fa9668aa19485a27bc6269d254a2611b7034997b6ac2f7a65bea94ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for cad2d-ir-native 0.19.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.