Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SyntaxWarning from tex/re strings #3163

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sas/qtgui/Calculators/DensityPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def setupUi(self):

self.setFixedSize(self.minimumSizeHint())

rx = QtCore.QRegularExpression("[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?")
rx = QtCore.QRegularExpression(r"[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?")
self.ui.editMolarVolume.setValidator(QtGui.QRegularExpressionValidator(rx, self.ui.editMolarVolume))
self.ui.editMassDensity.setValidator(QtGui.QRegularExpressionValidator(rx, self.ui.editMassDensity))

Expand Down
2 changes: 1 addition & 1 deletion src/sas/qtgui/Calculators/KiessigPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, parent=None):
self.manager = parent
self.thickness = KiessigThicknessCalculator()

rx = QtCore.QRegularExpression("[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?")
rx = QtCore.QRegularExpression(r"[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?")
self.deltaq_in.setValidator(QtGui.QRegularExpressionValidator(rx, self.deltaq_in))

# signals
Expand Down
16 changes: 8 additions & 8 deletions src/sas/qtgui/Calculators/ResolutionCalculatorPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def checkWavelength(self):
text_edit.setStyleSheet(BG_WHITE)
input_string = str(text_edit.text())
if self.cbWaveColor.currentText() != 'TOF':
input_wavelength = re.match('\d+\.?\d*', input_string)
input_wavelength = re.match(r'\d+\.?\d*', input_string)
if input_wavelength is None:
text_edit.setStyleSheet(BG_RED)
self.cmdCompute.setEnabled(False)
Expand All @@ -137,7 +137,7 @@ def checkWavelength(self):
text_edit.setStyleSheet(BG_WHITE)
self.cmdCompute.setEnabled(True)
else:
interval_wavelength = re.match('^\d+\.?\d*\s*-\s*\d+\.?\d*$',
interval_wavelength = re.match(r'^\d+\.?\d*\s*-\s*\d+\.?\d*$',
input_string)

if interval_wavelength is None:
Expand All @@ -148,7 +148,7 @@ def checkWavelength(self):
else:
# check on min < max
[wavelength_min, wavelength_max] = \
re.findall('\d+\.?\d*', interval_wavelength.group())
re.findall(r'\d+\.?\d*', interval_wavelength.group())

if float(wavelength_min) >= float(wavelength_max):
text_edit.setStyleSheet(BG_RED)
Expand All @@ -167,7 +167,7 @@ def checkWavelengthSpread(self):
if text_edit.isModified():
text_edit.setStyleSheet(BG_WHITE)
if self.cbWaveColor.currentText() != 'TOF':
pattern = '^\d+\.?\d*(|;\s*\d+)$'
pattern = r'^\d+\.?\d*(|;\s*\d+)$'
input_string = str(text_edit.text())
wavelength_spread_input = re.match(pattern, input_string)

Expand All @@ -183,7 +183,7 @@ def checkWavelengthSpread(self):
text_edit.setStyleSheet(BG_WHITE)
self.cmdCompute.setEnabled(True)
else:
pattern = '^\d+\.?\d*\s*-\s*\d+\.?\d*(|;\s*\d+)$'
pattern = r'^\d+\.?\d*\s*-\s*\d+\.?\d*(|;\s*\d+)$'
input_string = str(text_edit.text())
wavelength_spread_input = re.match(pattern, input_string)

Expand All @@ -208,7 +208,7 @@ def checkPixels(self):

if text_edit.isModified():
text_edit.setStyleSheet(BG_WHITE)
pattern = '^\d+\.?\d*,\s*\d+\.?\d*$'
pattern = r'^\d+\.?\d*,\s*\d+\.?\d*$'
input_string = str(text_edit.text())
pixels_input = re.match(pattern, input_string)

Expand All @@ -226,7 +226,7 @@ def checkQx_y(self):
""" Validator for qx and qy inputs """
Q_modified = [self.txtQx.isModified(), self.txtQy.isModified()]
if any(Q_modified):
pattern = '^-?\d+\.?\d*(,\s*-?\d+\.?\d*)*$'
pattern = r'^-?\d+\.?\d*(,\s*-?\d+\.?\d*)*$'
text_edit = self.txtQx if Q_modified[0] else self.txtQy
input_string = str(text_edit.text())
q_input = re.match(pattern, input_string)
Expand Down Expand Up @@ -265,7 +265,7 @@ def checkAperture(self):
if text_edit.isModified():
text_edit.setStyleSheet(BG_WHITE)
input_string = str(text_edit.text())
pattern = '^\d+\.?\d*(|,\s*\d+)$'
pattern = r'^\d+\.?\d*(|,\s*\d+)$'
aperture_input = re.match(pattern, input_string)

if aperture_input is None:
Expand Down
2 changes: 1 addition & 1 deletion src/sas/qtgui/Calculators/SldPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def setupUi(self):
# Chemical formula is checked via periodictable.formula module.
self.ui.editMolecularFormula.setValidator(GuiUtils.FormulaValidator(self.ui.editMolecularFormula))

rx = QtCore.QRegularExpression("[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?")
rx = QtCore.QRegularExpression(r"[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?")
self.ui.editMassDensity.setValidator(QtGui.QRegularExpressionValidator(rx, self.ui.editMassDensity))
self.ui.editNeutronWavelength.setValidator(QtGui.QRegularExpressionValidator(rx, self.ui.editNeutronWavelength))
self.ui.editXrayWavelength.setValidator(QtGui.QRegularExpressionValidator(rx, self.ui.editXrayWavelength))
Expand Down
4 changes: 2 additions & 2 deletions src/sas/qtgui/MainWindow/DataManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def rename(self, name):
return ""

# Explicitly match [0-9]+ at the end of the name
result = re.split("\[[0-9]+\]$", name)
result = re.split(r"\[[0-9]+\]$", name)
base_name = result[0].strip()

# data_name_dict: {'baseName': [0, 1, .. n]}
Expand Down Expand Up @@ -278,7 +278,7 @@ def remove_item_from_data_name_dict(self, name):
Remove 'name' or 'name [n]' from data_name_dict
"""
# Split on whitespace - split 'name [n]' into list of len() == 2
data_name_split = re.split("\[[0-9]+\]$", name)
data_name_split = re.split(r"\[[0-9]+\]$", name)
base_name = data_name_split[0].strip()
if name in self.data_name_dict:
self.data_name_dict[name].remove(0)
Expand Down
2 changes: 1 addition & 1 deletion src/sas/qtgui/Perspectives/Corfunc/ExtractionCanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def draw_data(self):
self.axes = self.fig.add_subplot(111)
self.axes.set_xscale("linear")
self.axes.set_yscale("linear")
self.axes.set_xlabel("Z [$\AA$]")
self.axes.set_xlabel(r"Z [$\AA$]")
self.axes.set_ylabel("Correlation")
self.axes.set_title("Real Space Correlations")
self.fig.tight_layout()
Expand Down
2 changes: 1 addition & 1 deletion src/sas/qtgui/Perspectives/Corfunc/IDFCanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def draw_data(self):
self.axes = self.fig.add_subplot(111)
self.axes.set_xscale("linear")
self.axes.set_yscale("linear")
self.axes.set_xlabel("Z [$\AA$]")
self.axes.set_xlabel(r"Z [$\AA$]")
self.axes.set_ylabel("IDF")
self.axes.set_title("Interface Distribution Function")
self.fig.tight_layout()
Expand Down
2 changes: 1 addition & 1 deletion src/sas/qtgui/Perspectives/Corfunc/QSpaceCanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def draw_data(self):
self.axes = self.fig.add_subplot(111)
self.axes.set_xscale("log")
self.axes.set_yscale("log")
self.axes.set_xlabel("Q [$\AA^{-1}$]")
self.axes.set_xlabel(r"Q [$\AA^{-1}$]")
self.axes.set_ylabel("I(Q) [cm$^{-1}$]")
self.axes.set_title("Scattering data")
self.fig.tight_layout()
Expand Down
6 changes: 3 additions & 3 deletions src/sas/qtgui/Perspectives/Corfunc/RealSpaceCanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ def draw_data(self):
self.axes = self.fig.add_subplot(111)
self.axes.set_xscale("linear")
self.axes.set_yscale("linear")
self.axes.set_xlabel("Z [$\AA$]")
self.axes.set_xlabel(r"Z [$\AA$]")
self.axes.set_ylabel("Correlation")
self.axes.set_title("Real Space Correlations")
self.fig.tight_layout()

if self.data is not None and len(self.data) == 2:
data1, data3 = self.data[0], self.data[1]
self.axes.plot(data1.x, data1.y, label="$\Gamma_1(z)$")
self.axes.plot(data3.x, data3.y, label="$\Gamma_3(z)$")
self.axes.plot(data1.x, data1.y, label=r"$\Gamma_1(z)$")
self.axes.plot(data3.x, data3.y, label=r"$\Gamma_3(z)$")

self.axes.set_xlim(0, max(data1.x) / 4)
self.legend = self.axes.legend()
Expand Down
2 changes: 1 addition & 1 deletion src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def plotPolydispersities(model):
xunit = model.details[name][0]
data1d.xtransform = 'x'
data1d.ytransform = 'y'
data1d.xaxis(r'\rm{{{}}}'.format(name.replace('_', '\_')), xunit)
data1d.xaxis(r'\rm{{{}}}'.format(name.replace('_', r'\_')), xunit)
data1d.yaxis(r'\rm{probability}', 'normalized')
data1d.scale = 'linear'
data1d.symbol = 'Line'
Expand Down
4 changes: 2 additions & 2 deletions src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -3905,9 +3905,9 @@ def onShowSLDProfile(self):
profile_data.symbol = 'Line'
profile_data.hide_error = True
profile_data._xaxis = "R"
profile_data._xunit = "\AA"
profile_data._xunit = r"\AA"
profile_data._yaxis = "SLD"
profile_data._yunit = "10^{-6}\AA^{-2}"
profile_data._yunit = r"10^{-6}\AA^{-2}"
profile_data.ytransform='y'
profile_data.xtransform='x'

Expand Down
2 changes: 1 addition & 1 deletion src/sas/qtgui/Perspectives/Inversion/InversionLogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def newPRPlot(self, out, pr, cov=None):
return new_plot

def add_errors(self, sigma=0.05):
"""
r"""
Adds errors to data set is they are not available.
Uses $\Delta y = \sigma | y |$.
"""
Expand Down
8 changes: 4 additions & 4 deletions src/sas/qtgui/Perspectives/ParticleEditor/syntax_highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ class PythonHighlighter(QSyntaxHighlighter):
# Comparison
'==', '!=', '<', '<=', '>', '>=',
# Arithmetic
'\+', '-', '\*', '/', '//', '\%', '\*\*',
r'\+', '-', r'\*', '/', '//', r'\%', r'\*\*',
# In-place
'\+=', '-=', '\*=', '/=', '\%=',
r'\+=', '-=', r'\*=', '/=', r'\%=',
# Bitwise
'\^', '\|', '\&', '\~', '>>', '<<',
r'\^', r'\|', r'\&', r'\~', '>>', '<<',
]

