Created
August 22, 2012 10:44
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 "[%s] Error while compiling %s" % (datetime.now().strftime("%X"), event.src_path) | |
| 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