66897f6
From 58347d9a569c4610b450161b575639e4403b8f8c Mon Sep 17 00:00:00 2001
0b1db49
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
0b1db49
Date: Thu, 25 Oct 2018 19:19:06 -0400
e0a9db8
Subject: [PATCH 2/5] Unbundle JSON-minify.
0b1db49
0b1db49
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
0b1db49
---
0b1db49
 asv/extern/minify_json.py | 128 --------------------------------------
0b1db49
 asv/util.py               |   5 +-
0b1db49
 pip_requirements.txt      |   1 +
0b1db49
 setup.py                  |   3 +-
0b1db49
 4 files changed, 5 insertions(+), 132 deletions(-)
0b1db49
 delete mode 100644 asv/extern/minify_json.py
0b1db49
0b1db49
diff --git a/asv/extern/minify_json.py b/asv/extern/minify_json.py
0b1db49
deleted file mode 100644
0b1db49
index ca87488..0000000
0b1db49
--- a/asv/extern/minify_json.py
0b1db49
+++ /dev/null
0b1db49
@@ -1,128 +0,0 @@
0b1db49
-'''
0b1db49
-Created on 20/01/2011
0b1db49
-
0b1db49
-v0.2 (C) Gerald Storer
0b1db49
-MIT License
0b1db49
-
0b1db49
-Based on JSON.minify.js:
0b1db49
-https://github.com/getify/JSON.minify
0b1db49
-
0b1db49
-Contributers:
0b1db49
- - Pradyun S. Gedam (conditions and variable names changed)
0b1db49
-'''
0b1db49
-
0b1db49
-
0b1db49
-import re
0b1db49
-
0b1db49
-def json_minify(string, strip_space=True):
0b1db49
-    tokenizer = re.compile(r'"|(/\*)|(\*/)|(//)|\n|\r')
0b1db49
-    in_string = False
0b1db49
-    in_multi = False
0b1db49
-    in_single = False
0b1db49
-
0b1db49
-    new_str = []
0b1db49
-    index = 0
0b1db49
-
0b1db49
-    for match in re.finditer(tokenizer, string):
0b1db49
-
0b1db49
-        if not (in_multi or in_single):
0b1db49
-            tmp = string[index:match.start()]
0b1db49
-            if not in_string and strip_space:
0b1db49
-                # replace white space as defined in standard
0b1db49
-                tmp = re.sub('[ \t\n\r]+', '', tmp)
0b1db49
-            new_str.append(tmp)
0b1db49
-
0b1db49
-        index = match.end()
0b1db49
-        val = match.group()
0b1db49
-
0b1db49
-        if val == '"' and not (in_multi or in_single):
0b1db49
-            escaped = re.search(r'(\\)*$', string[:match.start()])
0b1db49
-
0b1db49
-            # start of string or unescaped quote character to end string
0b1db49
-            if not in_string or (escaped is None or len(escaped.group()) % 2 == 0):
0b1db49
-                in_string = not in_string
0b1db49
-            index -= 1 # include " character in next catch
0b1db49
-        elif not (in_string or in_multi or in_single):
0b1db49
-            if val == '/*':
0b1db49
-                in_multi = True
0b1db49
-            elif val == '//':
0b1db49
-                in_single = True
0b1db49
-        elif val == '*/' and in_multi and not (in_string or in_single):
0b1db49
-            in_multi = False
0b1db49
-        elif val in '\r\n' and not (in_multi or in_string) and in_single:
0b1db49
-            in_single = False
0b1db49
-        elif not ((in_multi or in_single) or (val in ' \r\n\t' and strip_space)):
0b1db49
-            new_str.append(val)
0b1db49
-
0b1db49
-    new_str.append(string[index:])
0b1db49
-    return ''.join(new_str)
0b1db49
-
0b1db49
-
0b1db49
-if __name__ == '__main__':
0b1db49
-    # Python 2.6+ needed to run tests
0b1db49
-    import json
0b1db49
-    import textwrap
0b1db49
-    import unittest
0b1db49
-
0b1db49
-    class JsonMinifyTestCase(unittest.TestCase):
0b1db49
-        """Tests for json_minify"""
0b1db49
-        def template(self, in_string, expected):
0b1db49
-            in_dict = json.loads(json_minify(in_string))
0b1db49
-            expected_dict = json.loads(expected)
0b1db49
-            self.assertEqual(in_dict, expected_dict)
0b1db49
-
0b1db49
-        def test_1(self):
0b1db49
-            self.template(textwrap.dedent('''
0b1db49
-                // this is a JSON file with comments
0b1db49
-                {
0b1db49
-                    "foo": "bar",    // this is cool
0b1db49
-                    "bar": [
0b1db49
-                        "baz", "bum"
0b1db49
-                    ],
0b1db49
-                /* the rest of this document is just fluff
0b1db49
-                   in case you are interested. */
0b1db49
-                    "something": 10,
0b1db49
-                    "else": 20
0b1db49
-                }
0b1db49
-
0b1db49
-                /* NOTE: You can easily strip the whitespace and comments
0b1db49
-                   from such a file with the JSON.minify() project hosted
0b1db49
-                   here on github at http://github.com/getify/JSON.minify
0b1db49
-                */'''),
0b1db49
-                '{"foo":"bar","bar":["baz","bum"],"something":10,"else":20}'
0b1db49
-            )
0b1db49
-
0b1db49
-        def test_2(self):
0b1db49
-            self.template(textwrap.dedent('''
0b1db49
-                {"/*":"*/","//":"",/*"//"*/"/*/"://
0b1db49
-                "//"}'''),
0b1db49
-                '{"/*":"*/","//":"","/*/":"//"}'
0b1db49
-            )
0b1db49
-
0b1db49
-        def test_3(self):
0b1db49
-            self.template(textwrap.dedent(r'''
0b1db49
-                /*
0b1db49
-                this is a
0b1db49
-                multi line comment */{
0b1db49
-
0b1db49
-                "foo"
0b1db49
-                :
0b1db49
-                    "bar/*"// something
0b1db49
-                    ,    "b\"az":/*
0b1db49
-                something else */"blah"
0b1db49
-
0b1db49
-                }
0b1db49
-                '''),
0b1db49
-                r'{"foo":"bar/*","b\"az":"blah"}'
0b1db49
-            )
0b1db49
-
0b1db49
-        def test_4(self):
0b1db49
-            self.template(textwrap.dedent(r'''
0b1db49
-                {"foo": "ba\"r//", "bar\\": "b\\\"a/*z",
0b1db49
-                "baz\\\\": /* yay */ "fo\\\\\"*/o"
0b1db49
-                }
0b1db49
-                '''),
0b1db49
-                r'{"foo":"ba\"r//","bar\\":"b\\\"a/*z","baz\\\\":"fo\\\\\"*/o"}'
0b1db49
-            )
0b1db49
-
0b1db49
-    unittest.main()
0b1db49
diff --git a/asv/util.py b/asv/util.py
66897f6
index 570c0f7..b4e1ddc 100644
0b1db49
--- a/asv/util.py
0b1db49
+++ b/asv/util.py
0b1db49
@@ -27,11 +27,10 @@ import shlex
0b1db49
 import operator
