Skip to content

Commit

Permalink
Merge pull request #74 from charliesome/detect-python-vs-python2
Browse files Browse the repository at this point in the history
Detect if `python2` is available or else fall back to `python`
  • Loading branch information
tmm1 committed May 19, 2013
2 parents 9604a54 + f03df35 commit 84c69a1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/pygments/popen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,21 @@ def start(pygments_path = File.expand_path('../../../vendor/pygments-main/', __F

# A pipe to the mentos python process. #popen4 gives us
# the pid and three IO objects to write and read.
script = File.expand_path('../mentos.py', __FILE__)
script = 'python ' + script if is_windows
script = "#{python_binary} #{File.expand_path('../mentos.py', __FILE__)}"
@pid, @in, @out, @err = popen4(script)
@log.info "[#{Time.now.iso8601}] Starting pid #{@pid.to_s} with fd #{@out.to_i.to_s}."
end

# Detect a suitable Python binary to use. We can't just use `python2`
# because apparently some old versions of Debian only have `python` or
# something like that.
def python_binary
@python_binary ||= begin
`which python2`
$?.success? ? "python2" : "python"
end
end

# Stop the child process by issuing a kill -9.
#
# We then call waitpid() with the pid, which waits for that particular
Expand Down

1 comment on commit 84c69a1

@robin850
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @charliesome ❤️ !

Please sign in to comment.