From b9ba68b1889ec3b33515b3bd5699497e954f9303 Mon Sep 17 00:00:00 2001 From: "FUJI Goro (gfx)" Date: Sat, 24 Dec 2016 10:41:37 +0900 Subject: [PATCH 1/2] Remove non-portable dependencies for JRuby --- lib/pygments/popen.rb | 26 +++++++++++++++----------- pygments.rb.gemspec | 3 +-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/pygments/popen.rb b/lib/pygments/popen.rb index 098f734b..f04ce9e2 100644 --- a/lib/pygments/popen.rb +++ b/lib/pygments/popen.rb @@ -1,6 +1,6 @@ # coding: utf-8 -require 'posix/spawn' -require 'yajl' +require 'open3' +require 'multi_json' require 'timeout' require 'logger' require 'time' @@ -13,9 +13,13 @@ class MentosError < IOError # Python process. module Pygments module Popen - include POSIX::Spawn extend self + def popen4(cmd) + stdin, stdout, stderr, wait_thr = Open3.popen3(cmd) + [wait_thr[:pid], stdin, stdout, stderr] + end + # Get things started by opening a pipe to mentos (the freshmaker), a # Python process that talks to the Pygments library. We'll talk back and # forth across this pipe. @@ -262,7 +266,7 @@ def mentos(method, args=[], kwargs={}, original_code=nil) kwargs.freeze kwargs = kwargs.merge("fd" => @out.to_i, "id" => id, "bytes" => bytesize) - out_header = Yajl.dump(:method => method, :args => args, :kwargs => kwargs) + out_header = MultiJson.dump(:method => method, :args => args, :kwargs => kwargs) # Get the size of the header itself and write that. bits = get_fixed_bits_from_header(out_header) @@ -322,12 +326,12 @@ def check_for_error def handle_header_and_return(header, id) if header header = header_to_json(header) - bytes = header["bytes"] + bytes = header[:bytes] # Read more bytes (the actual response body) res = @out.read(bytes.to_i) - if header["method"] == "highlight" + if header[:method] == "highlight" # Make sure we have a result back; else consider this an error. if res.nil? @log.warn "No highlight result back from mentos." @@ -423,7 +427,7 @@ def get_header # want them, text otherwise. def return_result(res, method) unless method == :lexer_name_for || method == :highlight || method == :css - res = Yajl.load(res, :symbolize_keys => true) + res = MultiJson.load(res, :symbolize_keys => true) end res = res.rstrip if res.class == String res @@ -432,14 +436,14 @@ def return_result(res, method) # Convert a text header into JSON for easy access. def header_to_json(header) @log.info "[In header: #{header} " - header = Yajl.load(header) + header = MultiJson.load(header, :symbolize_keys => true) - if header["error"] + if header[:error] # Raise this as a Ruby exception of the MentosError class. # Stop so we don't leave the pipe in an inconsistent state. @log.error "Failed to convert header to JSON." - stop header["error"] - raise MentosError, header["error"] + stop header[:error] + raise MentosError, header[:error] else header end diff --git a/pygments.rb.gemspec b/pygments.rb.gemspec index 3f18266f..4e2f2b48 100644 --- a/pygments.rb.gemspec +++ b/pygments.rb.gemspec @@ -14,8 +14,7 @@ Gem::Specification.new do |s| s.email = ['aman@tmm1.net'] s.license = 'MIT' - s.add_dependency 'yajl-ruby', '~> 1.2' - s.add_dependency 'posix-spawn', '~> 0.3.6' + s.add_dependency 'multi_json', '>= 1.0.0' s.add_development_dependency 'rake-compiler', '~> 0.7.6' s.add_development_dependency 'test-unit', '~> 3.0.0' From 9a2cc25f8d5a2598e2eec116e27a3e3a726795e4 Mon Sep 17 00:00:00 2001 From: "FUJI Goro (gfx)" Date: Sat, 24 Dec 2016 10:58:37 +0900 Subject: [PATCH 2/2] CI on JRuby --- circle.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/circle.yml b/circle.yml index 94d00c27..b774e4cb 100644 --- a/circle.yml +++ b/circle.yml @@ -1,7 +1,20 @@ machine: ruby: version: 2.3.1 + java: + version: oraclejdk8 + environment: + JRUBY_OPTS: '--dev --debug' + JRUBY: jruby-9.1.6.0 + +dependencies: + pre: + - echo rvm_autoupdate_flag=0 >> ~/.rvmrc + - rvm install $JRUBY + post: + - rvm-exec $JRUBY bundle install test: override: + - rvm-exec $JRUBY bundle exec rake test - bundle exec rake test