-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 bindings for UsdValidator
, UsdValidatorSuite
and UsdValidationRegistry
#3242
Add python bindings for UsdValidator
, UsdValidatorSuite
and UsdValidationRegistry
#3242
Conversation
@nvmkuruc for vis. |
df3bf80
to
3a639cb
Compare
UsdValidationRegistry
UsdValidator
, UsdValidatorSuite
and UsdValidationRegistry
Filed as internal issue #USD-10006 |
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
3a639cb
to
96c4413
Compare
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
I haven't started syncing this in yet, so will it be possible for you to follow the naming convention and 80 column line width, etc for commits specific for this PR (not the ones on which this is based)? |
Usd._register_test_validators() | ||
|
||
def test_query_validators_and_suites(self): | ||
validation_registry = Usd.ValidationRegistry() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable names also need to do follow camelCase convention. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @roggiezhang-nv.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @roggiezhang-nv
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if it satisfies the format. I'd hope there is a format guideline or style file so we can enforce the same format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately we do not have a format enforcing (clang format equivalent) thing right now. But most of the coding conventions are documented here: https://openusd.org/release/api/_page__coding__guidelines.html
A change soon will make it more front and center when filing a PR.
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a pass at this. And I am not able to understand why we will want to restrict python bindings for registering validators. In my initial proposal I also provided an example I think of a usecase for this.
I think since validation registration just require callbacks, python cb can be mapped to the appropriate cpp APIs for the wrapping?
Kindly let me know if there are reasons I am failing to understand here. Thanks
} | ||
|
||
// Test only for registering validators as no APIs are exposed to register | ||
// validators from python. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be the case. We should definitely expose validator registration from python. I will like to hear thoughts on why this restrictions is being placed? Thanks
return_value_policy<TfPySequenceToList>(), (args("schemaTypes"))); | ||
|
||
// For python testing only | ||
def("_register_test_validators", &_RegisterTestValidators); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we shouldn't be doing this here. Once we have APIs wrapped for registering of various validators, we should have the test code register the validators for its purpose, instead of making this wrapper code handle any test specific wrapping.
We thought the GIL warrants additional consideration when scheduling and running validators. We're not necessarily opposed to registering validators in python, but didn't want to do it on the initial pass. |
I see in that case, maybe lets remove the test code from the wrapper. I am just starting work on ValidationContext / Running of validators, so can also take a stab at this when this work is all done. |
We could consider keeping |
I think Matt replied all those questions. Let me know if I have anything else to fix. |
So having a chat with Alex and he mentioned about the use of TfPyFunctionFromPython, which takes care of acquiring/locking and releasing of GIL when appropriate python method is called and I think something along these lines should work:
Let me know if this makes sense? |
It makes sense for sure. I think Matt concerns are more about how those validators are scheduled and running in a parallel execution environment. I'll let Matt to comment more. |
5986aad
to
bbee580
Compare
@tallytalwar I rebased this branch to shrink the change history. |
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
@tallytalwar @nvmkuruc I moved test cpp code into test plugin. |
|
||
TF_REGISTRY_FUNCTION(UsdValidationRegistry) | ||
{ | ||
fprintf(stderr, "test!!!!!\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this still be there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. Removed.
80354ed
to
8f0e7fc
Compare
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
def setUpClass(cls) -> None: | ||
Plug.Registry().RegisterPlugins( | ||
os.path.dirname(__file__) | ||
+ "/UsdPlugins/lib/TestUsdValidationRegistryPy/Resources/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using pathlib
or os.path.join
to be safe.
const UsdStagePtr &stage) const = &UsdValidator::Validate; | ||
UsdValidationErrorVector (UsdValidator::*_ValidatePrim)(const UsdPrim &prim) | ||
const = &UsdValidator::Validate; | ||
class_<UsdValidator, boost::noncopyable>("Validator", no_init) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be helpful to have a __repr__
implementation.
You could consider returning UsdValidatorRegistry.GetOrLoadValidatorByName(<name>)
if you're sure that the validator is in the registry. @tallytalwar for additional thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense to me, but to confirm, @nvmkuruc your suggestion will help a developer do:
validator = UsdValidatorRegistry.GetOrLoadValidatorByName("plug:validatorName")
print(validator)
UsdValidator(name='plug:validatorName')
Instead of printing the python object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__repr__
added. Do we need to add method to stringify validator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tallytalwar Yup! It's analogous to Sdf.Layer.FindOrOpen
.
I don't think stringify has much of a use case.
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
105f6db
to
18bc714
Compare
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
Thanks! |
Thanks @roggiezhang-nv for addressing notes and cleaning the PR. We just pushed an update to dev branch, which might require rebase/updates to this PR. Can you please update it? Thanks |
18bc714
to
a83d3ab
Compare
Rebased. |
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
Description of Change(s)
Add python bindings for
UsdValidator
,UsdValidatorSuite
andUsdValidationRegistry
.It is stacked on #3223, #3232, and #3236 for adding Python bindings for validator framework.
Fixes Issue(s)