Skip to content

Commit

Permalink
Merge pull request #38613 from peterfpeterson/pre-commit-ruff-ornlnext
Browse files Browse the repository at this point in the history
pre-commit ruff update - ornl-next
  • Loading branch information
peterfpeterson authored Jan 16, 2025
2 parents 4f567e7 + 62ee6dc commit 5fc96e8
Show file tree
Hide file tree
Showing 395 changed files with 1,049 additions and 1,181 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ repos:
)$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.9.1
# ruff must appear before black in the list of hooks
hooks:
- id: ruff
Expand Down
2 changes: 1 addition & 1 deletion Framework/PythonInterface/mantid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _bin_dirs():

if _bindir is None:
raise ImportError(
"Broken installation! Unable to find Mantid.properties file.\n" "Directories searched: {}".format(", ".join(_bin_dirs()))
"Broken installation! Unable to find Mantid.properties file.\nDirectories searched: {}".format(", ".join(_bin_dirs()))
)

# Windows doesn't have rpath settings so make sure the C-extensions can find the rest of the
Expand Down
2 changes: 1 addition & 1 deletion Framework/PythonInterface/mantid/plots/datafunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ def update_colorbar_scale(figure, image, scale, vmin, vmax):
if locator.tick_values(vmin=vmin, vmax=vmax).size == 0:
locator = LogLocator()
mantid.kernel.logger.warning(
"Minor ticks on colorbar scale cannot be shown " "as the range between min value and max value is too large"
"Minor ticks on colorbar scale cannot be shown as the range between min value and max value is too large"
)
colorbar.set_ticks(locator)

Expand Down
6 changes: 3 additions & 3 deletions Framework/PythonInterface/mantid/plots/mantidaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def check_axes_distribution_consistency(self):
def artists_workspace_has_errors(self, artist):
"""Check if the given artist's workspace has errors"""
if artist not in self.get_tracked_artists():
raise ValueError("Artist '{}' is not tracked and so does not have " "an associated workspace.".format(artist))
raise ValueError("Artist '{}' is not tracked and so does not have an associated workspace.".format(artist))
workspace, spec_num = self.get_artists_workspace_and_spec_num(artist)
if artist.axes.creation_args[0].get("axis", None) == MantidAxType.BIN:
if any([workspace.readE(i)[spec_num] != 0 for i in range(0, workspace.getNumberHistograms())]):
Expand Down Expand Up @@ -1199,7 +1199,7 @@ def set_waterfall(self, state, x_offset=None, y_offset=None, fill=False):
# that they can use the update_waterfall function to do this.
if x_offset != self.waterfall_x_offset or y_offset != self.waterfall_y_offset:
logger.information(
"If your plot is already a waterfall plot you can use update_waterfall(x, y) to" " change its offset values."
"If your plot is already a waterfall plot you can use update_waterfall(x, y) to change its offset values."
)
else:
# Nothing needs to be changed.
Expand All @@ -1211,7 +1211,7 @@ def set_waterfall(self, state, x_offset=None, y_offset=None, fill=False):
datafunctions.set_initial_dimensions(self)
else:
if bool(x_offset) or bool(y_offset) or fill:
raise RuntimeError("You have set waterfall to false but have given a non-zero value for the offset or " "set fill to true.")
raise RuntimeError("You have set waterfall to false but have given a non-zero value for the offset or set fill to true.")

