Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve debug #242

Merged
merged 7 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements/linting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pathspec==0.10.1
# via black
platformdirs==2.5.2
# via black
ruff==0.0.130
ruff==0.0.285
# via -r requirements/linting.in
sniffio==1.3.0
# via trio
Expand Down
18 changes: 14 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ impl RustNotify {

let event_handler = move |res: NotifyResult<Event>| match res {
Ok(event) => {
if debug {
eprintln!("raw-event: {:?}", event);
}
if let Some(path_buf) = event.paths.first() {
let path = match path_buf.to_str() {
Some(s) => s.to_string(),
Expand Down Expand Up @@ -154,9 +151,22 @@ impl RustNotify {
}
}
EventKind::Remove(_) => CHANGE_DELETED,
_ => return,
event_kind => {
if debug {
eprintln!(
"raw-event={:?} event.kind={:?} no change detected",
event_kind, event_kind
);
}
return;
}
};
if debug {
eprintln!("raw-event={:?} change={:?}", event, change);
}
changes_clone.lock().unwrap().insert((change, path));
} else if debug {
eprintln!("raw-event={:?} no paths found", event);
}
}
Err(e) => {
Expand Down
5 changes: 4 additions & 1 deletion tests/test_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ async def test_awatch_no_yield(mock_rust_notify: 'MockRustType', caplog):

assert changes == {(Change.added, 'spam.py')}
assert mock.watch_count == 2
assert caplog.text == "watchfiles.main DEBUG: 1 change detected: {(<Change.added: 1>, 'spam.py')}\n"
assert caplog.text == (
"watchfiles.main DEBUG: all changes filtered out, raw_changes={(1, 'spam.pyc')}\n"
"watchfiles.main DEBUG: 1 change detected: {(<Change.added: 1>, 'spam.py')}\n"
)


def test_watch_timeout(mock_rust_notify: 'MockRustType', caplog):
Expand Down
4 changes: 4 additions & 0 deletions watchfiles/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ def watch(
if changes:
_log_changes(changes)
yield changes
else:
logger.debug('all changes filtered out, raw_changes=%s', raw_changes)


async def awatch( # noqa C901
Expand Down Expand Up @@ -259,6 +261,8 @@ async def stop_soon():
if changes:
_log_changes(changes)
yield changes
else:
logger.debug('all changes filtered out, raw_changes=%s', raw_changes)


def _prep_changes(
Expand Down