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

Add polling options for remote file systems #10

Merged
merged 1 commit into from
May 8, 2015
Merged
Show file tree
Hide file tree
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
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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good idea to call out why this is here! 👍

--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