Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #55 from nitoyon/windows-support

Support for Windows
  • Loading branch information...
commit b414b5dc9a02d1cdddf00c3beffe4a3e2e99b003 2 parents 4af8402 + 7772eda
@tnm tnm authored
Showing with 25 additions and 15 deletions.
  1. +19 −12 lib/pygments/mentos.py
  2. +6 −3 lib/pygments/popen.rb
View
31 lib/pygments/mentos.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-import sys, re, os, signal, resource
+import sys, re, os, signal
import traceback
if 'PYGMENTS_PATH' in os.environ:
sys.path.insert(0, os.environ['PYGMENTS_PATH'])
@@ -320,20 +320,27 @@ def main():
# Signal handlers to trap signals.
signal.signal(signal.SIGINT, _signal_handler)
signal.signal(signal.SIGTERM, _signal_handler)
- signal.signal(signal.SIGHUP, _signal_handler)
+ if sys.platform != "win32":
+ signal.signal(signal.SIGHUP, _signal_handler)
mentos = Mentos()
- # close fd's inherited from the ruby parent
- maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
- if maxfd == resource.RLIM_INFINITY:
- maxfd = 65536
-
- for fd in range(3, maxfd):
- try:
- os.close(fd)
- except:
- pass
+ if sys.platform == "win32":
+ # disable CRLF
+ import msvcrt
+ msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
+ else:
+ # close fd's inherited from the ruby parent
+ import resource
+ maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
+ if maxfd == resource.RLIM_INFINITY:
+ maxfd = 65536
+
+ for fd in range(3, maxfd):
+ try:
+ os.close(fd)
+ except:
+ pass
mentos.start()
View
9 lib/pygments/popen.rb
@@ -20,12 +20,13 @@ module Popen
# Python process that talks to the Pygments library. We'll talk back and
# forth across this pipe.
def start(pygments_path = File.expand_path('../../../vendor/pygments-main/', __FILE__))
+ is_windows = RUBY_PLATFORM =~ /mswin|mingw/
begin
- @log = Logger.new(ENV['MENTOS_LOG'] ||= '/dev/null')
+ @log = Logger.new(ENV['MENTOS_LOG'] ||= is_windows ? 'NUL:' : '/dev/null')
@log.level = Logger::INFO
@log.datetime_format = "%Y-%m-%d %H:%M "
rescue
- @log = Logger.new('/dev/null')
+ @log = Logger.new(is_windows ? 'NUL:' : '/dev/null')
end
ENV['PYGMENTS_PATH'] = pygments_path
@@ -35,7 +36,9 @@ 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.
- @pid, @in, @out, @err = popen4(File.expand_path('../mentos.py', __FILE__))
+ script = File.expand_path('../mentos.py', __FILE__)
+ script = 'python ' + script if is_windows
+ @pid, @in, @out, @err = popen4(script)
@log.info "[#{Time.now.iso8601}] Starting pid #{@pid.to_s} with fd #{@out.to_i.to_s}."
end
Please sign in to comment.
Something went wrong with that request. Please try again.