# Python braces
braces = [
'\{', '\}', '\(', '\)', '\[', '\]',
r'\{', r'\}', r'\(', r'\)', r'\[', r'\]',
]

def __init__(self, document):
Expand Down
6 changes: 3 additions & 3 deletions src/sas/qtgui/Plotting/Slicers/AnnulusSlicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ def _post_data(self, nbins=None):
new_plot.interactive = True
new_plot.detector = self.data.detector
# If the data file does not tell us what the axes are, just assume...
new_plot.xaxis("\\rm{\phi}", 'degrees')
new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}")
new_plot.xaxis(r"\rm{\phi}", 'degrees')
new_plot.yaxis(r"\rm{Intensity} ", "cm^{-1}")
if hasattr(data, "scale") and data.scale == 'linear' and \
self.data.name.count("Residuals") > 0:
new_plot.ytransform = 'y'
new_plot.yaxis("\\rm{Residuals} ", "/")
new_plot.yaxis(r"\rm{Residuals} ", "/")

new_plot.id = "AnnulusPhi" + self.data.name
new_plot.type_id = "Slicer" + self.data.name # Used to remove plots after changing slicer so they don't keep showing up after closed
Expand Down
6 changes: 3 additions & 3 deletions src/sas/qtgui/Plotting/Slicers/WedgeSlicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ def _post_data(self, new_sector=None, nbins=None):
if self.averager.__name__ == 'SectorPhi':
# angular plots usually require a linear x scale and better with
# a linear y scale as well.
new_plot.xaxis("\\rm{\phi}", "degrees")
new_plot.xaxis(r"\rm{\phi}", "degrees")
new_plot.xtransform = 'x'
new_plot.ytransform = 'y'
else:
new_plot.xaxis("\\rm{Q}", 'A^{-1}')
new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}")
new_plot.xaxis(r"\rm{Q}", 'A^{-1}')
new_plot.yaxis(r"\rm{Intensity} ", "cm^{-1}")

