Skip to content

Instantly share code, notes, and snippets.

@abhin4v
Created August 22, 2012 10:44
Show Gist options
  • Select an option

  • Save abhin4v/3424296 to your computer and use it in GitHub Desktop.

Select an option

Save abhin4v/3424296 to your computer and use it in GitHub Desktop.
Watches current directory and compiles the haskell source files when they are modified
# Usage: python HaskellCC.py (Ctrl-C for exit)
import time
from datetime import datetime
import subprocess
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
class HaskellContinuousCompiler(PatternMatchingEventHandler):
def on_modified(self, event):
print "[%s] Compiling %s" % (datetime.now().strftime("%X"), event.src_path)
try:
subprocess.check_output(["ghc", "-c", event.src_path])
print "[%s] Compiled %s" % (datetime.now().strftime("%X"), event.src_path)
except subprocess.CalledProcessError:
print
print "[%s] Error while compiling %s" % (datetime.now().strftime("%X"), event.src_path)
print "-------------------------------------------------------------"
print
if __name__ == "__main__":
event_handler = HaskellContinuousCompiler(patterns=["*.hs"], ignore_directories=True)
observer = Observer()
observer.schedule(event_handler, path='.')
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment