Skip to content

Commit 7cd42b3

Browse files
author
Ben Cipollini
committed
RF: json => simplejson
1 parent 2d64a6d commit 7cd42b3

File tree

8 files changed

+32
-23
lines changed

8 files changed

+32
-23
lines changed

nipype/interfaces/fsl/tests/test_maths.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@
1414
from nipype.interfaces.base import Undefined
1515
import nipype.interfaces.fsl.maths as fsl
1616
from nipype.interfaces.fsl import no_fsl, Info
17+
from nipype.interfaces.fsl.base import FSLCommand
1718

1819

19-
def set_output_type(fsl_output_type=None):
20+
def set_output_type(fsl_output_type):
2021
prev_output_type = os.environ.get('FSLOUTPUTTYPE', None)
22+
2123
if fsl_output_type is not None:
2224
os.environ['FSLOUTPUTTYPE'] = fsl_output_type
25+
elif 'FSLOUTPUTTYPE' in os.environ:
26+
del os.environ['FSLOUTPUTTYPE']
27+
28+
FSLCommand.set_default_output_type(Info.output_type())
29+
2330
return prev_output_type
2431

2532
def create_files_in_directory():
@@ -500,7 +507,7 @@ def test_tempfilt(fsl_output_type=None):
500507

501508
@skipif(no_fsl)
502509
def test_all_again():
503-
# Rerun tests with all file types
510+
# Rerun tests with all output file types
504511
all_func = [test_binarymaths, test_changedt, test_dilation, test_erosion,
505512
test_mask, test_maximage, test_meanimage, test_multimaths,
506513
test_smooth, test_tempfilt, test_threshold, test_unarymaths]

nipype/interfaces/io.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from builtins import zip
2121
from builtins import filter
2222
from builtins import range
23+
2324
import glob
2425
import fnmatch
2526
import string
@@ -2158,7 +2159,7 @@ class JSONFileGrabber(IOBase):
21582159
>>> jsonSource.inputs.in_file = 'jsongrabber.txt'
21592160
>>> res = jsonSource.run()
21602161
>>> pprint.pprint(res.outputs.get()) # doctest: +NORMALIZE_WHITESPACE
2161-
{'param1': u'exampleStr', 'param2': 4, 'param3': 1.0}
2162+
{'param1': 'exampleStr', 'param2': 4, 'param3': 1.0}
21622163
21632164
21642165
"""
@@ -2167,12 +2168,12 @@ class JSONFileGrabber(IOBase):
21672168
_always_run = True
21682169

21692170
def _list_outputs(self):
2170-
import json
2171+
import simplejson
21712172

21722173
outputs = {}
21732174
if isdefined(self.inputs.in_file):
21742175
with open(self.inputs.in_file, 'r') as f:
2175-
data = json.load(f)
2176+
data = simplejson.load(f)
21762177

21772178
if not isinstance(data, dict):
21782179
raise RuntimeError('JSON input has no dictionary structure')
@@ -2269,7 +2270,7 @@ def _process_name(self, name, val):
22692270
return name, val
22702271

22712272
def _list_outputs(self):
2272-
import json
2273+
import simplejson
22732274
import os.path as op
22742275

22752276
if not isdefined(self.inputs.out_file):
@@ -2287,7 +2288,7 @@ def _list_outputs(self):
22872288
out_dict[key] = val
22882289

22892290
with open(out_file, 'w') as f:
2290-
json.dump(out_dict, f)
2291+
simplejson.dump(out_dict, f)
22912292
outputs = self.output_spec().get()
22922293
outputs['out_file'] = out_file
22932294
return outputs

nipype/interfaces/tests/test_io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def test_freesurfersource():
373373

374374

375375
def test_jsonsink():
376-
import json
376+
import simplejson
377377
import os
378378

379379
ds = nio.JSONFileSink()
@@ -392,7 +392,7 @@ def test_jsonsink():
392392
res = js.run()
393393

394394
with open(res.outputs.out_file, 'r') as f:
395-
data = json.load(f)
395+
data = simplejson.load(f)
396396
yield assert_true, data == {"contrasts": {"alt": "someNestedValue"}, "foo": "var", "new_entry": "someValue"}
397397

398398
js = nio.JSONFileSink(infields=['test'], in_dict={'foo': 'var'})
@@ -402,7 +402,7 @@ def test_jsonsink():
402402
res = js.run()
403403

404404
with open(res.outputs.out_file, 'r') as f:
405-
data = json.load(f)
405+
data = simplejson.load(f)
406406
yield assert_true, data == {"test": "testInfields", "contrasts": {"alt": "someNestedValue"}, "foo": "var", "new_entry": "someValue"}
407407

408408
os.chdir(curdir)

nipype/utils/filemanip.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import gzip
1111
import hashlib
1212
from hashlib import md5
13-
import json
13+
import simplejson
1414
import os
1515
import re
1616
import shutil
@@ -382,7 +382,7 @@ def save_json(filename, data):
382382
"""
383383

