Skip to content

Commit 1d5d02d

Browse files
authored
Merge pull request #3172 from havardAasen/fix-python-syntax-warning
Fix Python syntax warning
2 parents 73b22f8 + c701633 commit 1d5d02d

13 files changed

Lines changed: 59 additions & 59 deletions

File tree

lib/python/linux_event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ def invert(d):
766766
KEYBTN_invert.update(BTN_invert)
767767

768768
def humanize(s):
769-
s = re.split("(\d+)", s)
769+
s = re.split(r"(\d+)", s)
770770
def maybe_int(ss):
771771
if ss and ss[0] in "0123456789": return int(ss)
772772
return ss

lib/python/pyngcgui.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,9 +2204,9 @@ def savesection_gcmc(self):
22042204

22052205
xcmd.append(m.sub_file)
22062206
print("xcmd=",xcmd)
2207-
e_message = ".*Runtime message\(\): *(.*)"
2208-
e_warning = ".*Runtime warning\(\): *(.*)"
2209-
e_error = ".*Runtime error\(\): *(.*)"
2207+
e_message = r".*Runtime message\(\): *(.*)"
2208+
e_warning = r".*Runtime warning\(\): *(.*)"
2209+
e_error = r".*Runtime error\(\): *(.*)"
22102210

22112211
s = subprocess.Popen(xcmd
22122212
,stdout=subprocess.PIPE

lib/python/qtvcp/lib/gcode_utility/hole_circle.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,18 @@ def units_changed(self):
167167
def set_validator(self):
168168
# set valid input formats for lineEdits
169169
if self.btn_inch.isChecked():
170-
valid_size = QtGui.QRegExpValidator(QRegExp('^((\d+(\.\d{,4})?)|(\.\d{,4}))$'))
171-
valid_radius = QtGui.QRegExpValidator(QRegExp('^((\d{1,3}(\.\d{1,4})?)|(\.\d{1,4}))$'))
170+
valid_size = QtGui.QRegExpValidator(QRegExp(r'^((\d+(\.\d{,4})?)|(\.\d{,4}))$'))
171+
valid_radius = QtGui.QRegExpValidator(QRegExp(r'^((\d{1,3}(\.\d{1,4})?)|(\.\d{1,4}))$'))
172172
valid_feed = QtGui.QRegExpValidator(QRegExp('[0-9]{0,6}[.][0-9]{0,3}'))
173173
else:
174-
valid_size = QtGui.QRegExpValidator(QRegExp('^((\d+(\.\d{,3})?)|(\.\d{,3}))$'))
175-
valid_radius = QtGui.QRegExpValidator(QRegExp('^((\d{1,4}(\.\d{1,3})?)|(\.\d{1,3}))$'))
176-
valid_feed = QtGui.QRegExpValidator(QRegExp('\d{0,5}[.]\d{0,1}'))
174+
valid_size = QtGui.QRegExpValidator(QRegExp(r'^((\d+(\.\d{,3})?)|(\.\d{,3}))$'))
175+
valid_radius = QtGui.QRegExpValidator(QRegExp(r'^((\d{1,4}(\.\d{1,3})?)|(\.\d{1,3}))$'))
176+
valid_feed = QtGui.QRegExpValidator(QRegExp(r'\d{0,5}[.]\d{0,1}'))
177177

178-
self.lineEdit_spindle.setValidator(QtGui.QRegExpValidator(QRegExp('\d{0,5}')))
178+
self.lineEdit_spindle.setValidator(QtGui.QRegExpValidator(QRegExp(r'\d{0,5}')))
179179
self.lineEdit_num_holes.setValidator(QtGui.QDoubleValidator(0, 99, 0))
180180
self.lineEdit_radius.setValidator(valid_radius)
181-
self.lineEdit_first.setValidator(QtGui.QRegExpValidator(QRegExp('\d{0,3}[.]\d{0,2}')))
181+
self.lineEdit_first.setValidator(QtGui.QRegExpValidator(QRegExp(r'\d{0,3}[.]\d{0,2}')))
182182
self.lineEdit_safe_z.setValidator(valid_size)
183183
self.lineEdit_start_height.setValidator(valid_size)
184184
self.lineEdit_depth.setValidator(valid_size)

lib/python/qtvcp/lib/qt_ngcgui/ngcgui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def new_label(self, width, text):
151151

152152
def new_lineedit(self, key, data):
153153
# QRegExp('^[+-]?((\d+(\.\d{,4})?)|(\.\d{,4}))$' allows max 4 digits after the decimal
154-
valid = QtGui.QRegExpValidator(QRegExp('^[+-]?((\d+(\.\d{,4})?)|(\.\d{,4}))$'))
154+
valid = QtGui.QRegExpValidator(QRegExp(r'^[+-]?((\d+(\.\d{,4})?)|(\.\d{,4}))$'))
155155
lineedit = QLineEdit(str(data))
156156
lineedit.parm_no = key
157157
lineedit.setMaxLength(10)

lib/python/qtvcp/lib/ripper/gcode_ripper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6106,7 +6106,7 @@ def EXPRESSION_EVAL(self,line):
61066106
#########################################
61076107
### Split the text into a list ###
61086108
#########################################
6109-
line = re.split( "([\[,\],\^,\*,\/,\%,\+,\-,\| ,\& ,\l ,\< ,\g ,\> ,\! ,\= ])", line)
6109+
line = re.split( r"([\[\]^*/%+\-| &l<g>!=])", line)
61106110

61116111
#########################################
61126112
### Remove empty items from the list ###

lib/python/qtvcp/widgets/basic_probe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ def __init__(self, parent=None):
4646
super(BasicProbe, self).__init__(parent)
4747
self.proc = None
4848
if INFO.MACHINE_IS_METRIC:
49-
self.valid = QtGui.QRegExpValidator(QRegExp('^[+-]?((\d+(\.\d{,4})?)|(\.\d{,4}))$'))
49+
self.valid = QtGui.QRegExpValidator(QRegExp(r'^[+-]?((\d+(\.\d{,4})?)|(\.\d{,4}))$'))
5050
else:
51-
self.valid = QtGui.QRegExpValidator(QRegExp('^[+-]?((\d+(\.\d{,3})?)|(\.\d{,3}))$'))
51+
self.valid = QtGui.QRegExpValidator(QRegExp(r'^[+-]?((\d+(\.\d{,3})?)|(\.\d{,3}))$'))
5252
self.setMinimumSize(600, 420)
5353
# load the widgets ui file
5454
self.filename = PATH.find_widget_path('basic_probe.ui')

lib/python/qtvcp/widgets/origin_offsetview.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,18 +267,18 @@ def reload_offsets(self):
267267
else:
268268
tmpl = self.imperial_text_template
269269

270-
degree_tmpl = "%{}.2f".format(len(locale.format(tmpl, 0)))
270+
degree_tmpl = "%{}.2f".format(len(locale.format_string(tmpl, 0)))
271271

272272
# fill each row of the liststore from the offsets arrays
273273
for row, i in enumerate([ap, rot, g92, tool, g54, g55, g56, g57, g58, g59, g59_1, g59_2, g59_3]):
274274
for column in range(0, 9):
275275
if row == 1:
276276
if column == 2:
277-
self.tabledata[row][column] = locale.format(degree_tmpl, rot)
277+
self.tabledata[row][column] = locale.format_string(degree_tmpl, rot)
278278
else:
279279
self.tabledata[row][column] = " "
280280
else:
281-
self.tabledata[row][column] = locale.format(tmpl, i[column])
281+
self.tabledata[row][column] = locale.format_string(tmpl, i[column])
282282
self.tablemodel.layoutChanged.emit()
283283

284284
# We read the var file directly

lib/python/qtvcp/widgets/versa_probe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ def __init__(self, parent=None):
5454
self.tool_number = None
5555
STATUS.connect('tool-info-changed', lambda w, data: self._tool_info(data))
5656
if INFO.MACHINE_IS_METRIC:
57-
self.valid = QtGui.QRegExpValidator(QtCore.QRegExp('^((\d{1,4}(\.\d{1,3})?)|(\.\d{1,3}))$'))
57+
self.valid = QtGui.QRegExpValidator(QtCore.QRegExp(r'^((\d{1,4}(\.\d{1,3})?)|(\.\d{1,3}))$'))
5858
else:
59-
self.valid = QtGui.QRegExpValidator(QtCore.QRegExp('^((\d{1,3}(\.\d{1,4})?)|(\.\d{1,4}))$'))
59+
self.valid = QtGui.QRegExpValidator(QtCore.QRegExp(r'^((\d{1,3}(\.\d{1,4})?)|(\.\d{1,4}))$'))
6060
self.setMinimumSize(600, 420)
6161
# Load the widgets UI file will use local file if available:
6262
self.filename = PATH.find_widget_path('versa_probe.ui')

src/emc/ini/update_ini.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
def copysection(block):
1616
#Just makes a straight copy of blocks that don't need any work
17-
regex = "^\s*\[%s\](.+?)(?:^\s*\[|\Z)" % block
17+
regex = r"^\s*\[%s\](.+?)(?:^\s*\[|\Z)" % block
1818
section = re.search(regex, inistring, re.M | re.DOTALL)
1919
newini.write("\n[%s]" % block)
2020
if section != None:
@@ -178,7 +178,7 @@ def writeifexists(file, section, src_item, dest_item = "None"):
178178
inistring = open(filename,'r').read()
179179
newini = open(filename, 'w')
180180
# Get a list of all sections
181-
all_sections = re.findall("^\s*\[(.+)\]", inistring, re.MULTILINE)
181+
all_sections = re.findall(r"^\s*\[(.+)\]", inistring, re.MULTILINE)
182182

183183
# A C-style Switch would be nice here, to allow us to fall through successive
184184
# version updates.
@@ -190,13 +190,13 @@ def writeifexists(file, section, src_item, dest_item = "None"):
190190
newini.write("# The original config files may be found in the %s directory\n\n" % backupdir)
191191

192192
# reproduce everything before the first [section] verbatim
193-
section = re.match("(.*?)^\[", inistring, re.DOTALL | re.MULTILINE)
193+
section = re.match(r"(.*?)^\[", inistring, re.DOTALL | re.MULTILINE)
194194
if section !=None:
195195
newini.write(section.group(1))
196196

197197
#[EMC] Section, change the version number
198198
all_sections.remove("EMC")
199-
section = re.search("\[EMC\](.+?)\n\[", inistring, re.DOTALL)
199+
section = re.search(r"\[EMC\](.+?)\n\[", inistring, re.DOTALL)
200200
if section: section = section.group(1)
201201
newini.write("[EMC]\n")
202202
if section != None:
@@ -215,7 +215,7 @@ def writeifexists(file, section, src_item, dest_item = "None"):
215215

216216
#[RS274NGC] Section, change FEATURES to separate entries
217217
all_sections.remove("RS274NGC")
218-
section = re.search("\[RS274NGC\](.+?)\n\[", inistring, re.DOTALL)
218+
section = re.search(r"\[RS274NGC\](.+?)\n\[", inistring, re.DOTALL)
219219
if section: section = section.group(1)
220220
newini.write("\n[RS274NGC]\n")
221221
if section != None:
@@ -233,7 +233,7 @@ def writeifexists(file, section, src_item, dest_item = "None"):
233233
newini.write(section)
234234

235235
all_sections.remove("EMCMOT")
236-
section = re.search("\[EMCMOT\](.+?)\n\[", inistring, re.DOTALL)
236+
section = re.search(r"\[EMCMOT\](.+?)\n\[", inistring, re.DOTALL)
237237
if section: section = section.group(1)
238238
newini.write("[EMCMOT]\n")
239239
section = re.sub("# Interval between tries to emcmot.*?\n", "", section)
@@ -264,14 +264,14 @@ def writeifexists(file, section, src_item, dest_item = "None"):
264264
for halfile in halpaths:
265265
hal = open(os.path.join(os.path.dirname(filename), halfile), 'r')
266266
for line in hal.readlines():
267-
match = re.match('(?:#autoconverted|loadrt) +(\w+kins)', line)
267+
match = re.match(r'(?:#autoconverted|loadrt) +(\w+kins)', line)
268268
if match:
269269
kins = match.group(1)
270-
match = re.search('coordinates *= *(\w+)', line)
270+
match = re.search(r'coordinates *= *(\w+)', line)
271271
if match:
272272
coordinates = list(match.group(1))
273273
coords_entry = 1
274-
match = re.search('kinstype *= *(\w+)', line)
274+
match = re.search(r'kinstype *= *(\w+)', line)
275275
if kinstype: kinstype = match.group(1)
276276
break
277277
if kins: break
@@ -286,7 +286,7 @@ def writeifexists(file, section, src_item, dest_item = "None"):
286286
for halfile in halpaths:
287287
hal = open(os.path.join(os.path.dirname(filename), halfile), 'r')
288288
for line in hal.readlines():
289-
match = re.match('setp +gantrykins.joint-(\d) +(\d)', line)
289+
match = re.match(r'setp +gantrykins.joint-(\d) +(\d)', line)
290290
if match:
291291
j = int(match.group(1))
292292
if j > joints: joints = j
@@ -298,15 +298,15 @@ def writeifexists(file, section, src_item, dest_item = "None"):
298298

299299
# In JA [TRAJ] expects MAX_LINEAR_VELOCITY not MAX_VELOCITY
300300
all_sections.remove("TRAJ")
301-
section = re.search("\[TRAJ\](.+?)\n\[", inistring, re.DOTALL)
301+
section = re.search(r"\[TRAJ\](.+?)\n\[", inistring, re.DOTALL)
302302
if section: section = section.group(1)
303303
newini.write("\n[TRAJ]\n")
304304
if section != None:
305305
if not re.search("MAX_LINEAR_VELOCITY", section):
306306
if re.search("MAX_VELOCITY", section):
307307
section = re.sub("MAX_VELOCITY", "MAX_LINEAR_VELOCITY", section)
308308
else:
309-
mv = re.findall("MAX_VELOCITY[\s=]+(\d*(\.\d+)?)", inistring, re.MULTILINE)
309+
mv = re.findall(r"MAX_VELOCITY[\s=]+(\d*(\.\d+)?)", inistring, re.MULTILINE)
310310
section = ("\n# this value based on fastest single axis" +
311311
"\nMAX_LINEAR_VELOCITY = %s" % max(mv)[0] + section)
312312
if not re.search("DEFAULT_LINEAR_VELOCITY", section):
@@ -338,8 +338,8 @@ def writeifexists(file, section, src_item, dest_item = "None"):
338338
L2J={}
339339
while 1:
340340
# Search preferentially in "[JOINT_N] in case the file is part-converted already
341-
if re.search("^(\[JOINT_%i\])"%j, inistring, re.MULTILINE):
342-
if re.search("^(\[AXIS_%s\])" % "XYZABCUVW"[j], inistring, re.MULTILINE):
341+
if re.search(r"^(\[JOINT_%i\])"%j, inistring, re.MULTILINE):
342+
if re.search(r"^(\[AXIS_%s\])" % "XYZABCUVW"[j], inistring, re.MULTILINE):
343343
copysection("AXIS_%s" % "XYZABCUVW"[j])
344344
# copysection("JOINT_%i" % j)
345345
elif j < len(coordinates):
@@ -385,17 +385,17 @@ def writeifexists(file, section, src_item, dest_item = "None"):
385385
for J in L2J[L]:
386386
# Take the coordinates index as the JOINT_Number
387387
newini.write("\n[JOINT_%i]" % J)
388-
section = re.search("\[AXIS_%i\](.+?)(\n\[|$)" % J, inistring, re.DOTALL)
388+
section = re.search(r"\[AXIS_%i\](.+?)(\n\[|$)" % J, inistring, re.DOTALL)
389389
if not section:
390-
section = re.search("\[AXIS_%i\](.+?)(\n\[|$)" % "XYZABCUVW".index(coordinates[J]), inistring, re.DOTALL)
390+
section = re.search(r"\[AXIS_%i\](.+?)(\n\[|$)" % "XYZABCUVW".index(coordinates[J]), inistring, re.DOTALL)
391391
if section:
392392
section = re.sub("HOME_SEQUENCE.*", sequence, section.group(1))
393393
newini.write(section)
394-
if not '\[AXIS_%i\]' % axisnum in subs:
395-
subs.update({'\[AXIS_%i\]' % axisnum : '[JOINT_%i]' % J})
396-
subs2.update({'joint\.%i\.' % axisnum : 'joint.%i.' % J})
394+
if not r'\[AXIS_%i\]' % axisnum in subs:
395+
subs.update({r'\[AXIS_%i\]' % axisnum : '[JOINT_%i]' % J})
396+
subs2.update({r'joint\.%i\.' % axisnum : 'joint.%i.' % J})
397397
else:
398-
subs.update({'\[AXIS_%i\]' % J : '[JOINT_%i]' % J})
398+
subs.update({r'\[AXIS_%i\]' % J : '[JOINT_%i]' % J})
399399
else:
400400
print("File parsing error, found an [AXIS_%i] section, but no content" % J)
401401
exit()
@@ -484,7 +484,7 @@ def writeifexists(file, section, src_item, dest_item = "None"):
484484
'halui.joint.selected': 'halui.joint.selected',
485485
'halui.joint.selected.is_homed':'halui.joint.selected.is-homed',
486486
'halui.joint.selected.on-soft-limit':'halui.joint.selected.on-soft-max-limit',
487-
'num_joints=\[TRAJ\]AXES': 'num_joints=[KINS]JOINTS',
487+
'num_joints=[TRAJ]AXES': 'num_joints=[KINS]JOINTS',
488488
'loadrt(.+kins)': 'loadrt [KINS]KINEMATICS\n#autoconverted \\1',
489489
'shuttlexpress': 'shuttle',
490490
'shuttlepro': 'shuttle',
@@ -495,7 +495,7 @@ def writeifexists(file, section, src_item, dest_item = "None"):
495495

496496
# converts @axN@ pattern to axis.L and splits any malformed setp from mpg
497497
subs2.update({
498-
'^\s*setp\s+(joint\S+)\s+(axis\S+)\s+(\S+)\s*$':
498+
r'^\s*setp\s+(joint\S+)\s+(axis\S+)\s+(\S+)\s*$':
499499
'setp \\1 \\3\nsetp \\2 \\3\n',
500500
'@ax0@': 'axis.x',
501501
'@ax1@': 'axis.y',

src/emc/usr_intf/axis/scripts/image-to-gcode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,9 @@ def filter_nonfloat(event):
547547
if event.char in "0123456789.": return
548548
return "break"
549549

550-
validate_float = "expr {![regexp {^-?([0-9]+(\.[0-9]*)?|\.[0-9]+|)$} %P]}"
550+
validate_float = r"expr {![regexp {^-?([0-9]+(\.[0-9]*)?|\.[0-9]+|)$} %P]}"
551551
validate_int = "expr {![regexp {^-?([0-9]+|)$} %P]}"
552-
validate_posfloat = "expr {![regexp {^?([0-9]+(\.[0-9]*)?|\.[0-9]+|)$} %P]}"
552+
validate_posfloat = r"expr {![regexp {^?([0-9]+(\.[0-9]*)?|\.[0-9]+|)$} %P]}"
553553
validate_posint = "expr {![regexp {^([0-9]+|)$} %P]}"
554554
def floatentry(f, v):
555555
var = tkinter.DoubleVar(f)

0 commit comments

Comments
 (0)