Skip to content

Commit

Permalink
Merge pull request #10 from carsongee/feature/poll
Browse files Browse the repository at this point in the history
Add polling options for remote file systems
  • Loading branch information
joeyespo committed May 8, 2015
2 parents 57f8a35 + 4970abe commit cd236e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pytest_watch/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
--onpass=<cmd> Run arbitrary programs on pass.
--onfail=<cmd> Run arbitrary programs on failure.
--nobeep Do not beep on failure.
--poll Use polling instead of events (useful in VMs)
--ext=<exts> Comma-separated list of file extensions that trigger a
new test run when changed (default: .py)
"""
Expand All @@ -41,4 +42,5 @@ def main(argv=None):

extensions = args['--ext'].split(',') if args['--ext'] else []
return watch(args['<directory>'], args['--clear'], not args['--nobeep'],
args['--onpass'], args['--onfail'], extensions)
args['--onpass'], args['--onfail'], args['--poll'],
extensions)
9 changes: 7 additions & 2 deletions pytest_watch/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from colorama import Fore
from watchdog.observers import Observer
from watchdog.observers.polling import PollingObserver
from watchdog.events import FileSystemEventHandler


Expand Down Expand Up @@ -59,7 +60,7 @@ def run(self, filename=None):


def watch(directory=None, auto_clear=False, beep_on_failure=True,
onpass=None, onfail=None, extensions=[]):
onpass=None, onfail=None, poll=False, extensions=[]):
"""
Starts a server to render the specified file or directory
containing a README.
Expand All @@ -74,7 +75,11 @@ def watch(directory=None, auto_clear=False, beep_on_failure=True,
event_handler.run()

# Setup watchdog
observer = Observer()
if poll:
observer = PollingObserver()
else:
observer = Observer()

observer.schedule(event_handler, path=directory, recursive=True)
observer.start()

Expand Down

0 comments on commit cd236e6

Please sign in to comment.