Skip to content

Commit

Permalink
enum codegen for Python (#5319)
Browse files Browse the repository at this point in the history
### What
* Part of #3384

Even includes codegen of the arrow serialization, which is a first for
Python.

Best reviewed commit-by-commit

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using newly built examples:
[app.rerun.io](https://app.rerun.io/pr/5319/index.html)
* Using examples from latest `main` build:
[app.rerun.io](https://app.rerun.io/pr/5319/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[app.rerun.io](https://app.rerun.io/pr/5319/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/5319)
- [Docs
preview](https://rerun.io/preview/2f1d162e5f221d9c0a78b1bcff1524fec67e110c/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/2f1d162e5f221d9c0a78b1bcff1524fec67e110c/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
  • Loading branch information
emilk authored Feb 28, 2024
1 parent 27cbc3d commit ce361be
Show file tree
Hide file tree
Showing 17 changed files with 701 additions and 114 deletions.
1 change: 1 addition & 0 deletions crates/re_types/definitions/rerun/datatypes.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ include "./datatypes/vec2d.fbs";
include "./datatypes/vec3d.fbs";
include "./datatypes/vec4d.fbs";

include "./testing/datatypes/enum.fbs";

namespace rerun.datatypes;
22 changes: 22 additions & 0 deletions crates/re_types/definitions/rerun/testing/datatypes/enum.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace rerun.testing.datatypes;

/// A test of the enum type.
enum EnumTest: byte {
/// Great film.
Up,

/// Feeling blue.
Down,

/// Correct.
Right,

/// It's what's remaining.
Left,

/// It's the only way to go.
Forward,

/// Baby's got it.
Back,
}
1 change: 1 addition & 0 deletions crates/re_types/src/testing/datatypes/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

203 changes: 203 additions & 0 deletions crates/re_types/src/testing/datatypes/enum_test.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/re_types/src/testing/datatypes/mod.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions crates/re_types_builder/src/codegen/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,29 @@ pub fn collect_examples_for_api_docs<'a>(
}

pub trait StringExt {
fn push_text(&mut self, text: impl AsRef<str>, linefeeds: usize, indent: usize) -> &mut Self;
fn push_unindented_text(&mut self, text: impl AsRef<str>, linefeeds: usize) -> &mut Self;
fn push_indented(
&mut self,
indent_level: usize,
text: impl AsRef<str>,
linefeeds: usize,
) -> &mut Self;

fn push_unindented(&mut self, text: impl AsRef<str>, linefeeds: usize) -> &mut Self;
}

impl StringExt for String {
fn push_text(&mut self, text: impl AsRef<str>, linefeeds: usize, indent: usize) -> &mut Self {
self.push_str(&indent::indent_all_by(indent, text.as_ref()));
fn push_indented(
&mut self,
indent_level: usize,
text: impl AsRef<str>,
linefeeds: usize,
) -> &mut Self {
self.push_str(&indent::indent_all_by(indent_level * 4, text.as_ref()));
self.push_str(&vec!["\n"; linefeeds].join(""));
self
}

fn push_unindented_text(&mut self, text: impl AsRef<str>, linefeeds: usize) -> &mut Self {
fn push_unindented(&mut self, text: impl AsRef<str>, linefeeds: usize) -> &mut Self {
self.push_str(&unindent::unindent(text.as_ref()));
self.push_str(&vec!["\n"; linefeeds].join(""));
self
Expand Down
Loading

0 comments on commit ce361be

Please sign in to comment.