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

Detect if python2 is available or else fall back to python #74

Merged
merged 1 commit into from
May 19, 2013
Merged
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: 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