Skip to content

Commit 66462d3

Browse files
authored
Merge pull request #3106 from effigies/mnt/deprecations
FIX: Mark strings containing regex escapes as raw
2 parents 63e5ef2 + d7cf744 commit 66462d3

File tree

7 files changed

+25
-24
lines changed

7 files changed

+25
-24
lines changed

nipype/interfaces/diffusion_toolkit/odf.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ class HARDIMat(CommandLine):
9696

9797
def _create_gradient_matrix(self, bvecs_file, bvals_file):
9898
_gradient_matrix_file = "gradient_matrix.txt"
99-
bvals = [val for val in re.split("\s+", open(bvals_file).readline().strip())]
99+
bvals = [val for val in re.split(r"\s+", open(bvals_file).readline().strip())]
100100
bvecs_f = open(bvecs_file)
101-
bvecs_x = [val for val in re.split("\s+", bvecs_f.readline().strip())]
102-
bvecs_y = [val for val in re.split("\s+", bvecs_f.readline().strip())]
103-
bvecs_z = [val for val in re.split("\s+", bvecs_f.readline().strip())]
101+
bvecs_x = [val for val in re.split(r"\s+", bvecs_f.readline().strip())]
102+
bvecs_y = [val for val in re.split(r"\s+", bvecs_f.readline().strip())]
103+
bvecs_z = [val for val in re.split(r"\s+", bvecs_f.readline().strip())]
104104
bvecs_f.close()
105105
gradient_matrix_f = open(_gradient_matrix_file, "w")
106106
for i in range(len(bvals)):

nipype/interfaces/dipy/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def create_interface_specs(class_name, params=None, BaseClass=TraitedSpec):
158158
attr[name] = traits_type(desc=desc[-1], mandatory=is_mandatory)
159159
else:
160160
attr[name] = traits_type(
161-
p[3], desc=desc[-1], exists=True, usedefault=True,
161+
p[3], desc=desc[-1], exists=True, usedefault=True
162162
)
163163

164164
newclass = type(str(class_name), (BaseClass,), attr)
@@ -189,7 +189,7 @@ def dipy_to_nipype_interface(cls_name, dipy_flow, BaseClass=DipyBaseInterface):
189189
parser = IntrospectiveArgumentParser()
190190
flow = dipy_flow()
191191
parser.add_workflow(flow)
192-
default_values = inspect.getargspec(flow.run).defaults
192+
default_values = inspect.getfullargspec(flow.run).defaults
193193
optional_params = [
194194
args + (val,) for args, val in zip(parser.optional_parameters, default_values)
195195
]

nipype/interfaces/elastix/utils.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class EditTransform(BaseInterface):
8585
input_spec = EditTransformInputSpec
8686
output_spec = EditTransformOutputSpec
8787
_out_file = ""
88-
_pattern = '\((?P<entry>%s\s"?)([-\.\s\w]+)("?\))'
88+
_pattern = r'\((?P<entry>%s\s"?)([-\.\s\w]+)("?\))'
8989

9090
_interp = {"nearest": 0, "linear": 1, "cubic": 3}
9191

@@ -103,14 +103,14 @@ def _run_interface(self, runtime):
103103
p = re.compile(
104104
(self._pattern % "ResultImagePixelType").decode("string-escape")
105105
)
106-
rep = "(\g<entry>%s\g<3>" % self.inputs.output_type
106+
rep = r"(\g<entry>%s\g<3>" % self.inputs.output_type
107107
contents = p.sub(rep, contents)
108108

109109
if isdefined(self.inputs.output_format):
110110
p = re.compile(
111111
(self._pattern % "ResultImageFormat").decode("string-escape")
112112
)
113-
rep = "(\g<entry>%s\g<3>" % self.inputs.output_format
113+
rep = r"(\g<entry>%s\g<3>" % self.inputs.output_format
114114
contents = p.sub(rep, contents)
115115

116116
if isdefined(self.inputs.interpolation):
@@ -119,7 +119,7 @@ def _run_interface(self, runtime):
119119
"string-escape"
120120
)
121121
)
122-
rep = "(\g<entry>%s\g<3>" % self._interp[self.inputs.interpolation]
122+
rep = r"(\g<entry>%s\g<3>" % self._interp[self.inputs.interpolation]
123123
contents = p.sub(rep, contents)
124124

125125
if isdefined(self.inputs.reference_image):
@@ -130,17 +130,17 @@ def _run_interface(self, runtime):
130130

131131
size = " ".join(["%01d" % s for s in im.shape])
132132
p = re.compile((self._pattern % "Size").decode("string-escape"))
133-
rep = "(\g<entry>%s\g<3>" % size
133+
rep = r"(\g<entry>%s\g<3>" % size
134134
contents = p.sub(rep, contents)
135135

136136
index = " ".join(["0" for s in im.shape])
137137
p = re.compile((self._pattern % "Index").decode("string-escape"))
138-
rep = "(\g<entry>%s\g<3>" % index
138+
rep = r"(\g<entry>%s\g<3>" % index
139139
contents = p.sub(rep, contents)
140140

