Skip to content

Conversation

@jafranc
Copy link
Contributor

@jafranc jafranc commented Oct 10, 2025

Among factorization effort, declaring more fit-for-use decorator that can minimize code duplication and boilerplate code. Here is a PR used in the case of Single Input Single Output PV Plugins that wrap a VTK plugin.

  • PoC on PVFillPartialArray
  • extend PoC

@jafranc jafranc self-assigned this Oct 10, 2025
@jafranc jafranc changed the title Jafranc/refact/testSISO feat: adding SISO decorator Oct 10, 2025
@jafranc jafranc changed the base branch from jafranc/refact/decorators to main October 15, 2025 09:14
@jafranc jafranc marked this pull request as ready for review October 15, 2025 11:56
Copy link
Contributor

@RomainBaville RomainBaville left a comment

Choose a reason for hiding this comment

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

Thanks for your work. It seems good to me but check PVMeshQualityEnhanced and the output of Filter.

# SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies.
# SPDX-FileContributor: Martin Lemay, Romain Baville
# ruff: noqa: E402 # disable Module level import not at top of file
import sys
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import sys
import sys
import numpy as np

from paraview.detail.loghandler import ( # type: ignore[import-not-found]
VTKHandler,
) # source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/detail/loghandler.py

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import vtkmodules.util.numpy_support as vnp

Returns:
int: 1 if calculation successfully ended, 0 otherwise.
inputMesh : a mesh to transform
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
inputMesh : a mesh to transform
inputMesh : A mesh to transform.

Returns:
int: 1 if calculation successfully ended, 0 otherwise.
inputMesh : a mesh to transform
outputMesh : a mesh transformed
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
outputMesh : a mesh transformed
outputMesh : A mesh transformed.

Returns:
vtkPointSet: output mesh
inputMesh(vtkPointSet): input mesh
outputMesh: output mesh
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
outputMesh: output mesh
outputMesh: Output mesh.

"""Pre-init the filter with the Base algo and I/O single type (usually vtkMultiBlockDataSet).
Args:
ar : fowarded arguments
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ar : fowarded arguments
ar : Fowarded arguments.

Args:
ar : fowarded arguments
kw : forwarded keywords args
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
kw : forwarded keywords args
kw : Forwarded keywords args.

"""Define filter here.
Args:
inputMesh : a mesh to transform
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
inputMesh : a mesh to transform
inputMesh : A mesh to transform.

Args:
inputMesh : a mesh to transform
outputMesh : a mesh transformed
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
outputMesh : a mesh transformed
outputMesh : A mesh transformed.

@alexbenedicto alexbenedicto self-requested a review October 20, 2025 22:21
update_paths()

__doc__ = """
Set of decorators that allows quicker generation of MultiBlockDataSet to MultiBlockDataSet filters
Copy link
Collaborator

Choose a reason for hiding this comment

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

This documentation does not take into account that we allow for multiple types of inputs U, we are not limited to MultiBlockDataSet.

Comment on lines 26 to 27
# from functools import wraps
# from dataclasses import dataclass
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove unused imports

Comment on lines 15 to 23
# Enum for filter categories
class FilterCategory( str, Enum ):
GEOS_UTILS = '4- Geos Utils'
GEOS_MESH = '1- Geos Mesh'
GEOS_PROP = '0- Geos Pre-processing'
GEOS_GEOMECHANICS = '2- Geos Geomechanics'
GEOS_PV = '3- Geos PV'
GEOS_QC = '5- Geos QC'
# Add more as needed
Copy link
Collaborator

Choose a reason for hiding this comment

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

2 things:

  • The class should be defined after the doc
  • Reorder from 0 to 5

Comment on lines 83 to 84
def SISOFilter( category: FilterCategory, decorated_label: str,
decorated_type: Union[str,list] ) -> Callable[ [ Type[ T ] ], Type[ T ] ]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def SISOFilter( category: FilterCategory, decorated_label: str,
decorated_type: Union[str,list] ) -> Callable[ [ Type[ T ] ], Type[ T ] ]:
def SISOFilter( category: FilterCategory, decoratedLabel: str,
decoratedType: Union[str,list] ) -> Callable[ [ Type[ T ] ], Type[ T ] ]:

And change that everywhere else

decorated_type: Union[str,list] ) -> Callable[ [ Type[ T ] ], Type[ T ] ]:
"""Decorate single input single output filter."""

def decorated_class( cls: Type[ T ] ) -> Type[ T ]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def decorated_class( cls: Type[ T ] ) -> Type[ T ]:
def decoratedClass( cls: Type[ T ] ) -> Type[ T ]:


def SISOFilter( category: FilterCategory, decorated_label: str,
decorated_type: Union[str,list] ) -> Callable[ [ Type[ T ] ], Type[ T ] ]:
"""Decorate single input single output filter."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""Decorate single input single output filter."""
"""Decorate Single Input Single Output (SISO) filter."""


def decorated_class( cls: Type[ T ] ) -> Type[ T ]:
"""Outer wrapper function. All is in the WrappingClass below."""
original_init = cls.__init__
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
original_init = cls.__init__
originalInit = cls.__init__

return 1

# Copy all methods and attributes from cls, including decorator metadata
for attr_name in dir(cls):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
for attr_name in dir(cls):
for attrName in dir(cls):

@@ -0,0 +1,191 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies.
# SPDX-FileContributor: Martin Lemay, Romain Baville
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# SPDX-FileContributor: Martin Lemay, Romain Baville
# SPDX-FileContributor: Martin Lemay, Romain Baville, Jacques Franc

@jafranc jafranc requested a review from alexbenedicto October 22, 2025 12:06
…t. Can still crash in some cases and will need separate PR to deal with it.
@jafranc jafranc requested a review from RomainBaville October 24, 2025 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants