rlbot-flatbuffers 0.14.4__tar.gz → 0.14.6__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.
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/Cargo.lock +25 -25
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/Cargo.toml +2 -2
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/PKG-INFO +1 -1
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/codegen/enums.rs +17 -67
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/codegen/main.rs +10 -30
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/codegen/pyi.rs +23 -39
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/codegen/structs.rs +122 -218
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/codegen/unions.rs +11 -54
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/src/lib.rs +3 -15
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/LICENSE +0 -0
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/README.md +0 -0
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/codegen/class_inject.rs +0 -0
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/codegen/generator.rs +0 -0
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/flatbuffers-schema/FLATBUFFERS-LICENSE +0 -0
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/flatbuffers-schema/README.md +0 -0
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/flatbuffers-schema/comms.fbs +0 -0
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/flatbuffers-schema/flatc +0 -0
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/flatbuffers-schema/flatc.exe +0 -0
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/flatbuffers-schema/gamedata.fbs +0 -0
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/flatbuffers-schema/gamestatemanip.fbs +0 -0
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/flatbuffers-schema/matchconfig.fbs +0 -0
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/flatbuffers-schema/rendering.fbs +0 -0
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/flatbuffers-schema/rlbot.fbs +0 -0
- {rlbot_flatbuffers-0.14.4 → rlbot_flatbuffers-0.14.6}/pyproject.toml +0 -0
|
@@ -115,9 +115,9 @@ checksum = "71dd52191aae121e8611f1e8dc3e324dd0dd1dee1e6dd91d10ee07a3cfb4d9d8"
|
|
|
115
115
|
|
|
116
116
|
[[package]]
|
|
117
117
|
name = "libc"
|
|
118
|
-
version = "0.2.
|
|
118
|
+
version = "0.2.171"
|
|
119
119
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
120
|
-
checksum = "
|
|
120
|
+
checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"
|
|
121
121
|
|
|
122
122
|
[[package]]
|
|
123
123
|
name = "manyhow"
|
|
@@ -153,9 +153,9 @@ dependencies = [
|
|
|
153
153
|
|
|
154
154
|
[[package]]
|
|
155
155
|
name = "once_cell"
|
|
156
|
-
version = "1.
|
|
156
|
+
version = "1.21.1"
|
|
157
157
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
158
|
-
checksum = "
|
|
158
|
+
checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc"
|
|
159
159
|
|
|
160
160
|
[[package]]
|
|
161
161
|
name = "portable-atomic"
|
|
@@ -185,9 +185,9 @@ dependencies = [
|
|
|
185
185
|
|
|
186
186
|
[[package]]
|
|
187
187
|
name = "pyo3"
|
|
188
|
-
version = "0.
|
|
188
|
+
version = "0.24.0"
|
|
189
189
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
190
|
-
checksum = "
|
|
190
|
+
checksum = "7f1c6c3591120564d64db2261bec5f910ae454f01def849b9c22835a84695e86"
|
|
191
191
|
dependencies = [
|
|
192
192
|
"cfg-if",
|
|
193
193
|
"indoc",
|
|
@@ -203,9 +203,9 @@ dependencies = [
|
|
|
203
203
|
|
|
204
204
|
[[package]]
|
|
205
205
|
name = "pyo3-build-config"
|
|
206
|
-
version = "0.
|
|
206
|
+
version = "0.24.0"
|
|
207
207
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
208
|
-
checksum = "
|
|
208
|
+
checksum = "e9b6c2b34cf71427ea37c7001aefbaeb85886a074795e35f161f5aecc7620a7a"
|
|
209
209
|
dependencies = [
|
|
210
210
|
"once_cell",
|
|
211
211
|
"target-lexicon",
|
|
@@ -213,9 +213,9 @@ dependencies = [
|
|
|
213
213
|
|
|
214
214
|
[[package]]
|
|
215
215
|
name = "pyo3-ffi"
|
|
216
|
-
version = "0.
|
|
216
|
+
version = "0.24.0"
|
|
217
217
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
218
|
-
checksum = "
|
|
218
|
+
checksum = "5507651906a46432cdda02cd02dd0319f6064f1374c9147c45b978621d2c3a9c"
|
|
219
219
|
dependencies = [
|
|
220
220
|
"libc",
|
|
221
221
|
"pyo3-build-config",
|
|
@@ -223,9 +223,9 @@ dependencies = [
|
|
|
223
223
|
|
|
224
224
|
[[package]]
|
|
225
225
|
name = "pyo3-macros"
|
|
226
|
-
version = "0.
|
|
226
|
+
version = "0.24.0"
|
|
227
227
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
228
|
-
checksum = "
|
|
228
|
+
checksum = "b0d394b5b4fd8d97d48336bb0dd2aebabad39f1d294edd6bcd2cccf2eefe6f42"
|
|
229
229
|
dependencies = [
|
|
230
230
|
"proc-macro2",
|
|
231
231
|
"pyo3-macros-backend",
|
|
@@ -235,9 +235,9 @@ dependencies = [
|
|
|
235
235
|
|
|
236
236
|
[[package]]
|
|
237
237
|
name = "pyo3-macros-backend"
|
|
238
|
-
version = "0.
|
|
238
|
+
version = "0.24.0"
|
|
239
239
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
240
|
-
checksum = "
|
|
240
|
+
checksum = "fd72da09cfa943b1080f621f024d2ef7e2773df7badd51aa30a2be1f8caa7c8e"
|
|
241
241
|
dependencies = [
|
|
242
242
|
"heck",
|
|
243
243
|
"proc-macro2",
|
|
@@ -248,9 +248,9 @@ dependencies = [
|
|
|
248
248
|
|
|
249
249
|
[[package]]
|
|
250
250
|
name = "quote"
|
|
251
|
-
version = "1.0.
|
|
251
|
+
version = "1.0.40"
|
|
252
252
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
253
|
-
checksum = "
|
|
253
|
+
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
|
254
254
|
dependencies = [
|
|
255
255
|
"proc-macro2",
|
|
256
256
|
]
|
|
@@ -279,7 +279,7 @@ dependencies = [
|
|
|
279
279
|
|
|
280
280
|
[[package]]
|
|
281
281
|
name = "rlbot_flatbuffers"
|
|
282
|
-
version = "0.14.
|
|
282
|
+
version = "0.14.6"
|
|
283
283
|
dependencies = [
|
|
284
284
|
"flatbuffers",
|
|
285
285
|
"get-size",
|
|
@@ -304,18 +304,18 @@ checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0"
|
|
|
304
304
|
|
|
305
305
|
[[package]]
|
|
306
306
|
name = "serde"
|
|
307
|
-
version = "1.0.
|
|
307
|
+
version = "1.0.219"
|
|
308
308
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
309
|
-
checksum = "
|
|
309
|
+
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
|
|
310
310
|
dependencies = [
|
|
311
311
|
"serde_derive",
|
|
312
312
|
]
|
|
313
313
|
|
|
314
314
|
[[package]]
|
|
315
315
|
name = "serde_derive"
|
|
316
|
-
version = "1.0.
|
|
316
|
+
version = "1.0.219"
|
|
317
317
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
318
|
-
checksum = "
|
|
318
|
+
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
|
|
319
319
|
dependencies = [
|
|
320
320
|
"proc-macro2",
|
|
321
321
|
"quote",
|
|
@@ -330,9 +330,9 @@ checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd"
|
|
|
330
330
|
|
|
331
331
|
[[package]]
|
|
332
332
|
name = "syn"
|
|
333
|
-
version = "2.0.
|
|
333
|
+
version = "2.0.100"
|
|
334
334
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
335
|
-
checksum = "
|
|
335
|
+
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
|
|
336
336
|
dependencies = [
|
|
337
337
|
"proc-macro2",
|
|
338
338
|
"quote",
|
|
@@ -341,9 +341,9 @@ dependencies = [
|
|
|
341
341
|
|
|
342
342
|
[[package]]
|
|
343
343
|
name = "target-lexicon"
|
|
344
|
-
version = "0.
|
|
344
|
+
version = "0.13.2"
|
|
345
345
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
346
|
-
checksum = "
|
|
346
|
+
checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a"
|
|
347
347
|
|
|
348
348
|
[[package]]
|
|
349
349
|
name = "unicode-ident"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "rlbot_flatbuffers"
|
|
3
|
-
version = "0.14.
|
|
3
|
+
version = "0.14.6"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
description = "A Python module implemented in Rust for serializing and deserializing RLBot's flatbuffers"
|
|
6
6
|
repository = "https://github.com/VirxEC/rlbot_flatbuffers_py"
|
|
@@ -18,7 +18,7 @@ all = "warn"
|
|
|
18
18
|
crate-type = ["cdylib"]
|
|
19
19
|
|
|
20
20
|
[dependencies]
|
|
21
|
-
pyo3 = { version = "0.
|
|
21
|
+
pyo3 = { version = "0.24.0", features = [] }
|
|
22
22
|
serde = "1.0.217"
|
|
23
23
|
flatbuffers = "=25.2.10"
|
|
24
24
|
# get-size appears to be unmaintained but it's too useful here
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rlbot_flatbuffers
|
|
3
|
-
Version: 0.14.
|
|
3
|
+
Version: 0.14.6
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
@@ -16,10 +16,7 @@ fn camel_to_snake_case(variable_name: &str) -> String {
|
|
|
16
16
|
for c in variable_name.chars() {
|
|
17
17
|
if c.is_uppercase() {
|
|
18
18
|
if last_was_uppercase {
|
|
19
|
-
snake_case_parts
|
|
20
|
-
.last_mut()
|
|
21
|
-
.unwrap()
|
|
22
|
-
.push(c.to_lowercase().next().unwrap());
|
|
19
|
+
snake_case_parts.last_mut().unwrap().push(c.to_lowercase().next().unwrap());
|
|
23
20
|
} else {
|
|
24
21
|
snake_case_parts.push(c.to_lowercase().to_string());
|
|
25
22
|
}
|
|
@@ -80,9 +77,7 @@ impl EnumBindGenerator {
|
|
|
80
77
|
})
|
|
81
78
|
}
|
|
82
79
|
|
|
83
|
-
pub fn raw_types_to_custom(
|
|
84
|
-
raw_types: Vec<(&str, &str, Option<Vec<String>>)>,
|
|
85
|
-
) -> Vec<CustomEnumType> {
|
|
80
|
+
pub fn raw_types_to_custom(raw_types: Vec<(&str, &str, Option<Vec<String>>)>) -> Vec<CustomEnumType> {
|
|
86
81
|
raw_types
|
|
87
82
|
.into_iter()
|
|
88
83
|
.map(|(name, raw_type, doc_str)| CustomEnumType {
|
|
@@ -129,17 +124,12 @@ impl EnumBindGenerator {
|
|
|
129
124
|
continue;
|
|
130
125
|
}
|
|
131
126
|
|
|
132
|
-
let definition = line_trim
|
|
133
|
-
.trim_start_matches("pub const ")
|
|
134
|
-
.trim_end_matches(';');
|
|
127
|
+
let definition = line_trim.trim_start_matches("pub const ").trim_end_matches(';');
|
|
135
128
|
|
|
136
129
|
let mut parts = definition.split(": Self = ");
|
|
137
130
|
|
|
138
131
|
let variable_name = parts.next()?;
|
|
139
|
-
let variable_value = parts
|
|
140
|
-
.next()?
|
|
141
|
-
.trim_start_matches("Self(")
|
|
142
|
-
.trim_end_matches(')');
|
|
132
|
+
let variable_value = parts.next()?.trim_start_matches("Self(").trim_end_matches(')');
|
|
143
133
|
|
|
144
134
|
let docs = if docs.is_empty() {
|
|
145
135
|
None
|
|
@@ -169,14 +159,11 @@ impl EnumBindGenerator {
|
|
|
169
159
|
let union_end_definition = "}\n";
|
|
170
160
|
let union_end = contents[union_start..].find(union_end_definition).unwrap();
|
|
171
161
|
|
|
172
|
-
let union_definition =
|
|
173
|
-
..union_start + union_end - union_end_definition.len()];
|
|
162
|
+
let union_definition =
|
|
163
|
+
&contents[union_start + union_definition.len()..union_start + union_end - union_end_definition.len()];
|
|
174
164
|
|
|
175
165
|
for (line, variable) in union_definition.split('\n').zip(&mut custom_types) {
|
|
176
|
-
let line_trim = line
|
|
177
|
-
.trim()
|
|
178
|
-
.trim_start_matches(&variable.name)
|
|
179
|
-
.trim_end_matches(',');
|
|
166
|
+
let line_trim = line.trim().trim_start_matches(&variable.name).trim_end_matches(',');
|
|
180
167
|
|
|
181
168
|
if line_trim.is_empty() {
|
|
182
169
|
variable.value = None;
|
|
@@ -185,9 +172,7 @@ impl EnumBindGenerator {
|
|
|
185
172
|
|
|
186
173
|
variable.snake_case_name = camel_to_snake_case(variable.name.as_str());
|
|
187
174
|
|
|
188
|
-
let new_type = line_trim
|
|
189
|
-
.trim_start_matches("(Box<")
|
|
190
|
-
.trim_end_matches("T>)");
|
|
175
|
+
let new_type = line_trim.trim_start_matches("(Box<").trim_end_matches("T>)");
|
|
191
176
|
variable.value = Some(new_type.to_string());
|
|
192
177
|
}
|
|
193
178
|
|
|
@@ -204,11 +189,7 @@ impl EnumBindGenerator {
|
|
|
204
189
|
|
|
205
190
|
for variable_info in &self.types {
|
|
206
191
|
let variable_name = variable_info.name.as_str();
|
|
207
|
-
write_fmt!(
|
|
208
|
-
self,
|
|
209
|
-
" {} => Ok(Self::{variable_name}),",
|
|
210
|
-
variable_info.raw_type
|
|
211
|
-
);
|
|
192
|
+
write_fmt!(self, " {} => Ok(Self::{variable_name}),", variable_info.raw_type);
|
|
212
193
|
}
|
|
213
194
|
|
|
214
195
|
if self.types.len() != usize::from(u8::MAX) {
|
|
@@ -256,10 +237,7 @@ impl Generator for EnumBindGenerator {
|
|
|
256
237
|
contents = contents.replace("\r\n", "\n");
|
|
257
238
|
}
|
|
258
239
|
|
|
259
|
-
contents = contents.replace(
|
|
260
|
-
"use self::flatbuffers",
|
|
261
|
-
"use get_size::GetSize;\nuse self::flatbuffers",
|
|
262
|
-
);
|
|
240
|
+
contents = contents.replace("use self::flatbuffers", "use get_size::GetSize;\nuse self::flatbuffers");
|
|
263
241
|
|
|
264
242
|
contents = contents.replace(
|
|
265
243
|
"#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]\n",
|
|
@@ -288,14 +266,8 @@ impl Generator for EnumBindGenerator {
|
|
|
288
266
|
|
|
289
267
|
fn generate_definition(&mut self) {
|
|
290
268
|
write_str!(self, "#[allow(non_camel_case_types)]");
|
|
291
|
-
write_str!(
|
|
292
|
-
|
|
293
|
-
"#[pyclass(module = \"rlbot_flatbuffers\", frozen, hash, eq, eq_int)]"
|
|
294
|
-
);
|
|
295
|
-
write_str!(
|
|
296
|
-
self,
|
|
297
|
-
"#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]"
|
|
298
|
-
);
|
|
269
|
+
write_str!(self, "#[pyclass(module = \"rlbot_flatbuffers\", frozen, hash, eq, eq_int)]");
|
|
270
|
+
write_str!(self, "#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]");
|
|
299
271
|
write_fmt!(self, "pub enum {} {{", self.struct_name);
|
|
300
272
|
write_str!(self, " #[default]");
|
|
301
273
|
|
|
@@ -309,17 +281,8 @@ impl Generator for EnumBindGenerator {
|
|
|
309
281
|
}
|
|
310
282
|
|
|
311
283
|
fn generate_from_flat_impls(&mut self) {
|
|
312
|
-
write_fmt!(
|
|
313
|
-
|
|
314
|
-
"impl From<flat::{}> for {} {{",
|
|
315
|
-
self.struct_name,
|
|
316
|
-
self.struct_name
|
|
317
|
-
);
|
|
318
|
-
write_fmt!(
|
|
319
|
-
self,
|
|
320
|
-
" fn from(flat_t: flat::{}) -> Self {{",
|
|
321
|
-
self.struct_name
|
|
322
|
-
);
|
|
284
|
+
write_fmt!(self, "impl From<flat::{}> for {} {{", self.struct_name, self.struct_name);
|
|
285
|
+
write_fmt!(self, " fn from(flat_t: flat::{}) -> Self {{", self.struct_name);
|
|
323
286
|
write_str!(self, " match flat_t {");
|
|
324
287
|
|
|
325
288
|
for variable_info in &self.types {
|
|
@@ -332,11 +295,7 @@ impl Generator for EnumBindGenerator {
|
|
|
332
295
|
);
|
|
333
296
|
}
|
|
334
297
|
|
|
335
|
-
write_fmt!(
|
|
336
|
-
self,
|
|
337
|
-
" _ => Self::{},",
|
|
338
|
-
self.types.last().unwrap().name.as_str()
|
|
339
|
-
);
|
|
298
|
+
write_fmt!(self, " _ => Self::{},", self.types.last().unwrap().name.as_str());
|
|
340
299
|
|
|
341
300
|
write_str!(self, " }");
|
|
342
301
|
write_str!(self, " }");
|
|
@@ -345,17 +304,8 @@ impl Generator for EnumBindGenerator {
|
|
|
345
304
|
}
|
|
346
305
|
|
|
347
306
|
fn generate_to_flat_impls(&mut self) {
|
|
348
|
-
write_fmt!(
|
|
349
|
-
|
|
350
|
-
"impl From<&{}> for flat::{} {{",
|
|
351
|
-
self.struct_name,
|
|
352
|
-
self.struct_name
|
|
353
|
-
);
|
|
354
|
-
write_fmt!(
|
|
355
|
-
self,
|
|
356
|
-
" fn from(py_type: &{}) -> Self {{",
|
|
357
|
-
self.struct_name
|
|
358
|
-
);
|
|
307
|
+
write_fmt!(self, "impl From<&{}> for flat::{} {{", self.struct_name, self.struct_name);
|
|
308
|
+
write_fmt!(self, " fn from(py_type: &{}) -> Self {{", self.struct_name);
|
|
359
309
|
write_str!(self, " match *py_type {");
|
|
360
310
|
|
|
361
311
|
for variable_info in &self.types {
|
|
@@ -53,15 +53,10 @@ impl PythonBindType {
|
|
|
53
53
|
"PredictionSlice",
|
|
54
54
|
"BallPrediction",
|
|
55
55
|
];
|
|
56
|
-
pub const UNIONS: [&'static str; 4] = [
|
|
57
|
-
"PlayerClass",
|
|
58
|
-
"CollisionShape",
|
|
59
|
-
"RelativeAnchor",
|
|
60
|
-
"RenderType",
|
|
61
|
-
];
|
|
56
|
+
pub const UNIONS: [&'static str; 4] = ["PlayerClass", "CollisionShape", "RelativeAnchor", "RenderType"];
|
|
62
57
|
|
|
63
|
-
pub const
|
|
64
|
-
|
|
58
|
+
pub const OPTIONAL_UNIONS: [&'static str; 1] = ["RelativeAnchor"];
|
|
59
|
+
pub const DEFAULT_OVERRIDES: [(&'static str, &'static str, &'static str); 1] = [("Color", "a", "255")];
|
|
65
60
|
pub const FREELIST_TYPES: [(&'static str, usize); 0] = [];
|
|
66
61
|
|
|
67
62
|
fn new(path: &Path) -> Option<Self> {
|
|
@@ -106,12 +101,7 @@ impl PythonBindType {
|
|
|
106
101
|
let struct_doc_str = if docs.is_empty() {
|
|
107
102
|
None
|
|
108
103
|
} else {
|
|
109
|
-
Some(
|
|
110
|
-
docs.into_iter()
|
|
111
|
-
.map(|s| s.to_string())
|
|
112
|
-
.rev()
|
|
113
|
-
.collect::<Vec<_>>(),
|
|
114
|
-
)
|
|
104
|
+
Some(docs.into_iter().map(|s| s.to_string()).rev().collect::<Vec<_>>())
|
|
115
105
|
};
|
|
116
106
|
|
|
117
107
|
if let Some(types) = StructBindGenerator::get_types(&contents, &struct_t_name) {
|
|
@@ -125,15 +115,11 @@ impl PythonBindType {
|
|
|
125
115
|
)?));
|
|
126
116
|
}
|
|
127
117
|
|
|
128
|
-
if let Some((types, enum_type)) =
|
|
129
|
-
enums::EnumBindGenerator::get_types(&contents, &struct_name)
|
|
130
|
-
{
|
|
118
|
+
if let Some((types, enum_type)) = enums::EnumBindGenerator::get_types(&contents, &struct_name) {
|
|
131
119
|
return Some(match enum_type {
|
|
132
|
-
enums::EnumType::Enum =>
|
|
133
|
-
filename.to_string(),
|
|
134
|
-
|
|
135
|
-
types,
|
|
136
|
-
)?),
|
|
120
|
+
enums::EnumType::Enum => {
|
|
121
|
+
Self::Enum(enums::EnumBindGenerator::new(filename.to_string(), struct_name, types)?)
|
|
122
|
+
}
|
|
137
123
|
enums::EnumType::Union => Self::Union(unions::UnionBindGenerator::new(
|
|
138
124
|
filename.to_string(),
|
|
139
125
|
struct_name,
|
|
@@ -183,10 +169,7 @@ fn mod_rs_generator(type_data: &[PythonBindType]) -> io::Result<()> {
|
|
|
183
169
|
|
|
184
170
|
file_contents.push(Cow::Borrowed(""));
|
|
185
171
|
|
|
186
|
-
fs::write(
|
|
187
|
-
format!("{PYTHON_OUT_FOLDER}/mod.rs"),
|
|
188
|
-
file_contents.join("\n"),
|
|
189
|
-
)?;
|
|
172
|
+
fs::write(format!("{PYTHON_OUT_FOLDER}/mod.rs"), file_contents.join("\n"))?;
|
|
190
173
|
|
|
191
174
|
Ok(())
|
|
192
175
|
}
|
|
@@ -204,10 +187,7 @@ fn run_flatc() -> io::Result<()> {
|
|
|
204
187
|
let mut schema_folder = Path::new(SCHEMA_FOLDER);
|
|
205
188
|
if !schema_folder.exists() {
|
|
206
189
|
schema_folder = Path::new(SCHEMA_FOLDER_BACKUP);
|
|
207
|
-
assert!(
|
|
208
|
-
schema_folder.exists(),
|
|
209
|
-
"Could not find flatbuffers schema folder"
|
|
210
|
-
);
|
|
190
|
+
assert!(schema_folder.exists(), "Could not find flatbuffers schema folder");
|
|
211
191
|
}
|
|
212
192
|
|
|
213
193
|
let schema_folder_str = schema_folder.display();
|
|
@@ -93,16 +93,10 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
|
|
|
93
93
|
write_str!(file, " def __new__(cls, value: int = 0): ...");
|
|
94
94
|
write_str!(file, " def __init__(self, value: int = 0):");
|
|
95
95
|
write_str!(file, " \"\"\"");
|
|
96
|
-
write_str!(
|
|
97
|
-
file,
|
|
98
|
-
" :raises ValueError: If the `value` is not a valid enum value"
|
|
99
|
-
);
|
|
96
|
+
write_str!(file, " :raises ValueError: If the `value` is not a valid enum value");
|
|
100
97
|
write_str!(file, " \"\"\"");
|
|
101
98
|
write_str!(file, " def __int__(self) -> int: ...");
|
|
102
|
-
write_fmt!(
|
|
103
|
-
file,
|
|
104
|
-
" def __eq__(self, other: {type_name}) -> bool: ..."
|
|
105
|
-
);
|
|
99
|
+
write_fmt!(file, " def __eq__(self, other: {type_name}) -> bool: ...");
|
|
106
100
|
write_str!(file, " def __hash__(self) -> str: ...");
|
|
107
101
|
}
|
|
108
102
|
PythonBindType::Struct(bind) => {
|
|
@@ -208,32 +202,32 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
|
|
|
208
202
|
python_types.push("str".to_string());
|
|
209
203
|
write_fmt!(file, " {variable_name}: str");
|
|
210
204
|
}
|
|
211
|
-
RustType::Union(type_name) => {
|
|
212
|
-
|
|
205
|
+
RustType::Union(type_name, is_optional) => {
|
|
206
|
+
if *is_optional {
|
|
207
|
+
write_fmt!(file, " {variable_name}: Optional[{type_name}]");
|
|
208
|
+
} else {
|
|
209
|
+
write_fmt!(file, " {variable_name}: {type_name}");
|
|
210
|
+
}
|
|
213
211
|
|
|
214
212
|
// search for the union with the name `type_name` and get the types
|
|
215
213
|
let union_types = type_data
|
|
216
214
|
.iter()
|
|
217
215
|
.find_map(|item| match item {
|
|
218
|
-
PythonBindType::Union(bind)
|
|
219
|
-
|
|
220
|
-
{
|
|
221
|
-
Some(
|
|
222
|
-
bind.types
|
|
223
|
-
.iter()
|
|
224
|
-
.skip(1)
|
|
225
|
-
.map(|v| v.name.as_str())
|
|
226
|
-
.collect::<Vec<_>>(),
|
|
227
|
-
)
|
|
216
|
+
PythonBindType::Union(bind) if bind.struct_name() == type_name => {
|
|
217
|
+
Some(bind.types.iter().skip(1).map(|v| v.name.as_str()).collect::<Vec<_>>())
|
|
228
218
|
}
|
|
229
219
|
_ => None,
|
|
230
220
|
})
|
|
231
221
|
.unwrap();
|
|
232
|
-
|
|
222
|
+
|
|
223
|
+
let python_type = union_types.join(" | ");
|
|
224
|
+
python_types.push(if *is_optional {
|
|
225
|
+
format!("Optional[{python_type}]")
|
|
226
|
+
} else {
|
|
227
|
+
python_type
|
|
228
|
+
});
|
|
233
229
|
}
|
|
234
|
-
RustType::Custom(type_name)
|
|
235
|
-
| RustType::Other(type_name)
|
|
236
|
-
| RustType::Base(type_name) => {
|
|
230
|
+
RustType::Custom(type_name) | RustType::Other(type_name) | RustType::Base(type_name) => {
|
|
237
231
|
python_types.push(type_name.to_string());
|
|
238
232
|
write_fmt!(file, " {variable_name}: {type_name}");
|
|
239
233
|
}
|
|
@@ -276,10 +270,7 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
|
|
|
276
270
|
|
|
277
271
|
if let Some((field, value)) = bind.default_override {
|
|
278
272
|
if field == variable_name {
|
|
279
|
-
write_fmt!(
|
|
280
|
-
file,
|
|
281
|
-
" {variable_name}: {python_type} = {value},"
|
|
282
|
-
);
|
|
273
|
+
write_fmt!(file, " {variable_name}: {python_type} = {value},");
|
|
283
274
|
continue;
|
|
284
275
|
}
|
|
285
276
|
}
|
|
@@ -290,19 +281,15 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
|
|
|
290
281
|
"String" => Cow::Borrowed("\"\""),
|
|
291
282
|
"Vec<u8>" => Cow::Borrowed("b\"\""),
|
|
292
283
|
t => {
|
|
293
|
-
if python_type.starts_with("Optional")
|
|
294
|
-
|| t.starts_with("Option<")
|
|
295
|
-
{
|
|
284
|
+
if python_type.starts_with("Optional") || t.starts_with("Option<") {
|
|
296
285
|
Cow::Borrowed("None")
|
|
297
286
|
} else if let Some(pos) = python_type.find('|') {
|
|
298
287
|
Cow::Owned(format!("{}()", &python_type[..pos - 1]))
|
|
299
288
|
} else if t.starts_with("Vec<") {
|
|
300
289
|
Cow::Borrowed("[]")
|
|
301
290
|
} else if t.starts_with("Box<") {
|
|
302
|
-
let inner_type =
|
|
303
|
-
.trim_start_matches("Box<")
|
|
304
|
-
.trim_end_matches('>')
|
|
305
|
-
.trim_end_matches('T');
|
|
291
|
+
let inner_type =
|
|
292
|
+
t.trim_start_matches("Box<").trim_end_matches('>').trim_end_matches('T');
|
|
306
293
|
Cow::Owned(format!("{inner_type}()"))
|
|
307
294
|
} else {
|
|
308
295
|
Cow::Owned(format!("{}()", t.trim_end_matches('T')))
|
|
@@ -310,10 +297,7 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
|
|
|
310
297
|
}
|
|
311
298
|
};
|
|
312
299
|
|
|
313
|
-
write_fmt!(
|
|
314
|
-
file,
|
|
315
|
-
" {variable_name}: {python_type} = {default_value},"
|
|
316
|
-
);
|
|
300
|
+
write_fmt!(file, " {variable_name}: {python_type} = {default_value},");
|
|
317
301
|
}
|
|
318
302
|
|
|
319
303
|
write_str!(file, " ): ...");
|