diff --git a/Gemfile b/Gemfile index 153dd3d..7383086 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ group :development do gem 'octopress-date-format', '~> 2.0' gem 'jekyll-sitemap' gem 'rdiscount', '~> 2.0' + gem 'pygments.rb', '~> 0.2.12' gem 'RedCloth', '~> 4.2.9' gem 'haml', '~> 4.0' gem 'compass', '~> 1.0.1' diff --git a/Gemfile.lock b/Gemfile.lock index 304092a..21fa9b9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 remote: http://rubygems.org/ specs: @@ -26,7 +19,7 @@ GEM kramdown (~> 0.13.4) liquid (~> 2.3) maruku (~> 0.5) - kramdown (0.13.7) + kramdown (0.14.1) liquid (2.3.0) maruku (0.6.1) syntax (>= 1.0.0) @@ -34,11 +27,11 @@ GEM rack (1.4.1) rack-protection (1.2.0) rack - rake (0.9.2.2) - rb-fsevent (0.9.1) + rake (0.9.5) + rb-fsevent (0.9.2) rdiscount (1.6.8) rubypants (0.2.0) - rubypython (0.6.2) + rubypython (0.5.3) blankslate (>= 2.1.2.3) ffi (~> 1.0.7) sass (3.1.19) @@ -60,12 +53,11 @@ DEPENDENCIES haml (~> 3.1.7) jekyll (~> 0.12) liquid (~> 2.3.0) - pygments.rb! + pygments.rb (~> 0.2.12) rack (~> 1.4.1) rake (~> 0.9.2) rb-fsevent (~> 0.9) rdiscount (~> 1.6.8) rubypants (~> 0.2.0) - rubypython (~> 0.6.1) sinatra (~> 1.3.2) stringex (~> 1.4.0) diff --git a/plugins/pygments_code.rb b/plugins/pygments_code.rb index c0f4de9..78e7894 100644 --- a/plugins/pygments_code.rb +++ b/plugins/pygments_code.rb @@ -43,3 +43,65 @@ module HighlightCode table += "
#{code}
" 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 diff --git a/plugins/ruby_python_arch_linux_fix.rb b/plugins/ruby_python_arch_linux_fix.rb deleted file mode 100644 index a43ec65..0000000 --- a/plugins/ruby_python_arch_linux_fix.rb +++ /dev/null @@ -1 +0,0 @@ -RubyPython.start :python_exe => 'python2.7'