if not self.is_waterfall():
# Nothing needs to be changed.
Expand Down
8 changes: 4 additions & 4 deletions Framework/PythonInterface/mantid/plots/plotfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def raise_if_not_sequence(value, seq_name, element_type=None):
"""
accepted_types = (list, tuple, range)
if type(value) not in accepted_types:
raise ValueError("{} should be a list or tuple, " "instead found '{}'".format(seq_name, value.__class__.__name__))
raise ValueError("{} should be a list or tuple, instead found '{}'".format(seq_name, value.__class__.__name__))
if element_type is not None:

def raise_if_not_type(x):
Expand Down Expand Up @@ -443,10 +443,10 @@ def _unpack_grouped_workspaces(mixed_list: List):
def _validate_plot_inputs(workspaces, spectrum_nums, wksp_indices, tiled=False, overplot=False):
"""Raises a ValueError if any arguments have the incorrect types"""
if spectrum_nums is not None and wksp_indices is not None:
raise ValueError("Both spectrum_nums and wksp_indices supplied. " "Please supply only 1.")
raise ValueError("Both spectrum_nums and wksp_indices supplied. Please supply only 1.")

if tiled and overplot:
raise ValueError("Both tiled and overplot flags set to true. " "Please set only one to true.")
raise ValueError("Both tiled and overplot flags set to true. Please set only one to true.")

raise_if_not_sequence(workspaces, "workspaces", MatrixWorkspace)

Expand Down Expand Up @@ -514,7 +514,7 @@ def _do_single_plot_mdhisto_workspace(ax, workspaces, errors=False):
num_dim += 1
if num_dim != 1:
raise RuntimeError(
f"Workspace {str(ws)} is an IMDHistoWorkspace with number of non-integral dimension " f"equal to {num_dim} but not 1."
f"Workspace {str(ws)} is an IMDHistoWorkspace with number of non-integral dimension equal to {num_dim} but not 1."
)

# Plot
Expand Down
2 changes: 1 addition & 1 deletion Framework/PythonInterface/mantid/plots/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def zoom_axis(ax, coord, x_or_y, factor):
:param float factor: The factor by which to zoom in, a factor less than 1 zooms out
"""
if x_or_y.lower() not in ["x", "y"]:
raise ValueError("Can only zoom on axis 'x' or 'y'. Found '{}'." "".format(x_or_y))
raise ValueError("Can only zoom on axis 'x' or 'y'. Found '{}'.".format(x_or_y))
get_lims = getattr(ax, "get_{}lim".format(x_or_y.lower()))
set_lims = getattr(ax, "set_{}lim".format(x_or_y.lower()))

Expand Down
9 changes: 4 additions & 5 deletions Framework/PythonInterface/mantid/simpleapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ def Load(*args, **kwargs):
# then raise a more helpful error than what we would get from an algorithm
if lhs[0] == 0 and "OutputWorkspace" not in kwargs:
raise RuntimeError(
"Unable to set output workspace name. Please either assign the output of "
"Load to a variable or use the OutputWorkspace keyword."
"Unable to set output workspace name. Please either assign the output of Load to a variable or use the OutputWorkspace keyword."
)

lhs_args = _get_args_from_lhs(lhs, algm)
Expand Down Expand Up @@ -246,7 +245,7 @@ def handleSpecialProperty(name, value=None):
# Check for any properties that aren't known and warn they will not be used
for key in list(final_keywords.keys()):
if key not in algm:
logger.warning("You've passed a property (%s) to StartLiveData() " "that doesn't apply to this Instrument." % key)
logger.warning("You've passed a property (%s) to StartLiveData() that doesn't apply to this Instrument." % key)
del final_keywords[key]

