Skip to content

Commit c5bfceb

Browse files
committed
fix(wheels): drop unused python deps, GraphML \r, walkdir+wait-timeout
1 parent b62980b commit c5bfceb

7 files changed

Lines changed: 50 additions & 87 deletions

File tree

diffctx/Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

diffctx/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,13 @@ rustc-hash = "2"
117117
similar = "2"
118118
glob = "0.3"
119119
smallvec = "1"
120+
walkdir = "2"
121+
wait-timeout = "0.2"
120122
pyo3 = { version = "0.24", features = ["extension-module", "abi3-py310"], optional = true }
121123

122124
[dev-dependencies]
123125
tempfile = "3"
124126
serde_yaml = "0.9"
125-
walkdir = "2"
126127
libtest-mimic = "0.7"
127128

128129
[[test]]

diffctx/src/candidate_files.rs

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::path::{Path, PathBuf};
22

33
use rayon::prelude::*;
44
use rustc_hash::FxHashSet;
5+
use walkdir::WalkDir;
56

67
use crate::config::graph_filtering::GRAPH_FILTERING;
78
use crate::config::limits::LIMITS;
@@ -45,45 +46,34 @@ pub fn collect_candidate_files(root_dir: &Path, included_set: &FxHashSet<PathBuf
4546
}
4647

