Find yourself executing the same command over and over again after applying changes to certain files? Pywatch will be you best friend!
Meet pywatch
: a cool little app that watches directories and files. Whenever it finds a file that changed, it executes the command you provided.
As an example; I use this to build a Docker image whenever I save a change to my Dockerfile.
pywatch "docker build . -t pauledenburg/behat" Dockerfile
Or execute tests whenever I make a change to one of the sourcefiles.
commandToExecute='docker exec -i hangman_app_1 behat -c tests/behat/behat.yml' find ./tests -name "*.php" -o -name "*.feature" \ | xargs pywatch "$commandToExecute"
This keeps an eye on all *.php
and *.feature
files under ./tests
.
When one of these files changes, it executes $commandToExecute
which resolves to executing behat in a Docker container.
Download the pywatch app from github: https://github.com/cmheisel/pywatch.
Then unzip and install with python.
unzip pywatch-master.zip cd pywatch-master sudo python setup.py install
Nice one: run tests when files change and create a Mac notifier whenever the tests fail.
This way you can keep the tests running in the background and you’ll be notified whenever a test failed.
find src tests -name "*.php" -o -name "*.feature" \ | xargs pywatch "./dev test phpunit" \ | grep "([0-9]* failed)" \ | sed -e 's/.*(\([0-9]* failed\)).*/\1/' \ | while read failure; do terminal-notifier -message "Test output: $failure" -title "Tests Failed!" done
From the pip website:
pip is already installed if you’re using Python 2 >=2.7.9 or Python 3 >=3.4 binaries downloaded from python.org, but you’ll need to upgrade pip.
To install pip, run the following.
curl -Lo get-pip.py https://bootstrap.pypa.io/get-pip.py python get-pip.py