summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-09-08 23:32:59 +0100
committerMichael Williamson <mike@zwobble.org>2015-09-09 00:08:45 +0100
commit75e786256c2bd1d3acdbccb7bf769443679f590d (patch)
tree0e615e0b931ffbda8e8944762554c2b622d47571
parent67294953a9ef2c72584bc6801457f3de2dec5c7f (diff)
Update jq to 1.5
-rw-r--r--.gitignore4
-rw-r--r--README.rst15
-rw-r--r--jq.pyx20
-rw-r--r--setup.py24
-rw-r--r--tests/jq_tests.py8
5 files changed, 25 insertions, 46 deletions
diff --git a/.gitignore b/.gitignore
index 1ef07a6..3767140 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,5 +6,5 @@
/.tox
/*.egg-info
/_jq-lib
-/jq-jq-1.4
-/_jq-lib-1.4.tar.gz
+/jq-jq-1.5
+/_jq-lib-1.5.tar.gz
diff --git a/README.rst b/README.rst
index bed353e..8dce9aa 100644
--- a/README.rst
+++ b/README.rst
@@ -8,7 +8,7 @@ Installation
------------
During installation,
-the source for jq 1.4 is downloaded over HTTPS and built.
+the source for jq 1.5 is downloaded over HTTPS and built.
Therefore, installation requires any programs required to build jq.
This includes:
@@ -16,10 +16,6 @@ This includes:
* The normal C compiler toolchain, such as gcc and make.
-* Flex
-
-* Bison
-
* libtool
* Python headers.
@@ -31,7 +27,7 @@ If on Debian, Ubuntu or relatives, running the following command should be suffi
.. code-block:: sh
- apt-get install autoconf build-essential flex bison libtool python-dev
+ apt-get install autoconf build-essential libtool python-dev
Red Hat, Fedora, CentOS or relatives
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -41,7 +37,7 @@ If on Red Hat, Fedora, CentOS, or relatives, running the following command shoul
.. code-block:: sh
yum groupinstall "Development Tools"
- yum install autoconf flex bison libtool python
+ yum install autoconf libtool python
Mac OS X
~~~~~~~~
@@ -52,10 +48,7 @@ Once Homebrew is installed, you can install the remaining dependencies with:
.. code-block:: sh
- brew install autoconf bison libtool
-
-Note that at least some versions of Mac OS X ship a version of ``bison`` that is too old for ``jq`` to use.
-jq.py will try to use the version from Homebrew if available.
+ brew install autoconf libtool
Usage
-----
diff --git a/jq.pyx b/jq.pyx
index 6e6a3e3..2da5f41 100644
--- a/jq.pyx
+++ b/jq.pyx
@@ -141,18 +141,22 @@ cdef class _Program(object):
if jv_is_valid(value):
self._process(value, results)
else:
- if jv_invalid_has_msg(jv_copy(value)):
- error_message = jv_invalid_get_msg(value)
- full_error_message = b"parse error: " + jv_string_value(error_message) + b"\n"
- self._error_store.store_error(full_error_message)
- jv_free(error_message)
- else:
- jv_free(value)
+ self._handle_invalid_jv(value, b"parse error: ")
break
jv_parser_free(parser)
return results
+
+ cdef void _handle_invalid_jv(self, jv value, char* prefix):
+ if jv_invalid_has_msg(jv_copy(value)):
+ error_message = jv_invalid_get_msg(value)
+ full_error_message = prefix + jv_string_value(error_message)
+ self._error_store.store_error(full_error_message)
+ jv_free(error_message)
+ else:
+ jv_free(value)
+
cdef void _process(self, jv value, object output):
@@ -166,7 +170,7 @@ cdef class _Program(object):
while True:
result = jq_next(self._jq)
if not jv_is_valid(result):
- jv_free(result)
+ self._handle_invalid_jv(result, b"")
return
else:
dumped = jv_dump_string(result, dumpopts)
diff --git a/setup.py b/setup.py
index e142b04..a5b22be 100644
--- a/setup.py
+++ b/setup.py
@@ -28,14 +28,14 @@ def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
-tarball_path = path_in_dir("_jq-lib-1.4.tar.gz")
-jq_lib_dir = path_in_dir("jq-jq-1.4")
+tarball_path = path_in_dir("_jq-lib-1.5.tar.gz")
+jq_lib_dir = path_in_dir("jq-jq-1.5")
class jq_build_ext(build_ext):
def run(self):
if os.path.exists(tarball_path):
os.unlink(tarball_path)
- urlretrieve("https://github.com/stedolan/jq/archive/jq-1.4.tar.gz", tarball_path)
+ urlretrieve("https://github.com/stedolan/jq/archive/jq-1.5.tar.gz", tarball_path)
if os.path.exists(jq_lib_dir):
shutil.rmtree(jq_lib_dir)
@@ -45,28 +45,12 @@ class jq_build_ext(build_ext):
print("Executing: %s" % ' '.join(args))
subprocess.check_call(args, cwd=jq_lib_dir)
- configure_args = ["CFLAGS=-fPIC"]
-
- if os.path.exists('/usr/local/bin/brew') and os.path.exists('/usr/local/Cellar'):
- print("Found Homebrew installation")
- # Mac OS X with Homebrew
- # Mac OS X usually ships with an old bison (yacc)
- # E.g.: OS X 10.9 has bison 2.3, but jq requires bison >= 2.5
- # Try to use Homebrew version of bison (3.0.3 as of this writing)
- try:
- yacc = subprocess.check_output("/usr/local/bin/brew ls bison | grep bin/yacc", shell=True).rstrip()
- print("Found Homebrew yacc at %s" % yacc)
- if yacc:
- configure_args.append('YACC=' + yacc)
- except subprocess.CalledProcessError:
- print("No Homebrew yacc found")
-
macosx_deployment_target = sysconfig.get_config_var("MACOSX_DEPLOYMENT_TARGET")
if macosx_deployment_target:
os.environ['MACOSX_DEPLOYMENT_TARGET'] = macosx_deployment_target
command(["autoreconf", "-i"])
- command(["./configure"] + configure_args)
+ command(["./configure", "CFLAGS=-fPIC", "--disable-maintainer-mode"])
command(["make"])
build_ext.run(self)
diff --git a/tests/jq_tests.py b/tests/jq_tests.py
index c0f4391..6220511 100644
--- a/tests/jq_tests.py
+++ b/tests/jq_tests.py
@@ -77,9 +77,7 @@ def value_error_is_raised_if_program_is_invalid():
jq("!")
assert False, "Expected error"
except ValueError as error:
- expected_error_str = """error: syntax error, unexpected INVALID_CHARACTER, expecting $end
-!
-1 compile error"""
+ expected_error_str = "jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at <top-level>, line 1:\n!\njq: 1 compile error"
assert_equal(str(error), expected_error_str)
@@ -90,7 +88,7 @@ def value_error_is_raised_if_input_cannot_be_processed_by_program():
program.transform(1)
assert False, "Expected error"
except ValueError as error:
- expected_error_str = "jq: error: Cannot index number with string"
+ expected_error_str = "Cannot index number with string \"x\""
assert_equal(str(error), expected_error_str)
@@ -113,7 +111,7 @@ def value_error_is_raised_if_input_is_not_valid_json():
program.transform(text="!!")
assert False, "Expected error"
except ValueError as error:
- expected_error_str = "parse error: Invalid numeric literal\n"
+ expected_error_str = "parse error: Invalid numeric literal at EOF at line 1, column 2"
assert_equal(str(error), expected_error_str)