4748
let mut fallback: Vec<PathBuf> = Vec::new();
48-
if let Ok(entries) = walkdir(root_dir) {
49-
for f in entries {
50-
if fallback.len() >= GRAPH_FILTERING.fallback_max_files {
51-
break;
49+
for entry in WalkDir::new(root_dir)
50+
.sort_by_file_name()
51+
.into_iter()
52+
.filter_entry(|e| {
53+
if e.depth() == 0 || !e.file_type().is_dir() {
54+
return true;
5255
}
53-
if is_candidate_file(&f, root_dir, included_set) {
54-
fallback.push(f);
56+
match e.file_name().to_str() {
57+
Some(name) => {
58+
!name.starts_with('.') && name != "node_modules" && name != "__pycache__"
59+
}
60+
None => true,
5561
}
62+
})
63+
.filter_map(|e| e.ok())
64+
{
65+
if !entry.file_type().is_file() {
66+
continue;
5667
}
57-
}
58-
fallback
59-
}
60-
61-
fn walkdir(root: &Path) -> std::io::Result<Vec<PathBuf>> {
62-
let mut result = Vec::new();
63-
walk_recursive(root, &mut result)?;
64-
Ok(result)
65-
}
66-
67-
fn walk_recursive(dir: &Path, result: &mut Vec<PathBuf>) -> std::io::Result<()> {
68-
let mut entries: Vec<PathBuf> = std::fs::read_dir(dir)?
69-
.filter_map(|e| e.ok().map(|e| e.path()))
70-
.collect();
71-
entries.sort();
72-
for path in entries {
73-
if path.is_dir() {
74-
let name = path
75-
.file_name()
76-
.map(|n| n.to_string_lossy().to_string())
77-
.unwrap_or_default();
78-
if name.starts_with('.') || name == "node_modules" || name == "__pycache__" {
79-
continue;
80-
}
81-
walk_recursive(&path, result)?;
82-
} else {
83-
result.push(path);
68+
if fallback.len() >= GRAPH_FILTERING.fallback_max_files {
69+
break;
70+
}
71+
let path = entry.into_path();
72+
if is_candidate_file(&path, root_dir, included_set) {
73+
fallback.push(path);
8474
}
8575
}
86-
Ok(())
76+
fallback
8777
}
8878

8979
pub fn normalize_path(path: &Path, root_dir: &Path) -> PathBuf {

diffctx/src/git.rs

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::time::Duration;
88
use once_cell::sync::Lazy;
99
use regex::Regex;
1010
use rustc_hash::FxHashSet;
11+
use wait_timeout::ChildExt;
1112

1213
use crate::config::git::{self, GIT};
1314
use crate::types::DiffHunk;
@@ -105,19 +106,12 @@ fn wait_with_timeout(
105106
})
106107
});
107108

108-
let start = std::time::Instant::now();
109-
let status = loop {
110-
match child.try_wait() {
111-
Ok(Some(status)) => break status,
112-
Ok(None) => {
113-
if start.elapsed() >= timeout {
114-
let _ = child.kill();
115-
let _ = child.wait();
116-
return Err(GitError::Timeout(timeout.as_secs()));
117-
}
118-
std::thread::sleep(Duration::from_millis(GIT.poll_interval_ms));
119-
}
120-
Err(e) => return Err(GitError::Io(e)),
109+
let status = match child.wait_timeout(timeout)? {
110+
Some(status) => status,
111+
None => {
112+
let _ = child.kill();
113+
let _ = child.wait();
114+
return Err(GitError::Timeout(timeout.as_secs()));
121115
}
122116
};
123117

@@ -576,8 +570,8 @@ impl CatFileBatch {
576570
if let Some(mut child) = self.child.take() {
577571
drop(child.stdin.take());
578572
match child.wait_timeout(Duration::from_secs(GIT.catfile_termination_timeout_seconds)) {
579-
Ok(_) => {}
580-
Err(_) => {
573+
Ok(Some(_)) => {}
574+
_ => {
581575
let _ = child.kill();
582576
let _ = child.wait();
583577
}
@@ -591,25 +585,3 @@ impl Drop for CatFileBatch {
591585
self.close();
592586
}
593587
}
594-
595-
trait WaitTimeout {
596-
fn wait_timeout(&mut self, dur: Duration) -> std::result::Result<std::process::ExitStatus, ()>;
597-
}
598-
599-
impl WaitTimeout for Child {
600-
fn wait_timeout(&mut self, dur: Duration) -> std::result::Result<std::process::ExitStatus, ()> {
601-
let start = std::time::Instant::now();
602-
loop {
603-
match self.try_wait() {
604-
Ok(Some(status)) => return Ok(status),
605-
Ok(None) => {
606-
if start.elapsed() >= dur {
607-
return Err(());
608-
}
609-
std::thread::sleep(Duration::from_millis(GIT.poll_interval_ms));
610-
}
611-
Err(_) => return Err(()),
612-
}
613-
}
614-
}
615-
}

diffctx/src/graph_export.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ fn escape_graphml(text: &str) -> String {
234234
'>' => out.push_str("&gt;"),
235235
'"' => out.push_str("&quot;"),
236236
'\'' => out.push_str("&apos;"),
237+
'\r' => out.push_str("&#xD;"),
237238
other => out.push(other),
238239
}
239240
}

pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ classifiers = [
5454
]
5555
dynamic = [ "version" ] # Version is still managed in version.py
5656
dependencies = [
57-
"networkx>=3.0,<4.0",
5857
"numpy>=1.24,<3.0",
5958
"pathspec>=0.11,<2.0",
60-
"tiktoken==0.12.0",
6159
]
6260
optional-dependencies.dev = [
6361
"black>=23.0.0,<27.0",
@@ -84,9 +82,9 @@ optional-dependencies.dev = [
8482
"ruamel-yaml>=0.18,<1.0",
8583
# Quality checks
8684
"ruff>=0.4,<1.0",
85+
"tiktoken==0.12.0",
8786
"treemapper[tree-sitter]",
8887
# Type stubs
89-
"types-networkx>=3.0,<4.0",
9088
"types-pyyaml>=6.0,<7.0",
9189
]
9290
optional-dependencies.embeddings = [

src/treemapper/writer.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -373,24 +373,15 @@ def _write_to_file_path(output_file: Path, writer: Callable[[TextIO], None]) ->
373373
os.fsync(f.fileno())
374374
os.replace(tmp_path, output_file)
375375
except PermissionError:
376-
try:
377-
os.unlink(tmp_path)
378-
except OSError:
379-
pass
376+
Path(tmp_path).unlink(missing_ok=True)
380377
logger.error("Unable to write to file '%s': permission denied", output_file)
381378
raise
382379
except OSError as e:
383-
try:
384-
os.unlink(tmp_path)
385-
except OSError:
386-
pass
380+
Path(tmp_path).unlink(missing_ok=True)
387381
logger.error("Unable to write to file '%s': %s", output_file, e)
388382
raise
389383
except BaseException:
390-
try:
391-
os.unlink(tmp_path)
392-
except OSError:
393-
pass
384+
Path(tmp_path).unlink(missing_ok=True)
394385
raise
395386

396387

0 commit comments

Comments
 (0)