set_properties(algm, **final_keywords)
Expand Down Expand Up @@ -450,7 +449,7 @@ def CutMD(*args, **kwargs): # noqa: C901
# Ensure the output names we were given are valid
if handling_multiple_workspaces:
if not isinstance(out_names, list):
raise RuntimeError("Multiple OutputWorkspaces must be given as a list when" " processing multiple InputWorkspaces.")
raise RuntimeError("Multiple OutputWorkspaces must be given as a list when processing multiple InputWorkspaces.")
else:
# We wrap in a list for our convenience. The user must not pass us one though.
if not isinstance(out_names, list):
Expand Down Expand Up @@ -1340,7 +1339,7 @@ def _update_sys_path(dirs):
logger.information("Path to plugins manifest is empty. The python plugins will not be loaded.")
elif not os.path.exists(plugins_manifest_path):
logger.warning(
"The path to the python plugins manifest is invalid. The built in python plugins will " "not be loaded into the simpleapi."
"The path to the python plugins manifest is invalid. The built in python plugins will not be loaded into the simpleapi."
)
else:
with open(plugins_manifest_path) as manifest:
Expand Down
2 changes: 1 addition & 1 deletion Framework/PythonInterface/mantid/utils/dgs/_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _qangle_validate_inputs(

if goniometer_constraints:
if goniometer_range[1] < goniometer_range[0] or goniometer_range[0] < -180.0 or goniometer_range[1] > 180.0:
raise ValueError("goniometer_range must be an increasing array, " "with both limits between -180 and 180 degrees")
raise ValueError("goniometer_range must be an increasing array, with both limits between -180 and 180 degrees")

return (Ei, DeltaE, sign, UB)

Expand Down
2 changes: 1 addition & 1 deletion Framework/PythonInterface/plugins/algorithms/Abins2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def _get_properties(self):

self._instrument_kwargs.update({"chopper_frequency": chopper_frequency})
elif self.getProperty("ChopperFrequency").value:
logger.warning("The selected instrument does not use a chopper: " "chopper frequency will be ignored.")
logger.warning("The selected instrument does not use a chopper: chopper frequency will be ignored.")

self.set_instrument()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def PyInit(self):
name="EulerConvention",
defaultValue="YZX",
validator=StringListValidator(eulerConventions),
doc="Euler angles convention used when calculating and displaying angles," "eg XYZ corresponding to alpha beta gamma.",
doc="Euler angles convention used when calculating and displaying angles, eg XYZ corresponding to alpha beta gamma.",
)

# alpha rotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def pyexec_setup(new_options):


class BASISCrystalDiffraction(DataProcessorAlgorithm):
_mask_file = "/SNS/BSS/shared/autoreduce/new_masks_08_12_2015/" "BASIS_Mask_default_diff.xml"
_mask_file = "/SNS/BSS/shared/autoreduce/new_masks_08_12_2015/BASIS_Mask_default_diff.xml"
_solid_angle_ws_ = "/SNS/BSS/shared/autoreduce/solid_angle_diff.nxs"
_flux_ws_ = "/SNS/BSS/shared/autoreduce/int_flux.nxs"
_wavelength_bands = {"311": [3.07, 3.60], "111": [6.05, 6.60]}
Expand Down Expand Up @@ -135,7 +135,7 @@ def version():

@staticmethod
def summary():
return "Multiple-file BASIS crystal reduction for diffraction " "detectors."
return "Multiple-file BASIS crystal reduction for diffraction detectors."

