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

Make regex patterns raw strings #605

Open
wants to merge 4 commits into
base: master
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 boost_adaptbx/boost/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class gcc_version(object):

def __init__(self):
pat = r" \s* = \s* (\d+) \s+"
m = re.search("__GNUC__ %s __GNUC_MINOR__ %s __GNUC_PATCHLEVEL__ %s"
m = re.search(r"__GNUC__ %s __GNUC_MINOR__ %s __GNUC_PATCHLEVEL__ %s"
% ((pat,)*3),
platform_info, re.X|re.M|re.S)
if not m:
Expand Down
6 changes: 3 additions & 3 deletions cctbx/eltbx/attenuation_coefficient.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ def chemlex(formula):
import re

# Check that the formula is valid
if re.match('^([A-Z][a-z]{0,2}[1-9]?)*$', formula):
if re.match(r'^([A-Z][a-z]{0,2}[1-9]?)*$', formula):

# Split the components by capital letter
comp = re.findall('[A-Z][^A-Z]*', formula)
comp = re.findall(r'[A-Z][^A-Z]*', formula)

# For each component split into element and number
el_num = []
for c in comp:

r = re.compile('([A-Z][a-z]{0,2})([1-9]+)')
r = re.compile(r'([A-Z][a-z]{0,2})([1-9]+)')
m = r.match(c)
if m:
el = m.group(1)
Expand Down
2 changes: 1 addition & 1 deletion dox.sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def boostFuncSignature(name,obj,removeSelf=False):
if len(docc)<2: return None,docc
doc1=docc[1]
# functions with weird docstring, likely not documented by boost
if not re.match('^'+nname+r'(.*)->.*$',doc1):
if not re.match(r'^'+nname+r'(.*)->.*$',doc1):
return None,docc
if doc1.endswith(':'): doc1=doc1[:-1]
strippedDoc=doc.split('\n')[2:]
Expand Down
4 changes: 2 additions & 2 deletions gltbx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def show_versions():
def check_glx_availability():
glxerr = easy_run.fully_buffered("glxinfo -b").stderr_lines
for line in glxerr :
if re.search('extension "GLX" missing', line):
if re.search(r'extension "GLX" missing', line):
return False
return True

Expand All @@ -58,7 +58,7 @@ def __init__(self):
import re
self.__dict__ = self._shared_state
if not self._shared_state:
vers_pat = re.compile("^((\d+)\.(\d+))(?:\.(\d+))?(?: (.*))?$")
vers_pat = re.compile(r"^((\d+)\.(\d+))(?:\.(\d+))?(?: (.*))?$")
m = vers_pat.search(gl.glGetString(gl.GL_VERSION))
self.__dict__.update(dict(zip(
["principal", "major_number", "minor_number", "release_number",
Expand Down
2 changes: 1 addition & 1 deletion iotbx/bioinformatics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Wrap lines that are longer than 'width'
def wrap(text, width):

return re.findall( "[^\n]{1,%d}" % width, text )
return re.findall( r"[^\n]{1,%d}" % width, text )


# Sequence headers
Expand Down
18 changes: 9 additions & 9 deletions iotbx/cif/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ def get_HL_labels(self, keys):
or like 'HLanomA', 'HLanomB', 'HLanomC', 'HLanomD'
Use a regular expression to group them accordingly
"""
allmatches = re.findall("(\S*(HL(\S*)[abcdABCD](\S*)))", alllabels )
allmatches = re.findall(r"(\S*(HL(\S*)[abcdABCD](\S*)))", alllabels )
HLtagslst = list(set([ (e[2], e[3]) for e in allmatches ]))
usedkeys = []
for m in HLtagslst:
Expand All @@ -794,7 +794,7 @@ def get_mapcoefficient_labels(self, keys):
remainingkeys = lstkeys[:] # deep copy the list
alllabels = " ".join(lstkeys) # _refln.FC _refln.PHIC _refln.FC_ALL _refln.PHIC_ALL _refln.FWT _refln.PHWT _refln.DELFWT _refln.PHDELWT
mapcoefflabels = []
PHmatches = re.findall("((\S*PH)([^I]\S*))", alllabels ) # [('_refln.PHWT', '_refln.PH', 'WT'), ('_refln.PHDELWT', '_refln.PH', 'DELWT')]
PHmatches = re.findall(r"((\S*PH)([^I]\S*))", alllabels ) # [('_refln.PHWT', '_refln.PH', 'WT'), ('_refln.PHDELWT', '_refln.PH', 'DELWT')]
for label in lstkeys:
for m in PHmatches:
Flabel = m[1].replace("PH","F") + m[2]
Expand All @@ -803,7 +803,7 @@ def get_mapcoefficient_labels(self, keys):
remainingkeys.remove(label)
remainingkeys.remove(m[0])
alllabels = " ".join(remainingkeys)
PHImatches = re.findall("((\S*PHI)(\S*))", alllabels ) # [('_refln.PHIC', '_refln.PHI', 'C'), ('_refln.PHIC_ALL', '_refln.PHI', 'C_ALL')]
PHImatches = re.findall(r"((\S*PHI)(\S*))", alllabels ) # [('_refln.PHIC', '_refln.PHI', 'C'), ('_refln.PHIC_ALL', '_refln.PHI', 'C_ALL')]
for label in lstkeys:
for m in PHImatches:
Flabel = m[1].replace("PHI","F") + m[2]
Expand All @@ -812,7 +812,7 @@ def get_mapcoefficient_labels(self, keys):
remainingkeys.remove(label)
remainingkeys.remove(m[0])
alllabels = " ".join(remainingkeys)
PHDELmatches = re.findall("(((\S*)PH)([^I]\S*(WT)))", alllabels ) # [('_refln.PHDELWT', '_refln.PH', '_refln.', 'DELWT', 'WT')]
PHDELmatches = re.findall(r"(((\S*)PH)([^I]\S*(WT)))", alllabels ) # [('_refln.PHDELWT', '_refln.PH', '_refln.', 'DELWT', 'WT')]
for label in lstkeys:
for m in PHDELmatches:
Flabel = m[2] + m[3].replace("WT","FWT")
Expand All @@ -821,7 +821,7 @@ def get_mapcoefficient_labels(self, keys):
remainingkeys.remove(label)
remainingkeys.remove(m[0])
alllabels = " ".join(remainingkeys)
phase_matches = re.findall("((\S*\.)phase(_\S*))", alllabels ) # [('_refln.phase_calc', '_refln.', '')]
phase_matches = re.findall(r"((\S*\.)phase(_\S*))", alllabels ) # [('_refln.phase_calc', '_refln.', '')]
for label in lstkeys:
for m in phase_matches:
phaselabel = m[0]
Expand All @@ -843,7 +843,7 @@ def guess_observationtype(labl):
if labl.startswith(okey):
return self.observation_types[okey]
return None
sigma_matches = re.findall("((\S*\.)SIG(\S*))", alllabels ) # catch label pairs like F(+),SIGF(+)
sigma_matches = re.findall(r"((\S*\.)SIG(\S*))", alllabels ) # catch label pairs like F(+),SIGF(+)
for label in lstkeys:
for m in sigma_matches:
FIlabel = m[1] + m[2]
Expand All @@ -852,7 +852,7 @@ def guess_observationtype(labl):
remainingkeys.remove(label)
remainingkeys.remove(m[0])
alllabels = " ".join(remainingkeys)
sigma_matches = re.findall("((\S*)_sigma(_*\S*))", alllabels ) # [('_refln.F_meas_sigma_au', '_refln.F_meas', '_au'), ('_refln.intensity_sigma', '_refln.intensity', ''), ('_refln.pdbx_I_plus_sigma', '_refln.pdbx_I_plus', '')]
sigma_matches = re.findall(r"((\S*)_sigma(_*\S*))", alllabels ) # [('_refln.F_meas_sigma_au', '_refln.F_meas', '_au'), ('_refln.intensity_sigma', '_refln.intensity', ''), ('_refln.pdbx_I_plus_sigma', '_refln.pdbx_I_plus', '')]
for label in lstkeys:
for m in sigma_matches:
FIlabel = m[1] + m[2]
Expand All @@ -862,8 +862,8 @@ def guess_observationtype(labl):
remainingkeys.remove(m[0])
alllabels = " ".join(remainingkeys)
# catch generic meas and sigma labels, https://www.iucr.org/__data/iucr/cifdic_html/2/cif_mm.dic/index.html
anymeas_matches = re.findall("((\S*)_meas(\S*))", alllabels ) + re.findall("((\S*)_calc(\S*))", alllabels )
anysigma_matches = re.findall("((\S*)_sigma(\S*))", alllabels )
anymeas_matches = re.findall(r"((\S*)_meas(\S*))", alllabels ) + re.findall(r"((\S*)_calc(\S*))", alllabels )
anysigma_matches = re.findall(r"((\S*)_sigma(\S*))", alllabels )
for mmatch in anymeas_matches:
for smatch in anysigma_matches:
if mmatch[1]==smatch[1] and mmatch[2]==smatch[2]:
Expand Down
2 changes: 1 addition & 1 deletion iotbx/command_line/file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
.caption = Any_format %s
}
""" % (" ".join(file_reader.standard_file_types),
" ".join([ re.sub(" ", "_", file_reader.standard_file_descriptions[ft])
" ".join([ re.sub(r" ", "_", file_reader.standard_file_descriptions[ft])
for ft in file_reader.standard_file_types ])))

def run(args=(), params=None, out=sys.stdout):
Expand Down
2 changes: 1 addition & 1 deletion iotbx/command_line/pdb_as_fasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def run(args=(), params=None, out=sys.stdout):
else :
seq = "".join(chain.as_sequence())
if (params.ignore_missing_residues_at_start):
seq = re.sub("^X*", "", seq)
seq = re.sub(r"^X*", "", seq)
seq_lines = []
k = 0
while (k < len(seq)):
Expand Down
2 changes: 1 addition & 1 deletion iotbx/data_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# datatypes have corresponding modules in iotbx/data_manager
# e.g. iotbx/data_manager/model.py
supported_datatypes = os.listdir(os.path.dirname(__file__))
re_search = re.compile('.py$')
re_search = re.compile(r'\.py$')
supported_datatypes = list(filter(re_search.search, supported_datatypes))
supported_datatypes.remove('__init__.py')
supported_datatypes.sort()
Expand Down
6 changes: 3 additions & 3 deletions iotbx/data_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ def import_loggraph(self, lines):
assert remainder == '', 'loggraph table has %d bytes following the table end' % len(remainder)

if '$TABLE' in header:
title = re.search('\\$TABLE\\s*:(.*?)(:|\n|$)', header, re.MULTILINE)
title = re.search(r'\$TABLE\s*:(.*?)(:|\n|$)', header, re.MULTILINE)
if title:
self.title = title.group(1).strip()

graphs = re.search('\\$(GRAPHS|SCATTER)[\\s\n]*((:[^:\n]*:[^:\n]*:[^:\n]*(:|$)[\\s\n]*)*)($|\\$)', header, re.MULTILINE)
graphs = re.search(r'\$(GRAPHS|SCATTER)[\s\n]*((:[^:\n]*:[^:\n]*:[^:\n]*(:|$)[\s\n]*)*)($|\$)', header, re.MULTILINE)
if graphs:
if graphs.group(1) == 'GRAPHS':
self.plot_type = "GRAPH"
Expand All @@ -201,7 +201,7 @@ def import_loggraph(self, lines):
else:
raise TypeError('Unknown graph type %s' % graphs.group(1))
graphs = graphs.group(2)
for graph in re.finditer(':([^:\n]*):([^:\n]*):([^:\n]*)(:|$)', graphs, re.MULTILINE):
for graph in re.finditer(r':([^:\n]*):([^:\n]*):([^:\n]*)(:|$)', graphs, re.MULTILINE):
self.add_graph(name=graph.group(1),
type=graph.group(2),
columns=[ int(col)-1 for col in graph.group(3).split(',') ])
Expand Down
2 changes: 1 addition & 1 deletion iotbx/detectors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,5 @@ def __str__(self):
def get_frame_path(self, frame):
assert isinstance(frame, int) and (frame > 0)
serial_format = "%%0%dd" % (self.base_name.count("#"))
format_str = re.sub("[#]{1,}", serial_format, self.base_name)
format_str = re.sub(r"[#]{1,}", serial_format, self.base_name)
return format_str % frame
2 changes: 1 addition & 1 deletion iotbx/file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def _try_as_seq(self):
# assert len(self._file_object) != 0
# for _line in self._file_object.splitlines():
# assert not _line.startswith(" ")
# line = re.sub(" ", "", _line)
# line = re.sub(r" ", "", _line)
# assert ((len(line) == 0) or
# (line[0] == ">") or
# (line == "*") or
Expand Down
8 changes: 4 additions & 4 deletions iotbx/fullprof/write_pcr.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,27 +190,27 @@ def __replace_match(string, match, var):
for param in freeparams:
if param == "scale":
# free all scale factors
for m in re.finditer('##_scf_##', ret):
for m in re.finditer(r'##_scf_##', ret):
ret = __replace_match(ret, m , varcount)
varcount += 1
elif param == "lattice":
# free all lattice parameters
for m in re.finditer('##_lp.*?_##', ret):
for m in re.finditer(r'##_lp.*?_##', ret):
if m.group(0) not in param_to_var:
param_to_var[m.group(0)] = varcount
varcount += 1
ret = __replace_match(ret, m , param_to_var[m.group(0)])
elif param == "profile":
# free all profile parameters
for m in re.finditer('##_prf*?_##', ret):
for m in re.finditer(r'##_prf*?_##', ret):
if m.group(0) not in param_to_var:
param_to_var[m.group(0)] = varcount
varcount += 1
ret = __replace_match(ret, m , param_to_var[m.group(0)])
else:
raise ValueError("unknown parameter type: '{0}'".format(param))
# fix all still unhandled flags
for m in re.finditer('##_.*?_##', ret):
for m in re.finditer(r'##_.*?_##', ret):
ret = ret[:m.start()] + "0.00".rjust(len(m.group(0))) + ret[m.end():]
ret = ret.replace('#__npar__#', str(varcount-1))
return ret
Expand Down
4 changes: 2 additions & 2 deletions iotbx/logfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def float_or_none(n):

def percent_to_float(value):
assert value.endswith("%")
return float(re.sub("\%$", "", value))
return float(re.sub(r"\%$", "", value))

class experiment_info(object):
def extract_all_stats(self):
Expand Down Expand Up @@ -471,7 +471,7 @@ def parse_xscale(lines):
elif (fields[0] == "total"):
overall = fields
break
elif re.match("^\d", line):
elif re.match(r"^\d", line):
bins.append(fields)
j += 1
assert (len(bins) > 0) and (len(overall) == len(bins[0]))
Expand Down
2 changes: 1 addition & 1 deletion iotbx/mtz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def hendrickson_lattman(self, root_label, i_coeff, anomalous_sign=None):
class ccp4_label_decorator(label_decorator):
def phases(self, root_label, anomalous_sign=None):
assert (root_label in ["FWT", "DELFWT"])
root_label = re.sub("F", "", root_label)
root_label = re.sub(r"F", "", root_label)
return self.anomalous(
"PH" + root_label + self.phases_suffix,
anomalous_sign)
Expand Down
4 changes: 2 additions & 2 deletions iotbx/pdb/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import os

def looks_like_pdb_id(id):
return (len(id) == 4) and (re.match("[1-9]{1}[a-zA-Z0-9]{3}", id))
return (len(id) == 4) and (re.match(r"[1-9]{1}[a-zA-Z0-9]{3}", id))

def validate_pdb_id(id):
if (not looks_like_pdb_id(id)):
Expand Down Expand Up @@ -77,7 +77,7 @@ def fetch(id, data_type="pdb", format="pdb", mirror="rcsb", log=None,
cache_files = os.listdir(local_cache)
for file_name in cache_files :
if (len(file_name) > 4):
file_id = re.sub("^pdb", "", file_name)[0:4]
file_id = re.sub(r"^pdb", "", file_name)[0:4]
if (file_id.lower() == id):
if (guess_file_type(file_name) == "pdb"):
file_name = os.path.join(local_cache, file_name)
Expand Down
10 changes: 5 additions & 5 deletions iotbx/pdb/remediation/remediator.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ def remediate(filename, remediated_out, f=None):
pdb_file = open(filename)

aa_re = re.compile(
' HN2 (ALA|ARG|ASN|ASP|ASX|CSE|CYS|GLN|GLU|GLX|GLY|HIS|ILE|'+
'LEU|LYS|MET|MSE|PHE|PRO|SER|THR|TRP|UNK|TYR|VAL)')
r' HN2 (ALA|ARG|ASN|ASP|ASX|CSE|CYS|GLN|GLU|GLX|GLY|HIS|ILE|'+
r'LEU|LYS|MET|MSE|PHE|PRO|SER|THR|TRP|UNK|TYR|VAL)')

for line in pdb_file:
line=line.rstrip()
Expand All @@ -350,7 +350,7 @@ def remediate(filename, remediated_out, f=None):
elif re.match(r'REMARK...\D',line):
print_line += line + "\n"
continue
elif re.match('REMARK 4 REMEDIATOR',line):
elif re.match(r'REMARK 4 REMEDIATOR',line):
continue
elif int(line[6:10]) > 4:
print_line += remark4 + "\n"
Expand Down Expand Up @@ -390,8 +390,8 @@ def remediate(filename, remediated_out, f=None):
m = aa_re.search(print_line)
if m:
res = m.group(1)
if re.search('1H '+res,print_line) or re.search('2H '+res,print_line):
print_line = re.sub(' HN2 '+res,'2H '+res,print_line)
if re.search(r'1H '+res,print_line) or re.search(r'2H '+res,print_line):
print_line = re.sub(r' HN2 '+res,'2H '+res,print_line)
print_line=print_line.rstrip("\n")

if not (print_line == ""):
Expand Down
6 changes: 3 additions & 3 deletions iotbx/reflection_file_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,9 @@ def __init__(self, params, input_files=None, inputs_object=None,
default_types = iotbx.mtz.default_column_types(output_array)
if (array_types[i] is not None):
if output_array.is_xray_amplitude_array():
array_types[i] = re.sub("J", "F", array_types[i])
array_types[i] = re.sub(r"J", "F", array_types[i])
elif output_array.is_xray_intensity_array():
array_types[i] = re.sub("F", "J", array_types[i])
array_types[i] = re.sub(r"F", "J", array_types[i])
if len(default_types) == len(array_types[i]):
print("Recovering original column types %s" % array_types[i], file=log)
column_types = array_types[i]
Expand Down Expand Up @@ -956,7 +956,7 @@ def modify_array(
raise Sorry("Missing output labels for %s!" % array_name)
if (array_params.column_root_label is not None):
output_labels = None
labels_base = re.sub(",merged$", "", array_params.labels)
labels_base = re.sub(r",merged$", "", array_params.labels)
input_labels = labels_base.split(",")
if not None in [array_params.scale_factor, array_params.scale_max] :
raise Sorry("The parameters scale_factor and scale_max are " +
Expand Down
2 changes: 1 addition & 1 deletion iotbx/table_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def format_d_max_min(d_max_min):
else :
(d_max, d_min) = d_max_min
d_max_str = "%.4g " % d_max
d_min_str = re.sub("\.$", ".0", re.sub("0*$", "", "%.3f" % d_min))
d_min_str = re.sub(r"\.$", ".0", re.sub(r"0*$", "", "%.3f" % d_min))
return "%s - %s" % (d_max_str, d_min_str)

def resize_column(cell_values, alignment="right"):
Expand Down
4 changes: 2 additions & 2 deletions libtbx/auto_build/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ def set_git_repository_config_to_rebase(config):
else:
branch = False
remote, rebase = False, False
if re.match('remote\s*=', line.strip()):
if re.match(r'remote\s*=', line.strip()):
remote = True
if re.match('rebase\s*=', line.strip()):
if re.match(r'rebase\s*=', line.strip()):
rebase = True
if branch and remote and not rebase:
insertions.insert(0, (n + 1, branch))
Expand Down
2 changes: 1 addition & 1 deletion libtbx/auto_build/create_mac_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def run(args, out=sys.stdout):
[py2app]
argv-emulation=0""")
f.close()
script_name = re.sub(".pyc$", ".py", py2app.script_py2applet.__file__)
script_name = re.sub(r"\.pyc$", ".py", py2app.script_py2applet.__file__)
import subprocess
executable = sys.executable
if (options.python_interpreter is not None):
Expand Down
4 changes: 2 additions & 2 deletions libtbx/auto_build/setup_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def get_module(module_name):
print("")
print("********** FETCHING MODULES **********")
print("")
module_list = re.sub(",", " ", module_list)
module_list = re.sub(r",", " ", module_list)
for module_name in module_list.split():
get_module(module_name)

Expand All @@ -241,7 +241,7 @@ def get_module(module_name):
base_module_dir = op.join(options.dest, installer_dir, "base")
os.makedirs(base_module_dir)
os.chdir(base_module_dir)
base_module_list = re.sub(",", " ", base_module_list)
base_module_list = re.sub(r",", " ", base_module_list)
for module_name in base_module_list.split():
get_module(module_name)

Expand Down
2 changes: 1 addition & 1 deletion libtbx/fastentrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def main():
import shutil
import sys
dests = sys.argv[1:] or ['.']
filename = re.sub('\.pyc$', '.py', __file__)
filename = re.sub(r'\.pyc$', '.py', __file__)

for dst in dests:
shutil.copy(filename, dst)
Expand Down
Loading