141141
spacing = " ".join(["%0.4f" % f for f in im.header.get_zooms()])
142142
p = re.compile((self._pattern % "Spacing").decode("string-escape"))
143-
rep = "(\g<entry>%s\g<3>" % spacing
143+
rep = r"(\g<entry>%s\g<3>" % spacing
144144
contents = p.sub(rep, contents)
145145

146146
itkmat = np.eye(4)
@@ -156,7 +156,7 @@ def _run_interface(self, runtime):
156156
# contents = p.sub(rep, contents)
157157

158158
p = re.compile((self._pattern % "Origin").decode("string-escape"))
159-
rep = "(\g<entry>%s\g<3>" % orig
159+
rep = r"(\g<entry>%s\g<3>" % orig
160160
contents = p.sub(rep, contents)
161161

162162
with open(self._get_outfile(), "w") as of:

nipype/interfaces/freesurfer/utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ def _format_arg(self, name, spec, value):
10171017
# extension strings
10181018
if value.endswith(".annot"):
10191019
value = value[:-6]
1020-
if re.match("%s[\.\-_]" % self.inputs.hemi, value[:3]):
1020+
if re.match(r"%s[\.\-_]" % self.inputs.hemi, value[:3]):
10211021
value = value[3:]
10221022
return "-annotation %s" % value
10231023
return super(SurfaceSnapshots, self)._format_arg(name, spec, value)
@@ -1145,7 +1145,7 @@ class ImageInfo(FSCommand):
11451145
output_spec = ImageInfoOutputSpec
11461146

11471147
def info_regexp(self, info, field, delim="\n"):
1148-
m = re.search("%s\s*:\s+(.+?)%s" % (field, delim), info)
1148+
m = re.search(r"%s\s*:\s+(.+?)%s" % (field, delim), info)
11491149
if m:
11501150
return m.group(1)
11511151
else:
@@ -1175,7 +1175,7 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None):
11751175
outputs.ph_enc_dir = self.info_regexp(info, "PhEncDir")
11761176

11771177
# File format and datatype are both keyed by "type"
1178-
ftype, dtype = re.findall("%s\s*:\s+(.+?)\n" % "type", info)
1178+
ftype, dtype = re.findall(r"%s\s*:\s+(.+?)\n" % "type", info)
11791179
outputs.file_format = ftype
11801180
outputs.data_type = dtype
11811181

nipype/interfaces/spm/model.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -474,15 +474,16 @@ def _make_matlab_command(self, _):
474474
script += "condnames=names;\n"
475475
else:
476476
if self.inputs.use_derivs:
477-
script += "pat = 'Sn\([0-9]*\) (.*)';\n"
477+
script += r"pat = 'Sn\([0-9]*\) (.*)';" "\n"
478478
else:
479479
script += (
480-
"pat = 'Sn\([0-9]*\) (.*)\*bf\(1\)|Sn\([0-9]*\) "
481-
".*\*bf\([2-9]\)|Sn\([0-9]*\) (.*)';\n"
480+
r"pat = 'Sn\([0-9]*\) (.*)\*bf\(1\)|Sn\([0-9]*\) "
481+
r".*\*bf\([2-9]\)|Sn\([0-9]*\) (.*)';"
482+
"\n"
482483
)
483484
script += "t = regexp(names,pat,'tokens');\n"
484485
# get sessidx for columns
485-
script += "pat1 = 'Sn\(([0-9].*)\)\s.*';\n"
486+
script += r"pat1 = 'Sn\(([0-9].*)\)\s.*';" "\n"
486487
script += "t1 = regexp(names,pat1,'tokens');\n"
487488
script += (
488489
"for i0=1:numel(t),condnames{i0}='';condsess(i0)=0;if "

nipype/pipeline/plugins/tests/test_tools.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ def test_report_crash():
2121
mock_node = mock.MagicMock(name="mock_node")
2222
mock_node._id = "an_id"
2323
mock_node.config = {
24-
"execution": {"crashdump_dir": ".", "crashfile_format": "pklz",}
24+
"execution": {"crashdump_dir": ".", "crashfile_format": "pklz"}
2525
}
2626

2727
actual_crashfile = report_crash(mock_node)
2828

29-
expected_crashfile = re.compile(".*/crash-.*-an_id-[0-9a-f\-]*.pklz")
29+
expected_crashfile = re.compile(r".*/crash-.*-an_id-[0-9a-f\-]*.pklz")
3030

3131
assert (
3232
expected_crashfile.match(actual_crashfile).group() == actual_crashfile

nipype/sphinxext/plot_workflow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def remove_coding(text):
314314
"""
315315
Remove the coding comment, which exec doesn't like.
316316
"""
317-
sub_re = re.compile("^#\s*-\*-\s*coding:\s*.*-\*-$", flags=re.MULTILINE)
317+
sub_re = re.compile(r"^#\s*-\*-\s*coding:\s*.*-\*-$", flags=re.MULTILINE)
318318
return sub_re.sub("", text)
319319

320320

0 commit comments

Comments
 (0)