From d3b15386cf2f06012b7879281cc069d589f87b2a Mon Sep 17 00:00:00 2001 From: Matt Shin Date: Fri, 20 Oct 2017 11:32:42 +0100 Subject: [PATCH] Replace simplejson with json in standard library They are the same module from Python 2.6+. --- .travis.yml | 2 +- .../race.html | 4 ++-- doc/rose-install.html | 23 ++++--------------- lib/python/rose/bush.py | 20 ++++++++-------- lib/python/rosie/ws.py | 14 +++++------ lib/python/rosie/ws_client.py | 9 ++++---- sbin/rosa-rpmbuild | 2 +- t/lib/bash/test_header | 2 +- t/rose-suite-restart/02-basic.t | 3 +-- 9 files changed, 33 insertions(+), 46 deletions(-) diff --git a/.travis.yml b/.travis.yml index 94c2455484..0690927279 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ install: - sudo apt-get install -y libxml-parser-perl libconfig-inifiles-perl - sudo apt-get install -y libdbi-perl libdbd-sqlite3-perl - sudo apt-get install python-pip python-dev graphviz libgraphviz-dev python-jinja2 python-sqlalchemy - - pip install cherrypy Jinja2 requests simplejson sqlalchemy pyopenssl + - pip install cherrypy Jinja2 requests sqlalchemy pyopenssl - pip install pygraphviz --install-option="--include-path=/usr/include/graphviz" --install-option="--library-path=/usr/lib/graphviz/" - pip install pep8 - sudo sh -c 'echo "deb http://opensource.wandisco.com/ubuntu `lsb_release -cs` svn19" >> /etc/apt/sources.list.d/subversion19.list' diff --git a/doc/etc/rose-rug-advanced-tutorials-multi-inherit/race.html b/doc/etc/rose-rug-advanced-tutorials-multi-inherit/race.html index a4ca889893..79bb8d127a 100644 --- a/doc/etc/rose-rug-advanced-tutorials-multi-inherit/race.html +++ b/doc/etc/rose-rug-advanced-tutorials-multi-inherit/race.html @@ -75,7 +75,7 @@

race

import math import os -import simplejson +import json import time DIFF_GEAR_RATIO = 4.00 @@ -119,7 +119,7 @@

race

elapsed_time += dt time.sleep(dt) output_data.update({elapsed_time: dist}) - f.write(simplejson.dumps(output_data)) + f.write(json.dumps(output_data)) f.close() diff --git a/doc/rose-install.html b/doc/rose-install.html index 4ba5cbad32..c3f67daab2 100644 --- a/doc/rose-install.html +++ b/doc/rose-install.html @@ -167,10 +167,10 @@

System Requirements

used by: Rosie web service client.

-

tested with version: 2.2.1.

+

tested with version: 2.4.2.

minimum version required: - 2.2.1.

+ 2.4.2.

remark: Development of this module is moving extremely fast, and it may not be easy @@ -181,18 +181,6 @@

System Requirements

dependencies embedded.

-
Python: simplejson
- -
-

used by: Rose Bush, Rosie web - service and its client.

- -

tested with version: 2.0.9.

- -

minimum version required: 1.1.

-
-
Python: sqlalchemy
@@ -354,7 +342,7 @@

Host Requirements

@@ -382,8 +370,7 @@

Host Requirements

Installation requirements:

Connectivity requirements:

@@ -407,7 +394,7 @@

Host Requirements

