Skip to main content

gorun

(c) Peter Bengtsson, mail@peterbe.com, 2009-2012 License: Python

Using (py)inotify to run commands when files change

Tired of switching console, arrow-up, Enter, switch console back for every little change you make when you’re writing code that has tests? Running with gorun.py enables you to just save in your editor and the tests are run automatically and immediately.

gorun.py does not use a slow pulling process which keeps taps on files modification time. Instead it uses the inotify which is “a Linux kernel subsystem that provides file system event notification”.

Installation

This will only work on Linux which has the inotify module enabled in the kernel. (Most modern kernels do)

pip install gorun

This will install pyinotify.

Then, create a settings file, which is just a python file that is expected to define a variable called DIRECTORIES. Here’s an example:

DIRECTORIES = (
   ('some/place/', './myframework test --dir some/place'),
   ('some/place/unitests.py',
    './myframework test --dir some/place --testclass Unittests'),
   ('/var/log/torrentsdownload.log',
    'growl downloads --logfile /var/log/torrentsdownload.log'),
)

Save that file as, for example, gorun_settings.py and then start it like this:

$ gorun.py gorun_settings

Configuration

Once you’ve set gorun to monitor a directory it will kick off on any file that changes in that directory. By default things like autosave files from certain editors are automatically created (e.g. #foo.py# or foo.py~) and these are ignored. If there are other file extensions you want gorun to ignore add this to your settings file:

IGNORE_EXTENSIONS = ('log',)

This will add to the list of already ignored file extensions such as .pyc.

Similarly, if there are certain directories that you don’t want the inotify to notice, you can list them like this:

IGNORE_DIRECTORIES = ('xapian_index', '.autosavefiles')

Disclaimer

This code hasn’t been extensively tested and relies on importing python modules so don’t let untrusted morons fiddle with your dev environment.

Todo

When doing Django development I often run on single test method over and over and over again till I get rid of all errors. When doing this I have to change the settings so it just runs one single test and when I’m done I go back to set it up so that it runs all tests when adjacent code works.

This is a nuisance and I might try to solve that one day. If you have any tips please let me know.

Release files for gorun 1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gorun 1.7
File Size Uploaded
gorun-1.7.tar.gz 5.7 kB Details

Release files / gorun-1.7.tar.gz

Download URL gorun-1.7.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ea90999d063d1d6e68c4a47c441aa470c8b8c76144e3822279755d0af3acb6ed
BLAKE2b-256 checksum
How to use checksums
8facf4e66d81acd8cb4e96d1ce5588d95e75757b80ffa98a2df986f457eb8001
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.7 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page