Skip to content

Commit f10b76f

Browse files
committed
remove *.pyc during rustpython-pylib build
1 parent 2efc566 commit f10b76f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pylib/build.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
fn main() {
2-
rerun_if_changed("../Lib/python_builtins/*");
2+
process_python_libs("../Lib/python_builtins/*");
33

44
#[cfg(not(feature = "stdlib"))]
5-
rerun_if_changed("../Lib/core_modules/*");
5+
process_python_libs("../Lib/core_modules/*");
66

77
#[cfg(feature = "stdlib")]
8-
rerun_if_changed("../../Lib/**/*");
8+
process_python_libs("../../Lib/**/*");
99

1010
if cfg!(windows) {
1111
if let Ok(real_path) = std::fs::read_to_string("Lib") {
@@ -14,14 +14,18 @@ fn main() {
1414
}
1515
}
1616

17-
fn rerun_if_changed(pattern: &str) {
17+
// remove *.pyc files and add *.py to watch list
18+
fn process_python_libs(pattern: &str) {
1819
let glob = glob::glob(pattern).unwrap_or_else(|e| panic!("failed to glob {pattern:?}: {e}"));
1920
for entry in glob.flatten() {
2021
if entry.is_dir() {
2122
continue;
2223
}
2324
let display = entry.display();
2425
if display.to_string().ends_with(".pyc") {
26+
if std::fs::remove_file(&entry).is_err() {
27+
println!("cargo:warning=failed to remove {display}")
28+
}
2529
continue;
2630
}
2731
println!("cargo:rerun-if-changed={display}");

0 commit comments

Comments
 (0)