384384
with open(filename, 'w') as fp:
385-
json.dump(data, fp, sort_keys=True, indent=4)
385+
simplejson.dump(data, fp, sort_keys=True, indent=4)
386386

387387

388388
def load_json(filename):
@@ -400,7 +400,7 @@ def load_json(filename):
400400
"""
401401

402402
with open (filename, 'r') as fp:
403-
data = json.load(fp)
403+
data = simplejson.load(fp)
404404
return data
405405

406406
def loadcrash(infile, *args):

nipype/utils/nipype2boutiques.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import argparse
1616
import inspect
1717
import sys
18-
import json
18+
import simplejson
1919
import tempfile
2020

2121
from nipype.interfaces.base import Interface
@@ -106,7 +106,7 @@ def generate_boutiques_descriptor(module, interface_name, ignored_template_input
106106
for input in tool_desc['inputs']:
107107
del input['tempvalue']
108108

109-
return json.dumps(tool_desc, indent=4, separators=(',', ': '))
109+
return simplejson.dumps(tool_desc, indent=4, separators=(',', ': '))
110110

111111
def get_boutiques_input(inputs,interface,input_name,spec,ignored_template_inputs,verbose,ignore_template_numbers):
112112
"""

nipype/utils/provenance.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from builtins import object
44

55
from pickle import dumps
6-
import json
6+
import simplejson
77
import os
88
import getpass
99
from socket import getfqdn
@@ -156,8 +156,8 @@ def safe_encode(x, as_literal=True):
156156
else:
157157
outdict[key] = encoded_value
158158
if not as_literal:
159-
return json.dumps(outdict)
160-
return pm.Literal(json.dumps(outdict), pm.XSD['string'])
159+
return simplejson.dumps(outdict)
160+
return pm.Literal(simplejson.dumps(outdict), pm.XSD['string'])
161161
if isinstance(x, list):
162162
try:
163163
nptype = np.array(x).dtype
@@ -174,8 +174,8 @@ def safe_encode(x, as_literal=True):
174174
else:
175175
outlist = x
176176
if not as_literal:
177-
return json.dumps(outlist)
178-
return pm.Literal(json.dumps(outlist), pm.XSD['string'])
177+
return simplejson.dumps(outlist)
178+
return pm.Literal(simplejson.dumps(outlist), pm.XSD['string'])
179179
if not as_literal:
180180
return dumps(x)
181181
return pm.Literal(dumps(x), nipype_ns['pickle'])
@@ -393,5 +393,5 @@ def write_provenance(self, filename='provenance', format='turtle'):
393393
fp.writelines(self.g.get_provn())
394394
if format in ['json', 'all']:
395395
with open(filename + '.json', 'wt') as fp:
396-
pm.json.dump(self.g, fp, cls=pm.ProvBundle.JSONEncoder)
396+
pm.simplejson.dump(self.g, fp, cls=pm.ProvBundle.JSONEncoder)
397397
return self.g

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ python-dateutil>=1.5
66
nibabel>=2.0.1
77
nose>=1.2
88
future==0.15.2
9+
simplejson

tools/github.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
standard_library.install_aliases()
33
import http.client
44
import inspect
5-
import json
5+
import simplejson
66
import os
77
from subprocess import Popen, PIPE
88

@@ -58,7 +58,7 @@ def create_hash_map():
5858
r1 = conn.getresponse()
5959
if r1.reason != 'OK':
6060
raise Exception('HTTP Response %s:%s' % (r1.status, r1.reason))
61-
payload = json.loads(r1.read())
61+
payload = simplejson.loads(r1.read())
6262
for infodict in payload['tree']:
6363
if infodict['type'] == "blob":
6464
hashmap[infodict['sha']] = infodict['path']

0 commit comments

Comments
 (0)