new_plot.id = str(self.averager.__name__) + self.data.name
new_plot.type_id = "Slicer" + self.data.name # Used to remove plots after changing slicer so they don't keep showing up after closed
Expand Down
10 changes: 5 additions & 5 deletions src/sas/qtgui/Utilities/PythonSyntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ class PythonHighlighter (QSyntaxHighlighter):
# Comparison
'==', '!=', '<', '<=', '>', '>=',
# Arithmetic
'\+', '-', '\*', '/', '//', '\%', '\*\*',
r'\+', '-', r'\*', '/', '//', r'\%', r'\*\*',
# In-place
'\+=', '-=', '\*=', '/=', '\%=',
r'\+=', '-=', r'\*=', '/=', r'\%=',
# Bitwise
'\^', '\|', '\&', '\~', '>>', '<<',
r'\^', r'\|', r'\&', r'\~', '>>', '<<',
]

# Python braces
braces = [
'\{', '\}', '\(', '\)', '\[', '\]',
r'\{', r'\}', r'\(', r'\)', r'\[', r'\]',
]
def __init__(self, document, is_python=True):
QSyntaxHighlighter.__init__(self, document)
Expand Down Expand Up @@ -209,4 +209,4 @@ def match_multiline(self, text, delimiter, in_state, style):
infile = open('PythonSyntax.py', 'r')
editor.setPlainText(infile.read())

