new pygment hack

This commit is contained in:
Jörg Thalheim 2012-12-09 20:02:01 +01:00
parent 90d989b1d8
commit f30b3300f0
4 changed files with 68 additions and 14 deletions

View File

@ -7,6 +7,7 @@ group :development do
gem 'octopress-date-format', '~> 2.0' gem 'octopress-date-format', '~> 2.0'
gem 'jekyll-sitemap' gem 'jekyll-sitemap'
gem 'rdiscount', '~> 2.0' gem 'rdiscount', '~> 2.0'
gem 'pygments.rb', '~> 0.2.12'
gem 'RedCloth', '~> 4.2.9' gem 'RedCloth', '~> 4.2.9'
gem 'haml', '~> 4.0' gem 'haml', '~> 4.0'
gem 'compass', '~> 1.0.1' gem 'compass', '~> 1.0.1'

View File

@ -1,10 +1,3 @@
GIT
remote: https://github.com/akzhan/pygments.rb.git
revision: 11422be8de49703021a2fb85eafe55caab5fc2af
specs:
pygments.rb (0.2.12)
rubypython (~> 0.6.1)
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
@ -26,7 +19,7 @@ GEM
kramdown (~> 0.13.4) kramdown (~> 0.13.4)
liquid (~> 2.3) liquid (~> 2.3)
maruku (~> 0.5) maruku (~> 0.5)
kramdown (0.13.7) kramdown (0.14.1)
liquid (2.3.0) liquid (2.3.0)
maruku (0.6.1) maruku (0.6.1)
syntax (>= 1.0.0) syntax (>= 1.0.0)
@ -34,11 +27,11 @@ GEM
rack (1.4.1) rack (1.4.1)
rack-protection (1.2.0) rack-protection (1.2.0)
rack rack
rake (0.9.2.2) rake (0.9.5)
rb-fsevent (0.9.1) rb-fsevent (0.9.2)
rdiscount (1.6.8) rdiscount (1.6.8)
rubypants (0.2.0) rubypants (0.2.0)
rubypython (0.6.2) rubypython (0.5.3)
blankslate (>= 2.1.2.3) blankslate (>= 2.1.2.3)
ffi (~> 1.0.7) ffi (~> 1.0.7)
sass (3.1.19) sass (3.1.19)
@ -60,12 +53,11 @@ DEPENDENCIES
haml (~> 3.1.7) haml (~> 3.1.7)
jekyll (~> 0.12) jekyll (~> 0.12)
liquid (~> 2.3.0) liquid (~> 2.3.0)
pygments.rb! pygments.rb (~> 0.2.12)
rack (~> 1.4.1) rack (~> 1.4.1)
rake (~> 0.9.2) rake (~> 0.9.2)
rb-fsevent (~> 0.9) rb-fsevent (~> 0.9)
rdiscount (~> 1.6.8) rdiscount (~> 1.6.8)
rubypants (~> 0.2.0) rubypants (~> 0.2.0)
rubypython (~> 0.6.1)
sinatra (~> 1.3.2) sinatra (~> 1.3.2)
stringex (~> 1.4.0) stringex (~> 1.4.0)

View File

@ -43,3 +43,65 @@ module HighlightCode
table += "</pre></td><td class='code'><pre><code class='#{lang}'>#{code}</code></pre></td></tr></table></div>" table += "</pre></td><td class='code'><pre><code class='#{lang}'>#{code}</code></pre></td></tr></table></div>"
end end
end end
#------------------------------------------------------------------------------#
# INTERIM BUGFIX FOR: https://github.com/imathis/octopress/issues/704
# an upstream solution is in the works but, as of 2012-08-29, the pygment.rb
# gem has yet to incorporate necessary changes and release a new gem:
# https://github.com/tmm1/pygments.rb/issues/10
#
# The ForcePython2 module below tries to ensure that, when the 'python' command
# is executed, it always returns an interpreter for version 2.* of python,
# regardless of what the system-wide default version of python is. When the
# system-wide version of python is not 2.* and a compatible version is found,
# a .pygments-cache/python-bin/python symlink is created which points to the
# compatible version. The python-bin directory is then added to the PATH
# which gives priority to locally identified version.
#
module ForcePython2
class << self
def find_python2
(%w{python python2} + 10.downto(0).map{|v|"python2.#{v}"}).each do |cmd|
cmd_path = which_cmd(cmd) or next
return cmd_path if python_major_ver(cmd_path) == 2
end
nil
end
def python_major_ver(cmd_path)
%x{"#{cmd_path}" -c "import sys; print(sys.version_info.major)"}.to_i
end
def which_cmd(cmd)
# loosely based on cross-platform solution found on stack overflow:
# http://stackoverflow.com/questions/2108727/
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] # windows
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
cmd_paths = exts.map {|ext| "#{path}#{File::SEPARATOR}#{cmd}#{ext}" }
cmd_path = cmd_paths.find {|c| File.executable?(c) }
return cmd_path if cmd_path
end
nil
end
def force
# rewrite PATH to include local dir which might have python symlink
path = "#{PYGMENTS_CACHE_DIR}#{File::SEPARATOR}python-bin"
ENV['PATH'] = "#{path}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
# if 'python' command's version is 2.*, we're good
return if python_major_ver(which_cmd('python')) == 2
# not v2, search all our paths for a compatible version
if cmd_path = find_python2
# found a compatible version, make it stick w/ a symlink
sym_path = "#{path}#{File::SEPARATOR}python#{File.extname(cmd_path)}"
FileUtils.mkdir_p(path)
File.symlink(cmd_path, sym_path) rescue nil # don't care if unimplemented
end
end
end
end
ForcePython2::force unless ENV['FORCE_PYTHON2'] =~ /^(?:0|false|no)$/i

View File

@ -1 +0,0 @@
RubyPython.start :python_exe => 'python2.7'