Skip to content

Commit e0ab6fc

Browse files
committed
ruff + yapf
1 parent 396ed11 commit e0ab6fc

File tree

7 files changed

+48
-56
lines changed

7 files changed

+48
-56
lines changed

geos-mesh/src/geos/mesh/processing/MergeBlockEnhanced.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from typing_extensions import Self
88

99
from geos.utils.Logger import Logger, getLogger
10-
from geos.utils.Errors import VTKError
1110
from geos.mesh.utils.multiblockModifiers import mergeBlocks
1211

1312
from vtkmodules.vtkCommonDataModel import (
@@ -122,7 +121,6 @@ def applyFilter( self: Self ) -> None:
122121
self.outputMesh = outputMesh
123122
self.logger.info( f"The filter {self.logger.name} succeeded." )
124123

125-
126124
def getOutput( self: Self ) -> vtkUnstructuredGrid:
127125
"""Get the merged mesh.
128126

geos-mesh/src/geos/mesh/utils/multiblockModifiers.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
from vtkmodules.vtkFiltersCore import vtkAppendDataSets
1919

2020
from geos.mesh.utils.arrayModifiers import fillAllPartialAttributes
21-
from geos.utils.Errors import VTKError
22-
from geos.utils.Logger import ( getLogger, Logger, VTKCaptureLog, RegexExceptionFilter)
21+
from geos.utils.Logger import ( getLogger, Logger, VTKCaptureLog, RegexExceptionFilter )
2322

2423
__doc__ = """Contains a method to merge blocks of a VTK multiblock dataset."""
2524

25+
2626
def mergeBlocks(
2727
inputMesh: Union[ vtkMultiBlockDataSet, vtkCompositeDataSet ],
2828
keepPartialAttributes: bool = False,
@@ -54,9 +54,9 @@ def mergeBlocks(
5454
if logger is None:
5555
logger: Logger = getLogger( "mergeBlocks", True )
5656

57-
vtkLogger.SetStderrVerbosity(vtkLogger.VERBOSITY_TRACE)
58-
logger.addFilter(RegexExceptionFilter()) # will raise VTKError if captured VTK Error
59-
logger.setLevel(logging.DEBUG)
57+
vtkLogger.SetStderrVerbosity( vtkLogger.VERBOSITY_TRACE )
58+
logger.addFilter( RegexExceptionFilter() ) # will raise VTKError if captured VTK Error
59+
logger.setLevel( logging.DEBUG )
6060

6161
# Fill the partial attributes with default values to keep them during the merge.
6262
if keepPartialAttributes and not fillAllPartialAttributes( inputMesh, logger ):
@@ -86,12 +86,11 @@ def mergeBlocks(
8686
block: vtkDataSet = vtkDataSet.SafeDownCast( iterator.GetCurrentDataObject() )
8787
af.AddInputData( block )
8888
iterator.GoToNextItem()
89-
9089
af.Update()
91-
captured_log.seek(0) #be kind let's just rewind
90+
captured_log.seek( 0 ) #be kind let's just rewind
9291
captured = captured_log.read().decode()
9392

94-
logger.debug(captured.strip())
93+
logger.debug( captured.strip() )
9594
outputMesh: vtkUnstructuredGrid = af.GetOutputDataObject( 0 )
9695

9796
return outputMesh

geos-posp/src/PVplugins/PVMohrCirclePlot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
GeosMeshOutputsEnum,
3939
)
4040
from geos.utils.Logger import Logger, getLogger
41-
from geos.utils.Errors import VTKError
4241
from geos.utils.PhysicalConstants import (
4342
DEFAULT_FRICTION_ANGLE_DEG,
4443
DEFAULT_FRICTION_ANGLE_RAD,
@@ -779,8 +778,9 @@ def RequestData(
779778
)
780779
Render()
781780

782-
except (ValueError,TypeError) as e:
783-
self.m_logger.error(f"MergeBlock failed due to {e}", exc_info=True) #no critical as there is no reason to crash here
781+
except ( ValueError, TypeError ) as e:
782+
self.m_logger.error( f"MergeBlock failed due to {e}",
783+
exc_info=True ) #no critical as there is no reason to crash here
784784
return 0
785785

786786
except Exception as e:

geos-posp/src/geos_posp/filters/GeosBlockMerge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
getRockSuffixRenaming,
1212
)
1313
from geos.utils.Logger import Logger, getLogger
14-
from geos.utils.Errors import VTKError
1514
from typing_extensions import Self
1615
from vtkmodules.util.vtkAlgorithm import VTKPythonAlgorithmBase
1716
from vtkmodules.vtkCommonCore import (
@@ -71,6 +70,7 @@
7170
output :vtkMultiBlockDataSet = mergeBlockFilter.GetOutputDataObject(0)
7271
"""
7372

73+
7474
class GeosBlockMerge( VTKPythonAlgorithmBase ):
7575

7676
def __init__( self: Self ) -> None:
@@ -154,12 +154,12 @@ def RequestData(
154154
# self.m_logger.error( mess )
155155
# self.m_logger.error( e, exc_info=True )
156156
# return 0
157-
except (ValueError,TypeError) as e:
157+
except ( ValueError, TypeError ) as e:
158158
mess0: str = "Geos block merge failed due to:"
159159
self.m_logger.critical( mess0 )
160160
self.m_logger.critical( e, exc_info=True )
161161
return 0
162-
except RuntimeError:
162+
except RuntimeError as e:
163163
self.m_logger.critical( "Geos block merge failed due to" )
164164
self.m_logger.critical( e, exc_info=True )
165165
return 0

geos-pv/src/geos/pv/plugins/PVMergeBlocksEnhanced.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ def RequestData(
124124

125125
try:
126126
filter.applyFilter()
127-
except (ValueError,TypeError) as e:
128-
filter.logger.error(f"MergeBlock failed due to {e}", exc_info=True) #no critical as there is no reason to crash here
127+
except ( ValueError, TypeError ) as e:
128+
filter.logger.error( f"MergeBlock failed due to {e}",
129+
exc_info=True ) #no critical as there is no reason to crash here
129130
return 0
130131
except RuntimeError as e:
131-
filter.logger.error(f"MergeBlock failed due to {e}", exc_info=True) #no critical as there is no reason to crash here
132+
filter.logger.error( f"MergeBlock failed due to {e}",
133+
exc_info=True ) #no critical as there is no reason to crash here
132134
return 0
133135
else:
134136
outputMesh.ShallowCopy( filter.getOutput() )
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
2-
class VTKError(Exception):
3-
""" Captured and adapted VTKError from log (see Logger.py)"""
4-
pass
1+
class VTKError( Exception ):
2+
"""Captured and adapted VTKError from log (see Logger.py)."""
3+
pass

geos-utils/src/geos/utils/Logger.py

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import Any, Union, Generator
66
from typing_extensions import Self
77

8-
import sys
98
import os
109
import re
1110
import tempfile
@@ -36,68 +35,63 @@
3635
vtkcalls..
3736
captured_log.seek(0) # be kind let's just rewind
3837
captured = captured_log.read().decode()
39-
38+
4039
logger.error(captured.strip())
4140
4241
"""
4342

44-
class RegexExceptionFilter(logging.Filter):
45-
"""
46-
Class to regexp VTK messages rethrown into logger by VTKCaptureLog.
47-
"""
4843

49-
pattern : str = r"vtkExecutive.cxx" #pattern captured that will raise a vtkError
44+
class RegexExceptionFilter( logging.Filter ):
45+
"""Class to regexp VTK messages rethrown into logger by VTKCaptureLog."""
5046

51-
def __init__(self):
47+
pattern: str = r"vtkExecutive.cxx" #pattern captured that will raise a vtkError
48+
49+
def __init__( self ) -> None:
50+
"""Init filter with class based pattern as this is patch to logging logic."""
5251
super().__init__()
53-
self.regex = re.compile(self.pattern)
52+
self.regex = re.compile( self.pattern )
5453

55-
def filter(self, record : logging.LogRecord):
56-
"""
57-
Filter VTK Error from stdErr.
58-
59-
Args:
60-
record(loggging.LogRecord)
54+
def filter( self, record: logging.LogRecord ) -> None:
55+
"""Filter VTK Error from stdErr.
6156
62-
Raises:
63-
VTKError(geos.utils.Error) if a pattern symbol is caught in the stderr.
57+
Args:
58+
record(loggging.LogRecord) : record that logger will provide as evaluated
59+
60+
Raises:
61+
VTKError(geos.utils.Error) if a pattern symbol is caught in the stderr.
6462
"""
6563
message = record.getMessage()
66-
if self.regex.search(message):
67-
raise VTKError(f"Log message matched forbidden pattern: {message}")
64+
if self.regex.search( message ):
65+
raise VTKError( f"Log message matched forbidden pattern: {message}" )
6866
return True # Allow other messages to pass
6967

7068

7169
@contextmanager
72-
def VTKCaptureLog()->Generator[Any,Any,Any]:
73-
"""
74-
Hard way of adapting C-like vtkLogger to logging class by throwing in
75-
stderr and reading back from it.
70+
def VTKCaptureLog() -> Generator[ Any, Any, Any ]:
71+
"""Hard way of adapting C-like vtkLogger to logging class by throwing in stderr and reading back from it.
7672
77-
Return:
78-
Generator buffering os.stderr
73+
Returns:
74+
Generator: buffering os stderr.
7975
8076
"""
81-
#equiv to pyvista's
77+
#equiv to pyvista's
8278
# from pyvista.utilities import VtkErrorCatcher
8379
# with VtkErrorCatcher() as err:
8480
# append_filter.Update()
8581
# print(err)
86-
87-
# Save original stderr file descriptor
8882
# original_stderr_fd = sys.stderr.fileno()
8983
original_stderr_fd = 2
90-
saved_stderr_fd = os.dup(original_stderr_fd)
84+
saved_stderr_fd = os.dup( original_stderr_fd )
9185

9286
# Create a temporary file to capture stderr
93-
with tempfile.TemporaryFile(mode='w+b') as tmp:
94-
os.dup2(tmp.fileno(), original_stderr_fd)
87+
with tempfile.TemporaryFile( mode='w+b' ) as tmp:
88+
os.dup2( tmp.fileno(), original_stderr_fd )
9589
try:
9690
yield tmp
9791
finally:
9892
# Restore original stderr
99-
os.dup2(saved_stderr_fd, original_stderr_fd)
100-
os.close(saved_stderr_fd)
93+
os.dup2( saved_stderr_fd, original_stderr_fd )
94+
os.close( saved_stderr_fd )
10195

10296

10397
class CountWarningHandler( logging.Handler ):

0 commit comments

Comments
 (0)