Skip to content

Commit

Permalink
Issue #178 fixed linting, mainly using f strings
Browse files Browse the repository at this point in the history
  • Loading branch information
thompson318 committed Dec 8, 2021
1 parent 1e4c5bc commit d38d7eb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
7 changes: 3 additions & 4 deletions sksurgeryvtk/models/surface_model_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,13 @@ def __init__(self, data, directory_prefix=None):
surface_name, assembly)

# Check surface exists and add to assembly
if surface_name in self.named_surfaces.keys():
if surface_name in self.named_surfaces:
surface = self.named_surfaces[surface_name]
new_assembly.AddPart(surface.actor)

else:
raise KeyError("Trying to add {} to vtkAssembly, \
but it is not a valid surface.".\
format(surface_name))
raise KeyError(f"Trying to add {surface_name} to \
vtkAssembly, but it is not a valid surface.")

self.named_assemblies[assembly] = new_assembly

Expand Down
8 changes: 4 additions & 4 deletions sksurgeryvtk/models/voxelise.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ def voxelise(input_mesh: Union[np.ndarray, vtk.vtkDataObject, str],
reader.Update()
grid = reader.GetOutput()
if grid.GetPointData().GetArray(array_name):
err = "The output file {} already has a field named {}!".format(
output_grid, array_name)
err = f"The output file {output_grid} already has a \
field named {array_name}!"
raise IOError(err)
b = grid.GetBounds()
size = b[1] - b[0]
Expand Down Expand Up @@ -418,7 +418,7 @@ def write_grid_to_file(grid: vtk.vtkStructuredGrid,
:param output_grid: File path
:type output_grid: str
"""
LOGGER.debug("Writing to {}".format(output_grid))
LOGGER.debug("Writing to %s", output_grid)
writer = vtk.vtkXMLStructuredGridWriter()
writer.SetFileName(output_grid)
writer.SetInputData(grid)
Expand Down Expand Up @@ -500,7 +500,7 @@ def save_displacement_array_in_grid(array: np.ndarray,
df.SetName( array_name )
if grid.GetPointData().HasArray(array_name):
grid.GetPointData().RemoveArray(array_name)
LOGGER.debug("Warning: Overwriting array {}".format(array_name))
LOGGER.debug("Warning: Overwriting array %s", array_name)
grid.GetPointData().AddArray(df)

if grid_is_file:
Expand Down
6 changes: 2 additions & 4 deletions sksurgeryvtk/models/vtk_surface_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def __init__(self, filename, colour, visibility=True, opacity=1.0,
self.reader = vtk.vtkXMLPolyDataReader()
else:
raise ValueError(
'File type not supported for model loading: {}'.format(
filename))
f'File type not supported for model loading: {filename}')

self.reader.SetFileName(filename)
self.reader.Update()
Expand Down Expand Up @@ -221,8 +220,7 @@ def set_texture(self, filename):

else:
raise ValueError(
'File type not supported for texture loading: {}'.format(
filename))
f'File type not supported for texture loading: {filename}')

else:
# Unset texture when the function is called with None.
Expand Down
15 changes: 6 additions & 9 deletions sksurgeryvtk/models/vtk_surface_model_directory_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,11 @@ def __init__(self, directory_name, defaults_file=None):
if not directory_name:
raise ValueError('Directory name is empty')
if not os.path.exists(directory_name):
raise ValueError('Directory does not exist: {}'
.format(directory_name))
raise ValueError(f'Directory does not exist: {directory_name}')
if not os.access(directory_name, os.X_OK):
raise ValueError('Directory is not executable: {}'
.format(directory_name))
raise ValueError(f'Directory is not executable: {directory_name}')
if not os.access(directory_name, os.R_OK):
raise ValueError('Directory is not readable: {}'
.format(directory_name))
raise ValueError(f'Directory is not readable: {directory_name}')

self.configuration_data = None

Expand Down Expand Up @@ -183,7 +180,7 @@ def get_model_colours(self, directory):
colour_file = directory + '/colours.txt'

if os.path.exists(colour_file):
with open(colour_file, 'r') as csv_file:
with open(colour_file, 'r', encoding='utf-8') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
counter = 0
for row in csv_reader:
Expand All @@ -196,8 +193,8 @@ def get_model_colours(self, directory):
filename = str(row[0])
full_path = os.path.join(directory, filename)
if not os.path.exists(full_path):
raise FileNotFoundError("File %s doesn't exist" \
% full_path)
raise FileNotFoundError(
f"File {full_path} doesn't exist")

self.colours[filename] = (float(row[1]),
float(row[2]),
Expand Down
2 changes: 1 addition & 1 deletion sksurgeryvtk/text/text_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def validate_input(self, text_list):

for idx, item in enumerate(text_list):
if not isinstance(item, str):
raise ValueError('Item at position {} not a string'.format(idx))
raise ValueError(f'Item at position {idx} not a string')


class VTKTextBase:
Expand Down

0 comments on commit d38d7eb

Please sign in to comment.