app.exec_()
app.exec_()
8 changes: 4 additions & 4 deletions src/sas/qtgui/Utilities/UnitTesting/GuiUtilsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,11 @@ def testrstToHtml(self):

s = ".. |Ang| unicode:: U+212B"
assert rstToHtml(s) == ('Ang', 'Å')
s = ".. |Ang^-1| replace:: |Ang|\ :sup:`-1`"
s = r".. |Ang^-1| replace:: |Ang|\ :sup:`-1`"
assert rstToHtml(s) == ('Ang^-1', 'Å<sup>-1</sup>')
s = ".. |1e-6Ang^-2| replace:: 10\ :sup:`-6`\ |Ang|\ :sup:`-2`"
s = r".. |1e-6Ang^-2| replace:: 10\ :sup:`-6`\ |Ang|\ :sup:`-2`"
assert rstToHtml(s) == ('1e-6Ang^-2', '10<sup>-6</sup> Å<sup>-2</sup>')
s = ".. |cm^-1| replace:: cm\ :sup:`-1`"
s = r".. |cm^-1| replace:: cm\ :sup:`-1`"
assert rstToHtml(s) == ('cm^-1', 'cm<sup>-1</sup>')
s = ".. |deg| unicode:: U+00B0"
assert rstToHtml(s) == ('deg', '°')
Expand All @@ -532,7 +532,7 @@ def testrstToHtml(self):
def testConvertUnitToHTML(self):
''' test unit string replacement'''
s = None
assert convertUnitToHTML(s) is ""
assert convertUnitToHTML(s) == ""

s = ""
assert convertUnitToHTML(s) == s
Expand Down
4 changes: 2 additions & 2 deletions src/sas/sascalc/calculator/geni.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _calc_Iqxy(scale, x, y, qx, qy):
Iq = [abs(np.sum(scale*np.exp(1j*(qx_k*x + qy_k*y))))**2
for qx_k, qy_k in zip(qx.flat, qy.flat)]
return np.asarray(Iq).reshape(qx.shape)
_calc_Iqxy.__doc__ = """
_calc_Iqxy.__doc__ = r"""
Compute I(q) for a set of points (x, y).

Uses: I(q) = \|sum V(r) rho(r) e^(1j q.r)\|^2 / sum V(r)
Expand Down Expand Up @@ -176,7 +176,7 @@ def _calc_Iqxy_elements(sld, x, y, z, elements, vol, qx, qy):
def _calc_Iqxy_magnetic(
qx, qy, x, y, rho, vol, rho_m,
up_frac_i=1, up_frac_f=1, up_theta=0., up_phi=0.):
"""Compute I(q) for a set of points (x, y), with magnetism on each point.
r"""Compute I(q) for a set of points (x, y), with magnetism on each point.

Uses: I(q) = sum_xs w_xs \|sum V(r) rho(q, r, xs) e^(1j q.r)\|^2 / sum V(r)
where rho is adjusted for the particular q and polarization cross section.
Expand Down
2 changes: 1 addition & 1 deletion src/sas/sascalc/invariant/invariant.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def __init__(self, scale=1, power=4):
self.dpower = 0.0

def linearize_q_value(self, value):
"""
r"""
Transform the input q-value for linearization

:param value: q-value
Expand Down
Loading