Skip to content

Bug fixes, new features and test suite#101

Closed
eviweb wants to merge 14 commits intojoh:masterfrom
eviweb:master
Closed

Bug fixes, new features and test suite#101
eviweb wants to merge 14 commits intojoh:masterfrom
eviweb:master

Conversation

@eviweb
Copy link
Contributor

@eviweb eviweb commented Mar 16, 2026

This PR addresses several open issues and adds new features.

Bug fixes

New features

Tests

  • Add tests #80 Add a test suite of 69 tests covering:
    • is_interested() and exclusion patterns
    • all event handlers (on_created, on_modified, on_moved, on_deleted)
    • debounce behavior
    • run_command() including -1, -k, quiet mode
    • CLI argument parsing for all flags
    • -p pattern filtering

Other

  • Update README.md to document new options with examples
  • Fix entry_points in setup.py (tuple → list)
  • Drop Python 2 / subprocess32 dependency
  • Add pyproject.toml with modern build system configuration
  • Update Usage: line in docstring to [OPTIONS]

PowerKiKi and others added 14 commits March 13, 2026 11:04
At least on Ubuntu 24.04, `pip` would error out with `error: externally-managed-environment`. According to the following SO, the proper way for an application that should be globally available, is to use `pipx` instead.

See https://stackoverflow.com/a/78652149/37706
Replace [px]* with [a-z] to match all vim swap extensions
(.swo, .swn, .swm, etc.) not just .swp and .swx.

Signed-off-by: Eric Villard <dev@eviweb.fr>
inotify fires both created and modified events when a file is created.
Previously on_created was entirely skipped for InotifyObserver, which
caused two bugs:
- files moved into a watched directory did not trigger the command (joh#68)
- WHEN_CHANGED_EVENT was never set to file_created on Linux (joh#76)

Fix: track recently created paths in a set and skip the redundant
modified event, instead of ignoring created events entirely.
last_run was recorded after subprocess.call(), so any file change
occurring during command execution had mtime > last_run and triggered
a re-run. Also the comparison used < instead of <=.

Fix: record last_run before subprocess.call() so that changes during
execution are correctly ignored on the next event.
Add modern pyproject.toml with build-system configuration.
Remove obsolete subprocess32 from requirements (Python 2 only).
A wheel can now be built with: python3 -m build
Signed-off-by: Eric Villard <dev@eviweb.fr>
-k: kill the currently running command before restarting it,
    useful for long-running processes (servers, watchers).
    Uses SIGTERM with 5s timeout fallback to SIGKILL.

-d DELAY: wait DELAY seconds before running the command,
    coalescing rapid successive changes into a single run.
    Uses threading.Timer, each new event resets the timer.
- Bump version to 0.4.0
- Fix entry_points: use list instead of tuple in setup.py
- Update Python requirement to 3.6+ (drop Python 2)
- Update installation URL to eviweb fork
- Document new -k and -d options in README
Replace set with dict (path -> timestamp). On each on_modified,
purge entries older than 1s before checking. Handles the case where
on_modified never fires after on_created (e.g. empty file creation)."

Signed-off-by: Eric Villard <dev@eviweb.fr>
Covers: is_interested(), event handlers, debounce, run_command,
CLI parsing. Also documents regex bug in backup file exclusion (.~$)."

Signed-off-by: Eric Villard <dev@eviweb.fr>
r'.~\$' matched any char before ~ due to unescaped dot.
Corrected to r'\.~\$' to match only literal dot (e.g. file.py~)."

Signed-off-by: Eric Villard <dev@eviweb.fr>
New option -p PATTERN (glob) restricts reactions to files whose
basename matches the pattern. Can be repeated for multiple patterns.
No -p means watch all files (existing behavior preserved).

Uses fnmatch for glob matching (*, ?, [...] supported).
Pattern check is applied in is_interested() after exclude rules,
so excluded files (vim swap, .git, etc.) are never triggered
regardless of patterns.

Examples:
  when-changed -r -p '*.py' src/ make test
  when-changed -r -p '*.py' -p '*.yml' src/ make lint

Signed-off-by: Eric Villard <dev@eviweb.fr>
@eviweb
Copy link
Contributor Author

eviweb commented Mar 16, 2026

Closing in favor of a cleaner PR opened from a dedicated branch.
The new PR excludes version bumps and contains a rebased, clean commit history.

@eviweb eviweb closed this Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants