Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create objects for delegating components #3303

Merged
merged 19 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/re_types/source_hash.txt

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

39 changes: 34 additions & 5 deletions crates/re_types_builder/src/codegen/python.rs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl PythonCodeGenerator {
let name = &obj.name;

if obj.is_delegating_component() {
vec![format!("{name}Array"), format!("{name}Type")]
vec![name.clone(), format!("{name}Array"), format!("{name}Type")]
} else {
vec![
format!("{name}"),
Expand Down Expand Up @@ -516,10 +516,11 @@ fn code_for_struct(

let mut code = String::new();

if *kind != ObjectKind::Component || obj.is_non_delegating_component() {
// field converters preprocessing pass — must be performed here because we must autogen
// converter function *before* the class
let mut field_converters: HashMap<String, String> = HashMap::new();

if !obj.is_delegating_component() {
for field in fields {
let (default_converter, converter_function) =
quote_field_converter_from_field(obj, objects, field);
Expand Down Expand Up @@ -552,6 +553,7 @@ fn code_for_struct(
};
field_converters.insert(field.fqname.clone(), converter);
}
}

// If the `ExtensionClass` has its own `__init__` then we need to pass the `init=False` argument
// to the `@define` decorator, to prevent it from generating its own `__init__`, which would
Expand All @@ -566,11 +568,20 @@ fn code_for_struct(
let mut superclasses = vec![];

if *kind == ObjectKind::Archetype {
superclasses.push("Archetype");
superclasses.push("Archetype".to_owned());
}

if ext_class.found {
superclasses.push(ext_class.name.as_str());
superclasses.push(ext_class.name.clone());
}

// Delegating component inheritance comes after the `ExtensionClass`
// This way if a component needs to override `__init__` it still can.
if obj.is_delegating_component() {
superclasses.push(format!(
"datatypes.{}",
obj.delegate_datatype(objects).unwrap().name
));
}

let superclass_decl = if superclasses.is_empty() {
Expand All @@ -594,10 +605,16 @@ fn code_for_struct(
format!("({define_args})")
};

let define_decorator = if obj.is_delegating_component() {
String::new()
} else {
format!("@define{define_args}")
};

code.push_unindented_text(
format!(
r#"
@define{define_args}
{define_decorator}
class {name}{superclass_decl}:
"#
),
Expand Down Expand Up @@ -634,6 +651,18 @@ fn code_for_struct(
);
}

if obj.is_delegating_component() {
code.push_text(
format!(
"# Note: there are no fields here because {} delegates to datatypes.{}",
obj.name,
obj.delegate_datatype(objects).unwrap().name
),
1,
4,
);
code.push_text("pass", 2, 4);
} else {
// NOTE: We need to add required fields first, and then optional ones, otherwise mypy
// complains.
// TODO(ab, #2641): this is required because fields without default should appear before fields
Expand Down
69 changes: 46 additions & 23 deletions rerun_py/rerun_sdk/rerun/_rerun2/components/__init__.py

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

This file was deleted.

9 changes: 8 additions & 1 deletion rerun_py/rerun_sdk/rerun/_rerun2/components/affix_fuzzer1.py

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

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

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

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

Loading