Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot] Typeshed patching: use build.rs instead of workflow #15370

Merged
merged 2 commits into from
Jan 9, 2025

Conversation

sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Jan 9, 2025

Summary

The symlink-approach in the typeshed-sync workflow caused some problems on Windows, even though it seemed to work fine in CI.

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).

Test Plan

  • Made sure that changes to knot_extensions.pyi result in a recompile of red_knot_vendored.

@sharkdp sharkdp added internal An internal refactor or improvement red-knot Multi-file analysis & type inference labels Jan 9, 2025
@sharkdp sharkdp force-pushed the david/typeshed_sync-copy-instead-of-symlink branch from f460e0f to 35f55f4 Compare January 9, 2025 09:35
Comment on lines 51 to 61
source="crates/red_knot_vendored/knot_extensions/knot_extensions.pyi"
target="crates/red_knot_vendored/vendor/typeshed/stdlib/knot_extensions.pyi"
(
echo "# WARNING: This file is generated by the typeshed sync workflow. Do not edit it manually."
echo "# Edit the source file at '$source' instead and then copy it over to this file."
) > "ruff/$target"
cat "ruff/$source" >> "ruff/$target"
(
echo "# Patch applied for red_knot:"
echo "knot_extensions: 3.0-"
) >> ruff/crates/red_knot_vendored/vendor/typeshed/stdlib/VERSIONS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind the approach taken here. An alternative could be to copy the file in the red_knot_vendored's build.rs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh, I like this much more. Thanks!

zip.finish()
}

fn main() {
println!("cargo::rerun-if-changed={TYPESHED_SOURCE_DIR}");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this means that we will rebuild red_knot_vendored if any file in the package has changed (ref). I need this, because knot_extensions.pyi is not in the vendor/typeshed directory, and we need to pick up changes to it.

And I don't think there's a huge drawback since there are no files in red_knot_vendored that should not trigger a rebuild except for the README.

Copy link
Contributor

github-actions bot commented Jan 9, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat

@sharkdp sharkdp changed the title [red-knot] Typeshed sync: use copy instead of symlink [red-knot] Typeshed patching: use build.rs instead of workflow Jan 9, 2025
@sharkdp sharkdp merged commit 097aa04 into main Jan 9, 2025
21 checks passed
@sharkdp sharkdp deleted the david/typeshed_sync-copy-instead-of-symlink branch January 9, 2025 10:50
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, using build.rs for this is so much cleaner!

Comment on lines +64 to +67
// Patch the VERSIONS file to make `knot_extensions` available
if normalized_relative_path == "stdlib/VERSIONS" {
writeln!(&mut zip, "knot_extensions: 3.0-")?;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I originally wrote this function, I intended to write it so that it could be used to zip up any directory into a zip archive -- that's why it's called zip_dir(), and that's why it accepts the typeshed directory path as a parameter rather than hardcoding it in the function. I think since I originally wrote it, it's already grown a few features that make it quite specific to its use-case here, such as the conditional logic a few lines above for deciding what the compression method should be. So I don't really mind much hardcoding things like "stdlib/VERSIONS" directly into the function body. But at this stage, it probably doesn't make much sense for the typeshed directory to be passed into the function as a parameter, and we should probably change the name of the function 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that, I figured it would be okay to modify in this way since it wasn't being used anywhere else and not in a place where it could be imported from anywhere else. See #15372

sharkdp added a commit that referenced this pull request Jan 9, 2025
## Summary

See #15370 (comment):

- Rename `zip_dir` to `write_zipped_typeshed_to` to clarify it's not a
generic function (anymore)
- Hard-code `TYPESHED_SOURCE_DIR` instead of using a `directory_path`
argument
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants