mirror of https://github.com/astral-sh/ruff
[red-knot] Typeshed patching: use build.rs instead of workflow (#15370)
## Summary The symlink-approach in the typeshed-sync workflow caused some problems on Windows, even though it seemed to work fine in CI: https://github.com/astral-sh/ruff/pull/15138#issuecomment-2578642129 Here, we rely on `build.rs` to patch typeshed instead, which allows us to get rid of the modifications in the workflow (thank you @MichaReiser for the idea). ## Test Plan - Made sure that changes to `knot_extensions.pyi` result in a recompile of `red_knot_vendored`.
This commit is contained in:
parent
f706c3fdf2
commit
097aa04c04
|
|
@ -46,10 +46,6 @@ jobs:
|
||||||
cp -r typeshed/stdlib ruff/crates/red_knot_vendored/vendor/typeshed/stdlib
|
cp -r typeshed/stdlib ruff/crates/red_knot_vendored/vendor/typeshed/stdlib
|
||||||
rm -rf ruff/crates/red_knot_vendored/vendor/typeshed/stdlib/@tests
|
rm -rf ruff/crates/red_knot_vendored/vendor/typeshed/stdlib/@tests
|
||||||
git -C typeshed rev-parse HEAD > ruff/crates/red_knot_vendored/vendor/typeshed/source_commit.txt
|
git -C typeshed rev-parse HEAD > ruff/crates/red_knot_vendored/vendor/typeshed/source_commit.txt
|
||||||
# Patch the typeshed stubs to include `knot_extensions`
|
|
||||||
ln -s ../../../knot_extensions/knot_extensions.pyi ruff/crates/red_knot_vendored/vendor/typeshed/stdlib/
|
|
||||||
echo "# Patch applied for red_knot:" >> ruff/crates/red_knot_vendored/vendor/typeshed/stdlib/VERSIONS
|
|
||||||
echo "knot_extensions: 3.0-" >> ruff/crates/red_knot_vendored/vendor/typeshed/stdlib/VERSIONS
|
|
||||||
- name: Commit the changes
|
- name: Commit the changes
|
||||||
id: commit
|
id: commit
|
||||||
if: ${{ steps.sync.outcome == 'success' }}
|
if: ${{ steps.sync.outcome == 'success' }}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
//! in `crates/red_knot_vendored/vendor/typeshed` change.
|
//! in `crates/red_knot_vendored/vendor/typeshed` change.
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use path_slash::PathExt;
|
use path_slash::PathExt;
|
||||||
|
|
@ -14,6 +15,7 @@ use zip::write::{FileOptions, ZipWriter};
|
||||||
use zip::CompressionMethod;
|
use zip::CompressionMethod;
|
||||||
|
|
||||||
const TYPESHED_SOURCE_DIR: &str = "vendor/typeshed";
|
const TYPESHED_SOURCE_DIR: &str = "vendor/typeshed";
|
||||||
|
const KNOT_EXTENSIONS_STUBS: &str = "knot_extensions/knot_extensions.pyi";
|
||||||
const TYPESHED_ZIP_LOCATION: &str = "/zipped_typeshed.zip";
|
const TYPESHED_ZIP_LOCATION: &str = "/zipped_typeshed.zip";
|
||||||
|
|
||||||
/// Recursively zip the contents of an entire directory.
|
/// Recursively zip the contents of an entire directory.
|
||||||
|
|
@ -55,9 +57,14 @@ fn zip_dir(directory_path: &str, writer: File) -> ZipResult<File> {
|
||||||
// Some unzip tools unzip files with directory paths correctly, some do not!
|
// Some unzip tools unzip files with directory paths correctly, some do not!
|
||||||
if absolute_path.is_file() {
|
if absolute_path.is_file() {
|
||||||
println!("adding file {absolute_path:?} as {normalized_relative_path:?} ...");
|
println!("adding file {absolute_path:?} as {normalized_relative_path:?} ...");
|
||||||
zip.start_file(normalized_relative_path, options)?;
|
zip.start_file(&*normalized_relative_path, options)?;
|
||||||
let mut f = File::open(absolute_path)?;
|
let mut f = File::open(absolute_path)?;
|
||||||
std::io::copy(&mut f, &mut zip).unwrap();
|
std::io::copy(&mut f, &mut zip).unwrap();
|
||||||
|
|
||||||
|
// Patch the VERSIONS file to make `knot_extensions` available
|
||||||
|
if normalized_relative_path == "stdlib/VERSIONS" {
|
||||||
|
writeln!(&mut zip, "knot_extensions: 3.0-")?;
|
||||||
|
}
|
||||||
} else if !normalized_relative_path.is_empty() {
|
} else if !normalized_relative_path.is_empty() {
|
||||||
// Only if not root! Avoids path spec / warning
|
// Only if not root! Avoids path spec / warning
|
||||||
// and mapname conversion failed error on unzip
|
// and mapname conversion failed error on unzip
|
||||||
|
|
@ -65,11 +72,17 @@ fn zip_dir(directory_path: &str, writer: File) -> ZipResult<File> {
|
||||||
zip.add_directory(normalized_relative_path, options)?;
|
zip.add_directory(normalized_relative_path, options)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Patch typeshed and add the stubs for the `knot_extensions` module
|
||||||
|
println!("adding file {KNOT_EXTENSIONS_STUBS} as stdlib/knot_extensions.pyi ...");
|
||||||
|
zip.start_file("stdlib/knot_extensions.pyi", options)?;
|
||||||
|
let mut f = File::open(KNOT_EXTENSIONS_STUBS)?;
|
||||||
|
std::io::copy(&mut f, &mut zip).unwrap();
|
||||||
|
|
||||||
zip.finish()
|
zip.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("cargo::rerun-if-changed={TYPESHED_SOURCE_DIR}");
|
|
||||||
assert!(
|
assert!(
|
||||||
Path::new(TYPESHED_SOURCE_DIR).is_dir(),
|
Path::new(TYPESHED_SOURCE_DIR).is_dir(),
|
||||||
"Where is typeshed?"
|
"Where is typeshed?"
|
||||||
|
|
|
||||||
|
|
@ -341,5 +341,3 @@ zipfile._path: 3.12-
|
||||||
zipimport: 3.0-
|
zipimport: 3.0-
|
||||||
zlib: 3.0-
|
zlib: 3.0-
|
||||||
zoneinfo: 3.9-
|
zoneinfo: 3.9-
|
||||||
# Patch applied for red_knot:
|
|
||||||
knot_extensions: 3.0-
|
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
../../../knot_extensions/knot_extensions.pyi
|
|
||||||
Loading…
Reference in New Issue