0b1db49
 import collections
0b1db49
 
0b1db49
+import json_minify
0b1db49
 import six
0b1db49
 from six.moves import xrange
0b1db49
 
0b1db49
-from .extern import minify_json
0b1db49
-
0b1db49
 
0b1db49
 nan = float('nan')
0b1db49
 inf = float('inf')
66897f6
@@ -780,7 +779,7 @@ def load_json(path, api_version=None, js_comments=False):
0b1db49
         content = fd.read()
0b1db49
 
66897f6
     if js_comments:
0b1db49
-        content = minify_json.json_minify(content)
0b1db49
+        content = json_minify.json_minify(content)
0b1db49
         content = content.replace(",]", "]")
0b1db49
         content = content.replace(",}", "}")
0b1db49
 
0b1db49
diff --git a/pip_requirements.txt b/pip_requirements.txt
0b1db49
index 2a8662c..07d485c 100644
0b1db49
--- a/pip_requirements.txt
0b1db49
+++ b/pip_requirements.txt
0b1db49
@@ -1,3 +1,4 @@
0b1db49
+JSON_minify
0b1db49
 sphinx
0b1db49
 sphinx_bootstrap_theme
0b1db49
 six
0b1db49
diff --git a/setup.py b/setup.py
0b1db49
index efbfa42..54916e3 100755
0b1db49
--- a/setup.py
0b1db49
+++ b/setup.py
0b1db49
@@ -224,7 +224,8 @@ def run_setup(build_binary=False):
0b1db49
         ext_modules = ext_modules,
0b1db49
 
0b1db49
         install_requires=[
0b1db49
-            str('six>=1.4')
0b1db49
+            str('JSON_minify'),
0b1db49
+            str('six>=1.4'),
0b1db49
         ],
0b1db49
 
0b1db49
         extras_require={
0b1db49
-- 
66897f6
2.21.0
0b1db49