@staticmethod
def seeAlso():
Expand Down Expand Up @@ -219,7 +219,7 @@ def PyInit(self):
#
crystal_diffraction_title = "Single Crystal Diffraction"
self.declareProperty(
"PsiAngleLog", "SE50Rot", direction=Direction.Input, doc="log entry storing rotation of the sample" "around the vertical axis"
"PsiAngleLog", "SE50Rot", direction=Direction.Input, doc="log entry storing rotation of the sample around the vertical axis"
)
self.declareProperty("PsiOffset", 0.0, direction=Direction.Input, doc="Add this quantity to PsiAngleLog")
self.declareProperty(
Expand All @@ -233,23 +233,23 @@ def PyInit(self):
# Reciprocal vector to be aligned with incoming beam
self.declareProperty(
FloatArrayProperty("VectorU", [1, 0, 0], array_length_three, direction=Direction.Input),
doc="three item, comma-separated, HKL indexes" "of the diffracting plane",
doc="three item, comma-separated, HKL indices of the diffracting plane",
)
# Reciprocal vector orthogonal to VectorU and in-plane with
# incoming beam
self.declareProperty(
FloatArrayProperty("VectorV", [0, 1, 0], array_length_three, direction=Direction.Input),
doc="three item, comma-separated, HKL indexes" "of the direction perpendicular to VectorV" "and the vertical axis",
doc="three item, comma-separated, HKL indices of the direction perpendicular to VectorVand the vertical axis",
)
# Abscissa view
self.declareProperty(
FloatArrayProperty("Uproj", [1, 0, 0], array_length_three, direction=Direction.Input),
doc="three item comma-separated Abscissa view" "of the diffraction pattern",
doc="three item comma-separated Abscissa view of the diffraction pattern",
)
# Ordinate view
self.declareProperty(
FloatArrayProperty("Vproj", [0, 1, 0], array_length_three, direction=Direction.Input),
doc="three item comma-separated Ordinate view" "of the diffraction pattern",
doc="three item comma-separated Ordinate view of the diffraction pattern",
)
# Hidden axis
self.declareProperty(FloatArrayProperty("Wproj", [0, 0, 1], array_length_three, direction=Direction.Input), doc="Hidden axis view")
Expand Down
12 changes: 6 additions & 6 deletions Framework/PythonInterface/plugins/algorithms/BASISDiffraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def pyexec_setup(new_options):


class BASISDiffraction(DataProcessorAlgorithm):
_mask_file = "/SNS/BSS/shared/autoreduce/new_masks_08_12_2015/" "BASIS_Mask_default_diff.xml"
_mask_file = "/SNS/BSS/shared/autoreduce/new_masks_08_12_2015/BASIS_Mask_default_diff.xml"
_solid_angle_ws_ = "/SNS/BSS/shared/autoreduce/solid_angle_diff.nxs"
_flux_ws_ = "/SNS/BSS/shared/autoreduce/int_flux.nxs"

Expand Down Expand Up @@ -173,7 +173,7 @@ def PyInit(self):
self.declareProperty("SingleCrystalDiffraction", False, direction=Direction.Input, doc="Calculate diffraction pattern?")
crystal_diffraction_enabled = EnabledWhenProperty("SingleCrystalDiffraction", PropertyCriterion.IsNotDefault)
self.declareProperty(
"PsiAngleLog", "SE50Rot", direction=Direction.Input, doc="log entry storing rotation of the sample" "around the vertical axis"
"PsiAngleLog", "SE50Rot", direction=Direction.Input, doc="log entry storing rotation of the sample around the vertical axis"
)
self.declareProperty("PsiOffset", 0.0, direction=Direction.Input, doc="Add this quantity to PsiAngleLog")
self.declareProperty(
Expand All @@ -187,23 +187,23 @@ def PyInit(self):
# Reciprocal vector to be aligned with incoming beam
self.declareProperty(
FloatArrayProperty("VectorU", [1, 0, 0], array_length_three, direction=Direction.Input),
doc="three item, comma-separated, HKL indexes" "of the diffracting plane",
doc="three item, comma-separated, HKL indices of the diffracting plane",
)
# Reciprocal vector orthogonal to VectorU and in-plane with
# incoming beam
self.declareProperty(
FloatArrayProperty("VectorV", [0, 1, 0], array_length_three, direction=Direction.Input),
doc="three item, comma-separated, HKL indexes" "of the direction perpendicular to VectorV" "and the vertical axis",
doc="three item, comma-separated, HKL indices of the direction perpendicular to VectorVand the vertical axis",
)
# Abscissa view
self.declareProperty(
FloatArrayProperty("Uproj", [1, 0, 0], array_length_three, direction=Direction.Input),
doc="three item comma-separated Abscissa view" "of the diffraction pattern",
doc="three item comma-separated Abscissa view of the diffraction pattern",
)
# Ordinate view
self.declareProperty(
FloatArrayProperty("Vproj", [0, 1, 0], array_length_three, direction=Direction.Input),
doc="three item comma-separated Ordinate view" "of the diffraction pattern",
doc="three item comma-separated Ordinate view of the diffraction pattern",
)
# Hidden axis
self.declareProperty(FloatArrayProperty("Wproj", [0, 0, 1], array_length_three, direction=Direction.Input), doc="Hidden axis view")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def pyexec_setup(remove_temp, new_options):


class BASISPowderDiffraction(DataProcessorAlgorithm):
_mask_file = "/SNS/BSS/shared/autoreduce/new_masks_08_12_2015/" "BASIS_Mask_default_diff.xml"
_mask_file = "/SNS/BSS/shared/autoreduce/new_masks_08_12_2015/BASIS_Mask_default_diff.xml"
# Consider only events with these wavelengths
_wavelength_bands = {"311": [3.07, 3.60], "111": [6.05, 6.60], "333": [2.02, 2.20]}
_diff_bank_numbers = list(range(5, 14))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def PyInit(self):
self.declareProperty(
name="FitMethod",
defaultValue="log",
doc="Function to use to fit transmission; can be Linear," " Log, Polynomial (first letter shall be capital)",
doc="Function to use to fit transmission; can be Linear, Log, Polynomial (first letter shall be capital)",
)

self.declareProperty(
Expand All @@ -107,17 +107,17 @@ def PyInit(self):

self.declareProperty(
FloatArrayProperty("BinningWavelength", direction=Direction.Input, validator=FloatArrayMandatoryValidator()),
doc="Wavelength boundaries for reduction: a comma separated list of first bin boundary," " width, last bin boundary",
doc="Wavelength boundaries for reduction: a comma separated list of first bin boundary, width, last bin boundary",
)

self.declareProperty(
FloatArrayProperty("BinningWavelengthTransm", direction=Direction.Input, validator=FloatArrayMandatoryValidator()),
doc="Wavelengths boundaries for transmission binning: a comma separated list of first bin" " boundary, width, last bin",
doc="Wavelengths boundaries for transmission binning: a comma separated list of first bin boundary, width, last bin",
)

self.declareProperty(
FloatArrayProperty("BinningQ", direction=Direction.Input, validator=FloatArrayMandatoryValidator()),
doc="Output Q-boundaries: a comma separated list of first bin boundary," " width, last bin boundary",
doc="Output Q-boundaries: a comma separated list of first bin boundary, width, last bin boundary",
)

self.declareProperty(name="Timemode", defaultValue=True, doc="If data collected in ToF or monochromatic mode")
Expand Down Expand Up @@ -154,7 +154,7 @@ def PyInit(self):

self.declareProperty(
MatrixWorkspaceProperty("OutputWorkspace", "", direction=Direction.Output),
doc="Name of the workspace that contains the result of the calculation. " "Created automatically.",
doc="Name of the workspace that contains the result of the calculation. Created automatically.",
)

self.declareProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def PyInit(self):
self.declareProperty(WorkspaceProperty("Workspace", "", Direction.Input), "The workspace to check.")
self.declareProperty("LogNames", "", "Names of the logs to look for")
self.declareProperty(
"Result", "A string that will be empty if all the logs are found, " "otherwise will contain an error message", Direction.Output
"Result", "A string that will be empty if all the logs are found, otherwise will contain an error message", Direction.Output
)
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def PyInit(self):
self.declareProperty(
"GenerateVirtualInstrument",
True,
"If True, then the geometry of all the detectors will be written " "to DetectorTableWorkspace",
"If True, then the geometry of all the detectors will be written to DetectorTableWorkspace",
)

default_num_dets = 256 * 256
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def PyInit(self):
)
self.declareProperty(
"Result",
"A string that will be empty if all the logs match, " "otherwise will contain a comma separated list of not matching logs",
"A string that will be empty if all the logs match, otherwise will contain a comma separated list of not matching logs",
Direction.Output,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ def PyExec(self):
def absoluteUnits(self, atoms):
absunits = self.getProperty("StatesPerEnergy").value
if absunits and len(atoms) != 1:
self.log().warning(
"Sample material information not set, or sample is not a pure element. " "Ignoring StatesPerEnergy property."
)
self.log().warning("Sample material information not set, or sample is not a pure element. Ignoring StatesPerEnergy property.")
absunits = False
return absunits

Expand Down
Loading

0 comments on commit 5fc96e8

Please sign in to comment.