Tool for automatically building source on save.
Project description
thirdparty.builder.assist
Tool for automatically building code on save.
Usage Synopsis
assist -p <path to watch> -- <command to run>
Overview
Inotify (i.e. inotifywait) and other file change notification systems will send many events all at once about how a file is being accessed or changed. You can't you these raw events to trigger a build because you'd start running the build prematurely.
This script is designed to watch for only mutation events (i.e. it ignores opens, accesses, and close with nowrite). When using an editor like VSCode, it is constantly accessing file meta data to determine if it needs to reread files. We should not build everytime VSCode merely reads the metadata of a file path.
The script waits for the inotify events to settle before running the build again. For example, you may run a formatter that modifies many files in the source directory. You don't want the build command to be executed after only the first file has been written, you need to wait until all files have been touched. This settlement is detected with a simple timeout. It waits for a given duration of no events after an event before running the given reaction command.
The script will not queue commands to run while changes are incoming. If the given command takes a while to run, changes might be made to the source while the command is running. The last change time is recorded and this is checked against the last time the command was executed. If the difference is greater than the given settlement duration it'll rerun the command.
The script has a signal handler to catch Ctrl-C. Ctrl-C is the expected way to exit the watcher.py while its waiting for updates. I don't know what the behavior of the system is if you Ctrl-C/SIGINT while the given user command is being executed.
Install
python3 -m pip install --upgrade thirdparty-builder-assist
CLI Usage
Thirdparty Builder Assist includes a console script assist
. The intended use for this is to run a file watcher for a source directory and automatically run a build and/or test command after there have been no changes to any files for 1 second.
If your current working directory is /project
, and this project is a make project will all source stored in /project/src
, you can use assist
to automatically run make
using a command like the following:
assist -p src -- make
API Usage
Thirdparty Builder Assist comes with an API that allows your code to react to inotify events the same way the assist
console script does. Using the same example above, here is an example Python snippet prints a message when change events are detected.
from thirdparty.builder.assist import start_watching
from time import sleep
# Fire up builder.assist thread.
assist_context = start_watching('/project/src')
while True:
sleep(0.1)
if assist_context.is_event():
print("Detected changes.")
Contributing
Any contributions and feature requests are welcome! Please submit all contributions for thirdparty.builder.assist as an issue or pull-request (PR) on thirdparty.builder.assist's Github Page.
License
MIT License
Copyright (c) 2020 third-party-dev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for thirdparty-builder-assist-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1fae2baec74f9cd3078b2f7c88435a3b9bcb4e9ec9b662f04d04a0a01e74566 |
|
MD5 | c6f01b84845421b9d94c19f8c28f61df |
|
BLAKE2b-256 | de6f84beaf3baa5c7360c20f9c4f224262335c2c5c3819134821e9735b67f634 |
Hashes for thirdparty_builder_assist-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5644b97cec9334c3754751e242299addfc86c26e28ce84511fd33430fba3b61 |
|
MD5 | 57d3b47d7bb1602aca5984bcb9dbcbe3 |
|
BLAKE2b-256 | 57968c2016cdb358b17786699de5ad4f6345c1063fdccf5ee102c2945110ea43 |