fix(cli): init --update should not update setup.py after replacing it (#5760)

This commit is contained in:
Philipp 2026-07-17 23:53:14 +02:00 committed by GitHub
parent 8b7c213443
commit 8fe4f218fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1215,22 +1215,23 @@ fn update_python_setup_py(path: &Path, language_name: &str, opts: &GenerateOpts)
if !contents.contains("build_ext") {
info!("Replacing setup.py");
generate_file(path, SETUP_PY_TEMPLATE, language_name, opts)?;
}
if !contents.contains(" and not get_config_var") {
info!("Updating Python free-threading support in setup.py");
contents = contents.replace(
r#"startswith("cp"):"#,
r#"startswith("cp") and not get_config_var("Py_GIL_DISABLED"):"#,
);
write_file(path, &contents)?;
}
if !contents.contains("include(\"src/*.c\")") {
info!("Updating sdist file list in setup.py");
let contents = contents.replace(
"include(\"src/tree_sitter/*.h\")",
"include(\"src/tree_sitter/*.h\")\n self.filelist.include(\"src/*.c\")",
);
write_file(path, &contents)?;
} else {
if !contents.contains(" and not get_config_var") {
info!("Updating Python free-threading support in setup.py");
contents = contents.replace(
r#"startswith("cp"):"#,
r#"startswith("cp") and not get_config_var("Py_GIL_DISABLED"):"#,
);
write_file(path, &contents)?;
}
if !contents.contains("include(\"src/*.c\")") {
info!("Updating sdist file list in setup.py");
let contents = contents.replace(
"include(\"src/tree_sitter/*.h\")",
"include(\"src/tree_sitter/*.h\")\n self.filelist.include(\"src/*.c\")",
);
write_file(path, &contents)?;
}
}
Ok(())
}