Skip to content

Commit 442a08f

Browse files
authored
Python support (#913)
Add a new cargo feature, 'python', which enables pyo3 bindings on some structs.
1 parent 51f8af5 commit 442a08f

File tree

11 files changed

+239
-2
lines changed

11 files changed

+239
-2
lines changed

Cargo.lock

Lines changed: 92 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modeling-cmds/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ convert_client_crate = ["dep:kittycad"]
2323
websocket = ["dep:serde_json"]
2424
webrtc = ["dep:webrtc"]
2525
unstable_exhaustive = []
26+
python = ["dep:pyo3"]
2627
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
2728

2829
[dependencies]
@@ -40,6 +41,7 @@ kittycad-unit-conversion-derive = "0.1.0"
4041
measurements = "0.11.0"
4142
parse-display = "0.9.1"
4243
parse-display-derive = "0.9.0"
44+
pyo3 = { version = "0.25.1", optional = true }
4345
schemars = { version = "0.8.22", features = [
4446
"bigdecimal04",
4547
"chrono",

modeling-cmds/src/format/dxf.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,19 @@ pub mod export {
2929
#[serde(rename = "DxfExportOptions")]
3030
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
3131
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
32+
#[cfg_attr(feature = "python", pyo3::pyclass)]
3233
pub struct Options {
3334
/// Export storage.
3435
pub storage: Storage,
3536
}
37+
38+
#[cfg(feature = "python")]
39+
#[pyo3::pymethods]
40+
impl Options {
41+
#[new]
42+
/// Set the options to their defaults.
43+
pub fn new() -> Self {
44+
Default::default()
45+
}
46+
}
3647
}

modeling-cmds/src/format/fbx.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@ pub mod import {
1111
#[serde(rename = "FbxImportOptions")]
1212
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1313
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
14+
#[cfg_attr(feature = "python", pyo3::pyclass)]
1415
pub struct Options {}
16+
17+
#[cfg(feature = "python")]
18+
#[pyo3::pymethods]
19+
impl Options {
20+
#[new]
21+
/// Set the options to their defaults.
22+
pub fn new() -> Self {
23+
Default::default()
24+
}
25+
}
1526
}
1627

1728
/// Export models in FBX format.
@@ -22,6 +33,7 @@ pub mod export {
2233
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema)]
2334
#[serde(rename = "FbxExportOptions")]
2435
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
36+
#[cfg_attr(feature = "python", pyo3::pyclass)]
2537
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2638
pub struct Options {
2739
/// Specifies which kind of FBX will be exported.
@@ -31,6 +43,16 @@ pub mod export {
3143
pub created: Option<chrono::DateTime<chrono::Utc>>,
3244
}
3345

46+
#[cfg(feature = "python")]
47+
#[pyo3::pymethods]
48+
impl Options {
49+
#[new]
50+
/// Set the options to their defaults.
51+
pub fn new() -> Self {
52+
Default::default()
53+
}
54+
}
55+
3456
impl std::fmt::Display for Options {
3557
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3658
write!(f, "storage: {}", self.storage)

modeling-cmds/src/format/gltf.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@ pub mod import {
1212
#[serde(rename = "GltfImportOptions")]
1313
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1414
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
15+
#[cfg_attr(feature = "python", pyo3::pyclass)]
1516
pub struct Options {}
17+
18+
#[cfg(feature = "python")]
19+
#[pyo3::pymethods]
20+
impl Options {
21+
#[new]
22+
/// Set the options to their defaults.
23+
pub fn new() -> Self {
24+
Default::default()
25+
}
26+
}
1627
}
1728

1829
/// Export models in KittyCAD's GLTF format.
@@ -23,6 +34,7 @@ pub mod export {
2334
#[display("storage: {storage}, presentation: {presentation}")]
2435
#[serde(rename = "GltfExportOptions")]
2536
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
37+
#[cfg_attr(feature = "python", pyo3::pyclass)]
2638
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2739
pub struct Options {
2840
/// Specifies which kind of glTF 2.0 will be exported.
@@ -31,6 +43,16 @@ pub mod export {
3143
pub presentation: Presentation,
3244
}
3345

46+
#[cfg(feature = "python")]
47+
#[pyo3::pymethods]
48+
impl Options {
49+
#[new]
50+
/// Set the options to their defaults.
51+
pub fn new() -> Self {
52+
Default::default()
53+
}
54+
}
55+
3456
/// Describes the storage format of a glTF 2.0 scene.
3557
#[derive(
3658
Default, Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,

modeling-cmds/src/format/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub type InputFormat = InputFormat3d;
7979
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
8080
#[serde(tag = "type", rename_all = "snake_case")]
8181
#[display(style = "snake_case")]
82+
#[cfg_attr(feature = "python", pyo3::pyclass)]
8283
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
8384
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
8485
pub enum InputFormat3d {

modeling-cmds/src/format/obj.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub mod import {
1414
#[serde(rename = "ObjImportOptions")]
1515
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1616
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
17+
#[cfg_attr(feature = "python", pyo3::pyclass)]
1718
pub struct Options {
1819
/// Co-ordinate system of input data.
1920
///
@@ -31,6 +32,16 @@ pub mod import {
3132
pub units: UnitLength,
3233
}
3334

35+
#[cfg(feature = "python")]
36+
#[pyo3::pymethods]
37+
impl Options {
38+
#[new]
39+
/// Set the options to their defaults.
40+
pub fn new() -> Self {
41+
Default::default()
42+
}
43+
}
44+
3445
impl Default for Options {
3546
fn default() -> Self {
3647
Self {
@@ -50,6 +61,7 @@ pub mod export {
5061
#[display("coords: {coords}, units: {units}")]
5162
#[serde(rename = "ObjExportOptions")]
5263
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
64+
#[cfg_attr(feature = "python", pyo3::pyclass)]
5365
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
5466
pub struct Options {
5567
/// Co-ordinate system of output data.
@@ -65,6 +77,16 @@ pub mod export {
6577
pub units: UnitLength,
6678
}
6779

80+
#[cfg(feature = "python")]
81+
#[pyo3::pymethods]
82+
impl Options {
83+
#[new]
84+
/// Set the options to their defaults.
85+
pub fn new() -> Self {
86+
Default::default()
87+
}
88+
}
89+
6890
impl Default for Options {
6991
fn default() -> Self {
7092
Self {

modeling-cmds/src/format/ply.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub mod import {
1414
#[serde(rename = "PlyImportOptions")]
1515
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1616
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
17+
#[cfg_attr(feature = "python", pyo3::pyclass)]
1718
pub struct Options {
1819
/// Co-ordinate system of input data.
1920
///
@@ -31,6 +32,16 @@ pub mod import {
3132
pub units: UnitLength,
3233
}
3334

35+
#[cfg(feature = "python")]
36+
#[pyo3::pymethods]
37+
impl Options {
38+
#[new]
39+
/// Set the options to their defaults.
40+
pub fn new() -> Self {
41+
Default::default()
42+
}
43+
}
44+
3445
impl Default for Options {
3546
fn default() -> Self {
3647
Self {
@@ -51,6 +62,7 @@ pub mod export {
5162
#[display("coords: {coords}, selection: {selection}, storage: {storage}, units: {units}")]
5263
#[serde(rename = "PlyExportOptions")]
5364
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
65+
#[cfg_attr(feature = "python", pyo3::pyclass)]
5466
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
5567
pub struct Options {
5668
/// Co-ordinate system of output data.
@@ -72,6 +84,16 @@ pub mod export {
7284
pub units: UnitLength,
7385
}
7486

87+
#[cfg(feature = "python")]
88+
#[pyo3::pymethods]
89+
impl Options {
90+
#[new]
91+
/// Set the options to their defaults.
92+
pub fn new() -> Self {
93+
Default::default()
94+
}
95+
}
96+
7597
impl Default for Options {
7698
fn default() -> Self {
7799
Self {

0 commit comments

Comments
 (0)