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

Add Python binding for UsdValidatorMetadata #3232

Conversation

roggiezhang-nv
Copy link
Contributor

Description of Change(s)

Add Python binding for UsdValidatorMetadata.

It is stacked on #3223 for adding Python bindings for validator framework.

Fixes Issue(s)

  • I have verified that all unit tests pass with the proposed changes
  • I have submitted a signed Contributor License Agreement

@roggiezhang-nv
Copy link
Contributor Author

@nvmkuruc for vis.

@jesschimein
Copy link
Contributor

Filed as internal issue #USD-9985

@jesschimein
Copy link
Contributor

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@tallytalwar tallytalwar left a comment

Choose a reason for hiding this comment

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

Left a note about modifying the usage of add_property for metadata data members which work off a token vector. Thanks

.add_property("name", &_GetMetadataName, &_SetMetadataName)
.add_property("plugin", &_GetMetadataPlugin, &_SetMetadataPlugin)
.add_property("keywords", make_function(
&_GetMetadataKeywords, return_value_policy<TfPySequenceToList>()), _SetMetadataKeywords)
Copy link
Contributor

@tallytalwar tallytalwar Aug 16, 2024

Choose a reason for hiding this comment

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

I was having some good discussion with Alex here at Pixar about python APIs and how it might be confusing for a python developer to not be able to do something like: metadata.keywords[0] = "foo". We also discussed and have many examples of this in our code base where we wrap something as a python property if value of the type is immutable in python.

So that gets me to, will it make more sense to provide a GetKeywords/SetKeywords (and similarly for schemaTypes below) which returns a list and takes in a list respectively? (We have example of this here: https://github.com/PixarAnimationStudios/OpenUSD/blob/release/pxr/usd/usd/wrapAttribute.cpp#L123-L124

But now this results in inconsistency with the cpp API, which at present doesn't provide any member functions on the UsdValidationMetadata struct. Do you think it will be possible for you to add these methods also for consistency?

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense to me. I'll change it to Set/Get function instead. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tallytalwar I have changed it to use getter/setter to access keywords and schemaTypes, but not for cpp struct. One question is that should I keep keywords and schemaTypes as private or add public getter/setter for them only? That adds another inconsistency that it has two set of methods to access the two members if I keep them public. While it breaks back compatibility if I moved them into private.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What about using a vector_indexing_suite to preserve consistency with the CPP API?

Copy link
Collaborator

@nvmkuruc nvmkuruc Aug 19, 2024

Choose a reason for hiding this comment

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

Rather than use vector_indexing_suite or adding explicit get/set methods, I think I'd actually argue in favor of just making UsdVaidatorMetadata immutable in python. In general, the usage for UsdValidatorMetadata is to just reflect and inspect metadata described in C++ validator plugins, not editing in python.

There's already a keyword argument interface for easy construction for testing. keywords and schemaTypes could use TfPySequenceToTuple.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that makes sense to me if we don't need to register validator in python.

Copy link
Contributor

@tallytalwar tallytalwar Aug 19, 2024

Choose a reason for hiding this comment

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

UsdValidatorMetadata is to just reflect and inspect metadata described in C++ validator plugins, not editing in python.

Hmm, I think we should allow registering of validators from python also. So I can see we providing API for this https://github.com/PixarAnimationStudios/OpenUSD/blob/release/pxr/usd/usd/validationRegistry.h#L226 in python.

For this usecase, we will have to have immutable metadata constructs in python, no? @nvmkuruc

Copy link
Collaborator

@nvmkuruc nvmkuruc Aug 20, 2024

Choose a reason for hiding this comment

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

Even when registering validators in python, the keyword arg constructor @roggiezhang-nv provides for validator metadata is probably the most pythonic way to initialize and somewhat symmetrical to aggregate initialization of structs with designated initializers in C++.

Copy link
Contributor

@tallytalwar tallytalwar Aug 20, 2024

Choose a reason for hiding this comment

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

Yup I missed the constructor! Agreed with your statements @nvmkuruc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll make those properties immutable then.

.add_property("keywords", make_function(
&_GetMetadataKeywords, return_value_policy<TfPySequenceToList>()), _SetMetadataKeywords)
.def_readwrite("doc", &UsdValidatorMetadata::doc)
.add_property("schemaTypes", make_function(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same note about schemaTypes also.

@jesschimein
Copy link
Contributor

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@tallytalwar
Copy link
Contributor

Thanks @roggiezhang-nv , syncing this in now.

@jesschimein
Copy link
Contributor

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pixar-oss pixar-oss merged commit 94471f0 into PixarAnimationStudios:dev Aug 24, 2024
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants