mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-13 09:12:40 +00:00
Use raw watcher
This commit is contained in:
parent
611037bbd4
commit
1768c4b7d3
1 changed files with 12 additions and 9 deletions
|
|
@ -1,12 +1,12 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::Instant;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{Parser, ValueHint};
|
use clap::{Parser, ValueHint};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use log::{debug, error};
|
use log::{debug, error};
|
||||||
use notify::{watcher, RecursiveMode, Watcher};
|
use notify::{raw_watcher, RecursiveMode, Watcher};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use walkdir::DirEntry;
|
use walkdir::DirEntry;
|
||||||
|
|
||||||
|
|
@ -98,21 +98,24 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
// Configure the file watcher.
|
// Configure the file watcher.
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
let mut watcher = watcher(tx, Duration::from_secs(2))?;
|
let mut watcher = raw_watcher(tx)?;
|
||||||
for file in &cli.files {
|
for file in &cli.files {
|
||||||
watcher.watch(file, RecursiveMode::Recursive)?;
|
watcher.watch(file, RecursiveMode::Recursive)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match rx.recv() {
|
match rx.recv() {
|
||||||
Ok(_) => {
|
Ok(e) => {
|
||||||
// Re-run on all change events.
|
if let Some(path) = e.path {
|
||||||
|
if path.to_string_lossy().ends_with(".py") {
|
||||||
clearscreen::clear()?;
|
clearscreen::clear()?;
|
||||||
tell_user!("File change detected...\n");
|
tell_user!("File change detected...\n");
|
||||||
|
|
||||||
let messages = run_once(&cli.files, !cli.no_cache)?;
|
let messages = run_once(&cli.files, !cli.no_cache)?;
|
||||||
report_continuously(&messages)?;
|
report_continuously(&messages)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(e) => return Err(e.into()),
|
Err(e) => return Err(e.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue