chore: unify Python function validation between TrainerClient and SparkClient - #654
chore: unify Python function validation between TrainerClient and SparkClient#654mehulkumaryadav wants to merge 5 commits into
Conversation
Signed-off-by: newtop7 <mehulop1415@gmail.com>
|
🎉 Welcome to the Kubeflow SDK! 🎉 Thanks for opening your first PR! We're happy to have you as part of our community 🚀 Here's what happens next:
Join the community:
Feel free to ask questions in the comments if you need any help or clarification! |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
lntutor
left a comment
There was a problem hiding this comment.
The decorated-function test does not exercise the decorator branch. @sample_decorator replaces sample_decorated_function with the nested wrapper; because that wrapper has no @... syntax, inspect.getsource(sample_decorated_function) yields the wrapper source and ast.FunctionDef.decorator_list is empty. The helper therefore accepts it instead of raising the asserted ValueError. Please use a pass-through decorator (def decorator(func): return func) for this test so the inspected function retains the decorated source, or otherwise test the actual callable/source pair that the validator receives.
Signed-off-by: newtop7 <mehulop1415@gmail.com>
|
Thanks , I have addressed this feedback by updating the test to use a pass-through decorator so it exercises the actual decorator branch. The corrected version has been pushed. |
|
/ok-to-test |
tariq-hasan
left a comment
There was a problem hiding this comment.
Hi @mehulkumaryadav! I have added a few comments.
| ) | ||
|
|
||
|
|
||
| def validate_python_function(func: Callable) -> None: |
There was a problem hiding this comment.
I think we want to apply this check to localprocess and container backend as well.
| """Validate that a Python function can be serialized and executed. | ||
|
|
||
| This validation is shared by TrainerClient and SparkClient. | ||
| """ |
There was a problem hiding this comment.
Let's match the Args, Raises, Returns docstring pattern from validate_wait_for_job_status.
| if not inspect.isfunction(job.func): | ||
| raise ValueError("`job.func` must be a Python function.") | ||
| # Validate generic Python function properties. | ||
| validate_python_function(job.func) |
There was a problem hiding this comment.
Given the validation we can remove the duplicate logic in utils.py.
| @@ -17,6 +17,27 @@ | |||
| from kubeflow.trainer.test.common import SUCCESS, TestCase | |||
|
|
|||
|
|
|||
There was a problem hiding this comment.
it might be nice to keep using the same section-divider style (like # Test Helpers / # Tests above) across other test files too, just for consistency when browsing the suite. No strong opinion though.
https://github.com/mehulkumaryadav/sdk/blob/2895b0780e39ece6e1ba9cc94af42f5ed2a99dbb/kubeflow/spark/backends/kubernetes/utils_test.py#L90
Signed-off-by: newtop7 <mehulop1415@gmail.com>
|
@tariq-hasan @Goku2099 I have reviewed and addressed all the review comments. Please let me know if there's anything else you'd like me to update. Thanks! |
aebdb8e to
e399167
Compare
Signed-off-by: newtop7 <mehulop1415@gmail.com>
Signed-off-by: newtop7 <mehulop1415@gmail.com>
Summary
Closes #637
This PR extracts the common Python function validation logic shared by
TrainerClientandSparkClientinto a reusable utility to ensure consistent validation behavior across both clients.Changes
validate_python_function()tokubeflow.common.utilsSparkClientinto the common utilityTrainerClientto use the shared validation utilitySparkClientTesting
validate_python_function()