Skip to main content

python-watcher

I've crated this project to watch over a repo dir and execute a file after modifying anything on that same dir. Its lightweight since it only has watchdog as a dependency.

Parameters for running

-d or --dir (str, required): 
    Folder you want the watcher to look for changes. Defaults to "."
-f or --file (str, required): 
    Script that you want to run after a file is changed (probably you main.py or something similar)
-t or --time (int, optional):
    Time delay to run again (good when saving constantly). Defaults to 1.
--test (bool, optional):
    If the watcher should run pytest command instead of python. Defaults to False.
--lint (bool, optional):
    If the watcher should run pylint command instead of python. Defaults to False.
--lint_src (str, optional):
    where the linter should be run (so it does not run into unwanted files).
--lint_threshold (float, optional):
    Threshold for Pylint to fail. Defaults to None (no threshold).

To run

Watching and executing a python script:

# watch changes in the directory "." and execute watcher.py
watcher -d . -f watcher.py

# watch changes only in the file watcher.py
watcher -f watcher.py

# watching and executing pytest
watcher --test

# watching and executing pylint only for "src" directory with a threshold with 90%
watcher --lint --lint_src src --lint_threshold 9

For dependencies all you need to do is run

Install from PyPi

pip install watcher-cli

Or from source:

git clone https://github.com/NathanGavenski/python-watcher
cd python-watcher
pip install -e .

Use cases

Although trivial, there are some uses cases that made me create this package:

  • Run pytest when saving a file.
  • Run pylint when making corrections.
  • Run smaller scripts after every modification.

Mostly I was tired off having to tab out from vim just to run pytest/pylint/python on the terminal.

Todo

  • create a proper setup
  • make it executable from command line
  • be able to pass parameters
  • read parameters from yaml file
  • only watch a single file changes
  • run pytest
  • run pylint
    • to run pylint there has to be a folder to run pylint over
    • fail with some threshold
  • Spawn a new process to close if needed (more control over running process)
  • Create documentation
  • Create tests
  • Publish
  • Fix pytest not working on GitHub actions

Metadata

Release files for watcher-cli 0.1.0

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

Source distribution (sdist)

Source distribution for watcher-cli 0.1.0
File Size Uploaded Provenance Actions
watcher_cli-0.1.0.tar.gz 7.1 kB Without provenance Details for watcher_cli-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for watcher-cli 0.1.0
File Interpreter ABI Platform Actions
watcher_cli-0.1.0-py3-none-any.whl Python 3 none any Details for watcher_cli-0.1.0-py3-none-any.whl

Total release size: 14.0 kB

Release files / watcher_cli-0.1.0.tar.gz

Download URL watcher_cli-0.1.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8ce68e6c61b7853e038152f4bbc27aef2bf05ccf1987f9972fe2bfef2e91f07a
BLAKE2b-256 checksum
How to use checksums
9c03aafd1d61d68c1629ad790481a10d2b3f83a192015c55a627e613411e67a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / watcher_cli-0.1.0-py3-none-any.whl

Download URL watcher_cli-0.1.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5cc8f5598a7a3e57d07408079d3c97f8b0ec222fdb98a341f894c4edb9891677
BLAKE2b-256 checksum
How to use checksums
4f48d9c11172d40ee218efdec08d49d8b267c735e09bae1bb8b99fb9439001c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Security for watcher-cli 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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