pygments.rb 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/circle.yml +13 -0
- data/lib/pygments/lexer.rb +2 -0
- data/lib/pygments/popen.rb +19 -16
- data/lib/pygments/version.rb +3 -1
- data/lib/pygments.rb +23 -2
- data/pygments.rb.gemspec +1 -2
- data/test/test_pygments.rb +23 -9
- data/vendor/pygments-main/scripts/find_error.py +1 -1
- metadata +8 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5021687249edac6151faaec1cec0187dea8eb311
|
|
4
|
+
data.tar.gz: f61e48727a7eb866ee5c5bd549ddce136095efc2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 05ec911f5a0aa423dd24da7ad7a4228989170790dee007347e401745c64d5c5fbc29b43cbe9e6a43f499f46ca5af8c504d0e0e29c2272aeb82fbcee524401b69
|
|
7
|
+
data.tar.gz: b93056fd8b559770b234958660c4643ac400cbedfcf65df9e20dfcf859651b75d3361b1723506ed6bf18d7ab30de128d15ca65ae2454974f73e345b8cc4bed9b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
changelog
|
|
2
2
|
===========
|
|
3
3
|
|
|
4
|
+
Version 1.1.1 (2016/12/28)
|
|
5
|
+
-----------------------------
|
|
6
|
+
|
|
7
|
+
* Suppress Ruby 2.4.0's warnings [#172](https://github.com/tmm1/pygments.rb/pull/172)
|
|
8
|
+
* Enable `frozen_string_literal` [#173](https://github.com/tmm1/pygments.rb/pull/173)
|
|
9
|
+
|
|
10
|
+
Version 1.1.0 (2016/12/24)
|
|
11
|
+
-----------------------------
|
|
12
|
+
|
|
13
|
+
* Support JRuby [#170](https://github.com/tmm1/pygments.rb/pull/170)
|
|
14
|
+
* Make pygments.rb thread safe [#171](https://github.com/tmm1/pygments.rb/pull/171)
|
|
15
|
+
|
|
4
16
|
Version 1.0.0 (2016/12/11)
|
|
5
17
|
-----------------------------
|
|
6
18
|
|
data/circle.yml
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
machine:
|
|
2
2
|
ruby:
|
|
3
3
|
version: 2.3.1
|
|
4
|
+
java:
|
|
5
|
+
version: oraclejdk8
|
|
6
|
+
environment:
|
|
7
|
+
JRUBY_OPTS: '--dev --debug'
|
|
8
|
+
JRUBY: jruby-9.1.6.0
|
|
9
|
+
|
|
10
|
+
dependencies:
|
|
11
|
+
pre:
|
|
12
|
+
- echo rvm_autoupdate_flag=0 >> ~/.rvmrc
|
|
13
|
+
- rvm install $JRUBY
|
|
14
|
+
post:
|
|
15
|
+
- rvm-exec $JRUBY bundle install
|
|
4
16
|
|
|
5
17
|
test:
|
|
6
18
|
override:
|
|
19
|
+
- rvm-exec $JRUBY bundle exec rake test
|
|
7
20
|
- bundle exec rake test
|
data/lib/pygments/lexer.rb
CHANGED
data/lib/pygments/popen.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'open3'
|
|
5
|
+
require 'multi_json'
|
|
4
6
|
require 'timeout'
|
|
5
7
|
require 'logger'
|
|
6
8
|
require 'time'
|
|
@@ -12,9 +14,12 @@ end
|
|
|
12
14
|
# Pygments provides access to the Pygments library via a pipe and a long-running
|
|
13
15
|
# Python process.
|
|
14
16
|
module Pygments
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
class Popen
|
|
18
|
+
|
|
19
|
+
def popen4(cmd)
|
|
20
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(cmd)
|
|
21
|
+
[wait_thr[:pid], stdin, stdout, stderr]
|
|
22
|
+
end
|
|
18
23
|
|
|
19
24
|
# Get things started by opening a pipe to mentos (the freshmaker), a
|
|
20
25
|
# Python process that talks to the Pygments library. We'll talk back and
|
|
@@ -262,7 +267,7 @@ module Pygments
|
|
|
262
267
|
|
|
263
268
|
kwargs.freeze
|
|
264
269
|
kwargs = kwargs.merge("fd" => @out.to_i, "id" => id, "bytes" => bytesize)
|
|
265
|
-
out_header =
|
|
270
|
+
out_header = MultiJson.dump(:method => method, :args => args, :kwargs => kwargs)
|
|
266
271
|
|
|
267
272
|
# Get the size of the header itself and write that.
|
|
268
273
|
bits = get_fixed_bits_from_header(out_header)
|
|
@@ -322,12 +327,12 @@ module Pygments
|
|
|
322
327
|
def handle_header_and_return(header, id)
|
|
323
328
|
if header
|
|
324
329
|
header = header_to_json(header)
|
|
325
|
-
bytes = header[
|
|
330
|
+
bytes = header[:bytes]
|
|
326
331
|
|
|
327
332
|
# Read more bytes (the actual response body)
|
|
328
333
|
res = @out.read(bytes.to_i)
|
|
329
334
|
|
|
330
|
-
if header[
|
|
335
|
+
if header[:method] == "highlight"
|
|
331
336
|
# Make sure we have a result back; else consider this an error.
|
|
332
337
|
if res.nil?
|
|
333
338
|
@log.warn "No highlight result back from mentos."
|
|
@@ -368,9 +373,7 @@ module Pygments
|
|
|
368
373
|
# id, with two padding also. This means we are sending over the 8 characters +
|
|
369
374
|
# code + 8 characters.
|
|
370
375
|
def add_ids(code, id)
|
|
371
|
-
code.freeze
|
|
372
|
-
code = id + " #{code} #{id}"
|
|
373
|
-
code
|
|
376
|
+
(id + " #{code} #{id}").freeze
|
|
374
377
|
end
|
|
375
378
|
|
|
376
379
|
# Write data to mentos, the Python process.
|
|
@@ -423,7 +426,7 @@ module Pygments
|
|
|
423
426
|
# want them, text otherwise.
|
|
424
427
|
def return_result(res, method)
|
|
425
428
|
unless method == :lexer_name_for || method == :highlight || method == :css
|
|
426
|
-
res =
|
|
429
|
+
res = MultiJson.load(res, :symbolize_keys => true)
|
|
427
430
|
end
|
|
428
431
|
res = res.rstrip if res.class == String
|
|
429
432
|
res
|
|
@@ -432,14 +435,14 @@ module Pygments
|
|
|
432
435
|
# Convert a text header into JSON for easy access.
|
|
433
436
|
def header_to_json(header)
|
|
434
437
|
@log.info "[In header: #{header} "
|
|
435
|
-
header =
|
|
438
|
+
header = MultiJson.load(header, :symbolize_keys => true)
|
|
436
439
|
|
|
437
|
-
if header[
|
|
440
|
+
if header[:error]
|
|
438
441
|
# Raise this as a Ruby exception of the MentosError class.
|
|
439
442
|
# Stop so we don't leave the pipe in an inconsistent state.
|
|
440
443
|
@log.error "Failed to convert header to JSON."
|
|
441
|
-
stop header[
|
|
442
|
-
raise MentosError, header[
|
|
444
|
+
stop header[:error]
|
|
445
|
+
raise MentosError, header[:error]
|
|
443
446
|
else
|
|
444
447
|
header
|
|
445
448
|
end
|
data/lib/pygments/version.rb
CHANGED
data/lib/pygments.rb
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'pygments/popen')
|
|
2
|
-
|
|
4
|
+
require 'forwardable'
|
|
3
5
|
|
|
4
6
|
module Pygments
|
|
5
|
-
extend Pygments::Popen
|
|
6
7
|
|
|
7
8
|
autoload :Lexer, 'pygments/lexer'
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
extend Forwardable
|
|
12
|
+
|
|
13
|
+
def engine
|
|
14
|
+
Thread.current.thread_variable_get(:pygments_engine) ||
|
|
15
|
+
Thread.current.thread_variable_set(:pygments_engine, Pygments::Popen.new)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def_delegators :engine,
|
|
19
|
+
:formatters,
|
|
20
|
+
:lexers,
|
|
21
|
+
:lexers!,
|
|
22
|
+
:filters,
|
|
23
|
+
:styles,
|
|
24
|
+
:css,
|
|
25
|
+
:lexer_name_for,
|
|
26
|
+
:highlight,
|
|
27
|
+
:start
|
|
28
|
+
end
|
|
8
29
|
end
|
data/pygments.rb.gemspec
CHANGED
|
@@ -14,8 +14,7 @@ Gem::Specification.new do |s|
|
|
|
14
14
|
s.email = ['aman@tmm1.net']
|
|
15
15
|
s.license = 'MIT'
|
|
16
16
|
|
|
17
|
-
s.add_dependency '
|
|
18
|
-
s.add_dependency 'posix-spawn', '~> 0.3.6'
|
|
17
|
+
s.add_dependency 'multi_json', '>= 1.0.0'
|
|
19
18
|
s.add_development_dependency 'rake-compiler', '~> 0.7.6'
|
|
20
19
|
s.add_development_dependency 'test-unit', '~> 3.0.0'
|
|
21
20
|
|
data/test/test_pygments.rb
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
#coding: utf-8
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
require 'test/unit'
|
|
4
5
|
require File.join(File.dirname(__FILE__), '..', '/lib/pygments.rb')
|
|
5
6
|
ENV['mentos-test'] = "yes"
|
|
6
7
|
|
|
8
|
+
|
|
7
9
|
P = Pygments
|
|
10
|
+
PE = Pygments.engine
|
|
8
11
|
|
|
9
12
|
class PygmentsHighlightTest < Test::Unit::TestCase
|
|
10
13
|
RUBY_CODE = "#!/usr/bin/ruby\nputs 'foo'"
|
|
@@ -111,6 +114,17 @@ class PygmentsHighlightTest < Test::Unit::TestCase
|
|
|
111
114
|
code = P.highlight("importr python; wat?", :lexer => 'py')
|
|
112
115
|
assert_match ">importr</span>", code
|
|
113
116
|
end
|
|
117
|
+
|
|
118
|
+
def test_highlight_on_multi_threads
|
|
119
|
+
10.times.map do
|
|
120
|
+
Thread.new do
|
|
121
|
+
test_full_html_highlight
|
|
122
|
+
end
|
|
123
|
+
end.each do |thread|
|
|
124
|
+
thread.join
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
114
128
|
end
|
|
115
129
|
|
|
116
130
|
# Philosophically, I'm not the biggest fan of testing private
|
|
@@ -118,44 +132,44 @@ end
|
|
|
118
132
|
# over the pipe I think it's necessary and informative.
|
|
119
133
|
class PygmentsValidityTest < Test::Unit::TestCase
|
|
120
134
|
def test_add_ids_with_padding
|
|
121
|
-
res =
|
|
135
|
+
res = PE.send(:add_ids, "herp derp baz boo foo", "ABCDEFGH")
|
|
122
136
|
assert_equal "ABCDEFGH herp derp baz boo foo ABCDEFGH", res
|
|
123
137
|
end
|
|
124
138
|
|
|
125
139
|
def test_add_ids_on_empty_string
|
|
126
|
-
res =
|
|
140
|
+
res = PE.send(:add_ids, "", "ABCDEFGH")
|
|
127
141
|
assert_equal "ABCDEFGH ABCDEFGH", res
|
|
128
142
|
end
|
|
129
143
|
|
|
130
144
|
def test_add_ids_with_unicode_data
|
|
131
|
-
res =
|
|
145
|
+
res = PE.send(:add_ids, "# ø ø ø", "ABCDEFGH")
|
|
132
146
|
assert_equal "ABCDEFGH # ø ø ø ABCDEFGH", res
|
|
133
147
|
end
|
|
134
148
|
|
|
135
149
|
def test_add_ids_with_starting_slashes
|
|
136
|
-
res =
|
|
150
|
+
res = PE.send(:add_ids, '\\# ø ø ø..//', "ABCDEFGH")
|
|
137
151
|
assert_equal "ABCDEFGH \\# ø ø ø..// ABCDEFGH", res
|
|
138
152
|
end
|
|
139
153
|
|
|
140
154
|
def test_get_fixed_bits_from_header
|
|
141
|
-
bits =
|
|
155
|
+
bits = PE.send(:get_fixed_bits_from_header, '{"herp": "derp"}')
|
|
142
156
|
assert_equal "00000000000000000000000000010000", bits
|
|
143
157
|
end
|
|
144
158
|
|
|
145
159
|
def test_get_fixed_bits_from_header_works_with_large_headers
|
|
146
|
-
bits =
|
|
160
|
+
bits = PE.send(:get_fixed_bits_from_header, '{"herp": "derp"}' * 10000)
|
|
147
161
|
assert_equal "00000000000000100111000100000000", bits
|
|
148
162
|
end
|
|
149
163
|
|
|
150
164
|
def test_size_check
|
|
151
165
|
size = "00000000000000000000000000100110"
|
|
152
|
-
res =
|
|
166
|
+
res = PE.send(:size_check, size)
|
|
153
167
|
assert_equal res, true
|
|
154
168
|
end
|
|
155
169
|
|
|
156
170
|
def test_size_check_bad
|
|
157
171
|
size = "some random thing"
|
|
158
|
-
res =
|
|
172
|
+
res = PE.send(:size_check, size)
|
|
159
173
|
assert_equal res, false
|
|
160
174
|
end
|
|
161
175
|
end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
debug_lexer.py
|
|
1
|
+
vendor/pygments-main/scripts/debug_lexer.py
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pygments.rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aman Gupta
|
|
@@ -9,36 +9,22 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2016-12-
|
|
12
|
+
date: 2016-12-28 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
|
-
name:
|
|
15
|
+
name: multi_json
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
|
17
17
|
requirements:
|
|
18
|
-
- - "
|
|
18
|
+
- - ">="
|
|
19
19
|
- !ruby/object:Gem::Version
|
|
20
|
-
version:
|
|
20
|
+
version: 1.0.0
|
|
21
21
|
type: :runtime
|
|
22
22
|
prerelease: false
|
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
24
|
requirements:
|
|
25
|
-
- - "
|
|
26
|
-
- !ruby/object:Gem::Version
|
|
27
|
-
version: '1.2'
|
|
28
|
-
- !ruby/object:Gem::Dependency
|
|
29
|
-
name: posix-spawn
|
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
|
31
|
-
requirements:
|
|
32
|
-
- - "~>"
|
|
33
|
-
- !ruby/object:Gem::Version
|
|
34
|
-
version: 0.3.6
|
|
35
|
-
type: :runtime
|
|
36
|
-
prerelease: false
|
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
-
requirements:
|
|
39
|
-
- - "~>"
|
|
25
|
+
- - ">="
|
|
40
26
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: 0.
|
|
27
|
+
version: 1.0.0
|
|
42
28
|
- !ruby/object:Gem::Dependency
|
|
43
29
|
name: rake-compiler
|
|
44
30
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -425,7 +411,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
425
411
|
version: '0'
|
|
426
412
|
requirements: []
|
|
427
413
|
rubyforge_project:
|
|
428
|
-
rubygems_version: 2.
|
|
414
|
+
rubygems_version: 2.6.8
|
|
429
415
|
signing_key:
|
|
430
416
|
specification_version: 4
|
|
431
417
|
summary: pygments wrapper for ruby
|