Skip to main content

A watcher for running python code when after every modification

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

watcher-cli-0.0.2.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

watcher_cli-0.0.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file watcher-cli-0.0.2.tar.gz.

File metadata

  • Download URL: watcher-cli-0.0.2.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for watcher-cli-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4ff42f4a9509f73811f5b13445a206c2a4f29ce25c8d38c4b15138dfbb2813f2
MD5 23d831ac927b9d41904298012eedee85
BLAKE2b-256 67b20219ab1f4272eb479c125cf84a9998c75461a4c458943ddf7fea1561ed81

See more details on using hashes here.

File details

Details for the file watcher_cli-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: watcher_cli-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for watcher_cli-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9aa79575797d091b57ff4524b7c8cb0ba5b53bce382f27e58e256aae562d214c
MD5 f699cd08e982649ad9b17c7f3c4fbde1
BLAKE2b-256 e1606548e2da8ad9306ac9083331f74ad804b4da575bfe0ac50093afe39aa29d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page