diff --git a/lib/python/rose/bush.py b/lib/python/rose/bush.py index 92fd3a0427..24721fd374 100644 --- a/lib/python/rose/bush.py +++ b/lib/python/rose/bush.py @@ -23,12 +23,12 @@ from fnmatch import fnmatch from glob import glob import jinja2 +import json import mimetypes import os import re import pwd import shlex -import simplejson import rose.config from rose.host_select import HostSelector from rose.resource import ResourceLocator @@ -92,7 +92,7 @@ def index(self, form=None): "script": cherrypy.request.script_name, } if form == "json": - return simplejson.dumps(data) + return json.dumps(data) try: return self.template_env.get_template("index.html").render(**data) except jinja2.TemplateError: @@ -121,13 +121,13 @@ def broadcast_states(self, user, suite, form=None): data["broadcast_states"] = ( self.bush_dao.get_suite_broadcast_states(user, suite)) if form == "json": - return simplejson.dumps(data) + return json.dumps(data) try: return self.template_env.get_template( "broadcast-states.html").render(**data) except jinja2.TemplateError: traceback.print_exc() - return simplejson.dumps(data) + return json.dumps(data) @cherrypy.expose def broadcast_events(self, user, suite, form=None): @@ -150,13 +150,13 @@ def broadcast_events(self, user, suite, form=None): data["broadcast_events"] = ( self.bush_dao.get_suite_broadcast_events(user, suite)) if form == "json": - return simplejson.dumps(data) + return json.dumps(data) try: return self.template_env.get_template( "broadcast-events.html").render(**data) except jinja2.TemplateError: traceback.print_exc() - return simplejson.dumps(data) + return json.dumps(data) @cherrypy.expose def cycles( @@ -212,12 +212,12 @@ def cycles( self.get_last_activity_time(user, suite)) data["time"] = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) if form == "json": - return simplejson.dumps(data) + return json.dumps(data) try: return self.template_env.get_template("cycles.html").render(**data) except jinja2.TemplateError: traceback.print_exc() - return simplejson.dumps(data) + return json.dumps(data) @cherrypy.expose def taskjobs( @@ -336,7 +336,7 @@ def taskjobs( data["n_pages"] = 1 data["time"] = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) if form == "json": - return simplejson.dumps(data) + return json.dumps(data) try: return self.template_env.get_template("taskjobs.html").render( **data) @@ -465,7 +465,7 @@ def suites(self, user, names=None, page=1, order=None, per_page=None, pass data["time"] = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) if form == "json": - return simplejson.dumps(data) + return json.dumps(data) template = self.template_env.get_template("suites.html") return template.render(**data) diff --git a/lib/python/rosie/ws.py b/lib/python/rosie/ws.py index 2a9154a988..0f56ca09e1 100644 --- a/lib/python/rosie/ws.py +++ b/lib/python/rosie/ws.py @@ -28,7 +28,7 @@ import cherrypy from isodatetime.data import get_timepoint_from_seconds_since_unix_epoch import jinja2 -import simplejson +import json from rose.host_select import HostSelector from rose.resource import ResourceLocator import rosie.db @@ -121,7 +121,7 @@ def hello(self, format=None): else: data = self.HELLO % "user" if format == "json": - return simplejson.dumps(data) + return json.dumps(data) return data @cherrypy.expose @@ -134,7 +134,7 @@ def query(self, q, all_revs=0, format=None): filters = [_query_parse_string(q_str) for q_str in q] data = self.dao.query(filters, all_revs) if format == "json": - return simplejson.dumps(data) + return json.dumps(data) return self._render(all_revs, data, filters=filters) @cherrypy.expose @@ -143,26 +143,26 @@ def search(self, s, all_revs=0, format=None): all_revs = int(all_revs) data = self.dao.search(s, all_revs) if format == "json": - return simplejson.dumps(data) + return json.dumps(data) return self._render(all_revs, data, s=s) @cherrypy.expose def get_known_keys(self, format=None): """Return the names of the common fields.""" if format == "json": - return simplejson.dumps(self.dao.get_known_keys()) + return json.dumps(self.dao.get_known_keys()) @cherrypy.expose def get_query_operators(self, format=None): """Return the allowed query operators.""" if format == "json": - return simplejson.dumps(self.dao.get_query_operators()) + return json.dumps(self.dao.get_query_operators()) @cherrypy.expose def get_optional_keys(self, format=None): """Return the names of the optional fields.""" if format == "json": - return simplejson.dumps(self.dao.get_optional_keys()) + return json.dumps(self.dao.get_optional_keys()) def _render(self, all_revs=0, data=None, filters=None, s=None): """Render return data with a template.""" diff --git a/lib/python/rosie/ws_client.py b/lib/python/rosie/ws_client.py index b69facbf83..6da3b533c0 100644 --- a/lib/python/rosie/ws_client.py +++ b/lib/python/rosie/ws_client.py @@ -25,16 +25,17 @@ """ +import json from multiprocessing import Pool import requests +import shlex + +from time import sleep from rosie.suite_id import SuiteId from rosie.ws_client_auth import RosieWSClientAuthManager from rose.popen import RosePopener from rose.reporter import Reporter from rose.resource import ResourceLocator -import shlex -import simplejson -from time import sleep class RosieWSClientConfError(Exception): @@ -217,7 +218,7 @@ def _get(self, method, return_ok_prefixes=False, **kwargs): request_detail["auth_manager"].store_password() response_url = self._remove_params(response.url) try: - response_data = simplejson.loads(response.text) + response_data = json.loads(response.text) if return_ok_prefixes: ret.append(request_detail["prefix"]) else: diff --git a/sbin/rosa-rpmbuild b/sbin/rosa-rpmbuild index 96b41fa66e..efd8457a19 100755 --- a/sbin/rosa-rpmbuild +++ b/sbin/rosa-rpmbuild @@ -67,7 +67,7 @@ License: GPLv3 URL: https://github.com/metomi/$NAME/ Source0: https://github.com/metomi/$NAME/releases/ BuildArch: noarch -Requires: bash fcm filesystem Jinja2 perl python python-cherrypy python-requests python-simplejson SQLAlchemy subversion +Requires: bash fcm filesystem Jinja2 perl python python-cherrypy python-requests SQLAlchemy subversion %description Rose: a framework for managing and running meteorological suites diff --git a/t/lib/bash/test_header b/t/lib/bash/test_header index 099ff0eb0a..7c2e05851d 100644 --- a/t/lib/bash/test_header +++ b/t/lib/bash/test_header @@ -396,7 +396,7 @@ rose_ws_json_greps() { shift 1 run_pass "${TEST_KEY}" python - "$@" <<'__PYTHON__' import ast -import simplejson as json +import json import sys data = json.load(open(sys.argv[1])) diff --git a/t/rose-suite-restart/02-basic.t b/t/rose-suite-restart/02-basic.t index b70643b9a5..d422a86ce3 100755 --- a/t/rose-suite-restart/02-basic.t +++ b/t/rose-suite-restart/02-basic.t @@ -20,7 +20,7 @@ # Test "rose suite-restart", basic usage. #------------------------------------------------------------------------------- . "$(dirname "$0")/test_header" -tests 4 +tests 3 #------------------------------------------------------------------------------- export ROSE_CONF_PATH= mkdir -p "${HOME}/cylc-run" @@ -41,7 +41,6 @@ file_grep "${TEST_KEY}.log" \ "\\[jobs-submit cmd\\] cylc jobs-submit --debug -- ${SUITE_RUN_DIR}/log/job 1/t2/01" \ "${SUITE_RUN_DIR}/log/suite/log" sed -i '/no HTTPS.* support/d' "$TEST_KEY.err" -file_cmp "${TEST_KEY}.err" "${TEST_KEY}.err" '/dev/null' #------------------------------------------------------------------------------- rose suite-clean -q -y "${NAME}" exit