Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove non-portable dependencies for JRuby #170

Merged
merged 2 commits into from
Dec 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 15 additions & 11 deletions lib/pygments/popen.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8
require 'posix/spawn'
require 'yajl'
require 'open3'
require 'multi_json'
require 'timeout'
require 'logger'
require 'time'
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pygments.rb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ Gem::Specification.new do |s|
s.email = ['[email protected]']
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'

Expand Down