Commit 0db0873f authored by André Anjos's avatar André Anjos 💬

Merge branch '73_factorize_simplejson' into 'master'

Factorize simplejson

See merge request !64
parents 04484221 2163c39b
Pipeline #28272 passed with stages
in 16 minutes and 49 seconds
......@@ -44,7 +44,7 @@ Docker helper classes
import os
import simplejson
import simplejson as json
import socket
import tempfile
import time
......@@ -78,7 +78,7 @@ class Host(object):
self.images_cache_filename
):
with open(self.images_cache_filename, "r") as f:
Host.images_cache = simplejson.load(f)
Host.images_cache = json.load(f)
# Discover the environments
if discover:
......@@ -90,7 +90,7 @@ class Host(object):
# (If necessary) Save the known infos about the images
if self.images_cache_filename is not None:
with open(self.images_cache_filename, "w") as f:
simplejson.dump(Host.images_cache, f, indent=4)
json.dump(Host.images_cache, f, indent=4)
def __contains__(self, key):
return (key in self.processing_environments) or (key in self.db_environments)
......@@ -180,7 +180,7 @@ class Host(object):
if status == 0:
try:
infos = simplejson.loads(stdout)
infos = json.loads(stdout)
Host.images_cache[image] = infos
return infos
except Exception as e:
......@@ -492,7 +492,7 @@ class Host(object):
return None
try:
return simplejson.loads(stdout)[0]["State"]["Status"]
return json.loads(stdout)[0]["State"]["Status"]
except Exception:
return None
......
......@@ -47,7 +47,7 @@ import os
import glob
import collections
import logging
import simplejson
import simplejson as json
from .. import schema
from .. import database
......@@ -417,7 +417,7 @@ class BaseExecutor(object):
return stats.io_statistics(self.data, self.input_list, self.output_list)
def __str__(self):
return simplejson.dumps(self.data, indent=4)
return json.dumps(self.data, indent=4)
def write(self, path):
"""Writes contents to precise filesystem location"""
......@@ -431,7 +431,7 @@ class BaseExecutor(object):
data = convert_experiment_configuration_to_container(self.data)
with open(os.path.join(directory, "configuration.json"), "wb") as f:
json_data = simplejson.dumps(data, indent=2)
json_data = json.dumps(data, indent=2)
f.write(json_data.encode("utf-8"))
tmp_prefix = os.path.join(directory, "prefix")
......@@ -447,7 +447,7 @@ class BaseExecutor(object):
"""Exports contents useful for a backend runner to run the algorithm"""
with open(os.path.join(directory, "configuration.json"), "wb") as f:
json_data = simplejson.dumps(self.data, indent=2)
json_data = json.dumps(self.data, indent=2)
f.write(json_data.encode("utf-8"))
tmp_prefix = os.path.join(directory, "prefix")
......
......@@ -46,7 +46,7 @@ import os
import shutil
import logging
import requests
import simplejson
import simplejson as json
from beat.backend.python.execution import MessageHandler
......@@ -190,13 +190,13 @@ class DockerExecutor(RemoteExecutor):
json_path = os.path.join(root_folder, db_name + ".json")
with open(json_path, "r") as f:
db_data = simplejson.load(f)
db_data = json.load(f)
database_paths[db_name] = db_data["root_folder"]
db_data["root_folder"] = os.path.join("/databases", db_name)
with open(json_path, "w") as f:
simplejson.dump(db_data, f, indent=4)
json.dump(db_data, f, indent=4)
# Determine the docker image to use for the databases
try:
......
......@@ -44,7 +44,7 @@ Validation for experiments
import os
import collections
import simplejson
import simplejson as json
from . import utils
from . import algorithm
......@@ -1306,7 +1306,7 @@ class Experiment(object):
str: The JSON representation for this object
"""
return simplejson.dumps(self.data, indent=indent, cls=utils.NumpyJSONEncoder)
return json.dumps(self.data, indent=indent, cls=utils.NumpyJSONEncoder)
def __str__(self):
......
......@@ -46,7 +46,7 @@ Also forward importing from :py:mod:`beat.backend.python.hash`
import collections
import simplejson
import simplejson as json
from beat.backend.python.hash import * # noqa
from beat.backend.python.hash import _sha256 # noqa
......@@ -165,9 +165,8 @@ def hashJSONStr(contents, description):
try:
return hashJSON( # noqa
simplejson.loads(contents, object_pairs_hook=collections.OrderedDict),
description,
json.loads(contents, object_pairs_hook=collections.OrderedDict), description
) # preserve order
except simplejson.JSONDecodeError:
except json.JSONDecodeError:
# falls back to normal file content hashing
return hash(contents)
......@@ -41,7 +41,7 @@ import collections
import pkg_resources
import six
import simplejson
import simplejson as json
import jsonschema
......@@ -55,7 +55,7 @@ def maybe_load_json(s):
with open(s, "rt") as f:
return maybe_load_json(f)
else:
return simplejson.loads(s, object_pairs_hook=collections.OrderedDict)
return json.loads(s, object_pairs_hook=collections.OrderedDict)
# if it is a 'file-like' object
if hasattr(s, "read"):
......@@ -94,7 +94,7 @@ def load_schema(schema_name, version=1):
with open(fname, "rb") as f:
data = f.read().decode()
schema = simplejson.loads(data)
schema = json.loads(data)
basedir = os.path.realpath(os.path.dirname(fname))
resolver = jsonschema.RefResolver("file://" + basedir + "/", schema)
......@@ -118,7 +118,7 @@ def validate(schema_name, data):
try:
cleaned_data, error_list = validate('toolchain', '/to/my/file.json')
except simplejson.JSONDecodeError as e:
except json.JSONDecodeError as e:
print(e)
......@@ -133,12 +133,12 @@ def validate(schema_name, data):
If ``data`` is a string and represents a valid filesystem path, the
relevant file will be opened and read as with
:py:func:`simplejson.load``. Otherwise, it will be considered to be
:py:func:`json.load``. Otherwise, it will be considered to be
string containing a valid JSON structure that will be loaded as with
:py:func:`simplejson.loads`.
:py:func:`json.loads`.
Note that if the file is opened and read internally using
:py:func:`simplejson.load`, exceptions may be thrown by that subsystem,
:py:func:`json.load`, exceptions may be thrown by that subsystem,
concerning the file structure. Consult the manual page for
:py:mod:`simplejson` for details.
......@@ -157,7 +157,7 @@ def validate(schema_name, data):
try:
data = maybe_load_json(data)
except simplejson.JSONDecodeError as e:
except json.JSONDecodeError as e:
return data, ["invalid JSON code: %s" % str(e)]
# handles the schema version
......
......@@ -62,7 +62,7 @@ import sys
import logging
import zmq
import signal
import simplejson
import simplejson as json
import multiprocessing
import six
......@@ -334,7 +334,7 @@ def main(user_input=None):
execution_process.join()
if "result" in result:
content = simplejson.dumps(result["result"])
content = json.dumps(result["result"])
status = WorkerController.DONE
if result["result"]["status"] != 0:
......@@ -383,7 +383,7 @@ def main(user_input=None):
# Command: execute <job-id> <json-command>
if command == WorkerController.EXECUTE:
job_id = parts[1]
data = simplejson.loads(parts[2])
data = json.loads(parts[2])
if args["--docker"]:
if docker_network_name:
data["network_name"] = docker_network_name
......
......@@ -50,7 +50,7 @@ Forward impored from :py:mod:`beat.backend.python.stats`:
import os
import copy
import simplejson
import simplejson as json
from . import schema
from . import prototypes
......@@ -224,7 +224,7 @@ class Statistics(object):
dict: JSON representation
"""
return simplejson.dumps(self._data, indent=indent)
return json.dumps(self._data, indent=indent)
def as_dict(self):
"""Returns self as a dictionary"""
......
......@@ -40,7 +40,7 @@ import os
import sys
import logging
import unittest
import simplejson
import simplejson as json
import tempfile
import shutil
import zmq
......@@ -128,7 +128,7 @@ class TestDatabasesProvider(unittest.TestCase):
def start_databases_provider(self, configuration):
with open(os.path.join(self.working_dir, "configuration.json"), "wb") as f:
data = simplejson.dumps(configuration, indent=4)
data = json.dumps(configuration, indent=4)
f.write(data.encode("utf-8"))
working_prefix = os.path.join(self.working_dir, "prefix")
......
......@@ -39,7 +39,7 @@
import os
import logging
import unittest
import simplejson
import simplejson as json
import multiprocessing
import queue
......@@ -394,7 +394,7 @@ class TestOneWorker(TestWorkerBase):
self.assertEqual(status, WorkerController.DONE)
self.assertEqual(job_id, expected_job_id)
result = simplejson.loads(data[0])
result = json.loads(data[0])
self.assertEqual(result["status"], 0)
......@@ -419,7 +419,7 @@ class TestOneWorker(TestWorkerBase):
self.assertEqual(status, WorkerController.JOB_ERROR)
self.assertEqual(job_id, 1)
result = simplejson.loads(data[0])
result = json.loads(data[0])
self.assertEqual(result["status"], 1)
self.assertTrue("a = b" in result["user_error"])
......@@ -534,7 +534,7 @@ class TestTwoWorkers(TestWorkerBase):
self.assertEqual(status, WorkerController.DONE)
self.assertEqual(job_id, 1)
result = simplejson.loads(data[0])
result = json.loads(data[0])
self.assertEqual(result["status"], 0)
......@@ -554,7 +554,7 @@ class TestTwoWorkers(TestWorkerBase):
self.assertEqual(worker, WORKER2)
self.assertEqual(job_id, 2)
result = simplejson.loads(data[0])
result = json.loads(data[0])
self.assertEqual(result["status"], 0)
self.controller.execute(WORKER1, 1, CONFIGURATION1)
......
......@@ -44,7 +44,7 @@ Validation for toolchains
import collections
import simplejson
import simplejson as json
from . import schema
from . import prototypes
......@@ -716,7 +716,7 @@ class Toolchain(object):
str: The JSON representation for this object
"""
return simplejson.dumps(self.data, indent=indent, cls=utils.NumpyJSONEncoder)
return json.dumps(self.data, indent=indent, cls=utils.NumpyJSONEncoder)
def __str__(self):
......
......@@ -46,7 +46,7 @@ import logging
import zmq
import socket
import simplejson
import simplejson as json
from .utils import send_multipart
......@@ -151,7 +151,7 @@ class WorkerController(object):
worker,
WorkerController.EXECUTE,
b"%d" % job_id,
simplejson.dumps(configuration),
json.dumps(configuration),
]
send_multipart(self.socket, parts)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment