-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Explicitly add schemars to ruff_python_ast Cargo.toml #12275
Conversation
Thanks for the PR. I'm hesitant merging the PR because it's unclear to me where this feature is used (I can't find any usage in our code). Ideally we would change the usage rather than the features exposed by the crate. |
Do you have a link to the CI log where the build on nix fails? I wonder what command it is using |
Here is the entire log. I am afraid that it won't help you much more than the error message I shared. It is weird, because manually running the exact same |
After a bit more of digging, this is my best guess of what's going on. According to Features - The Cargo Book:
But, it also says that:
Which is exactly what's happening here: [features]
serde = ["dep:serde", "ruff_text_size/serde", "dep:ruff_cache", "compact_str/serde", "dep:ruff_macros", "dep:schemars"] This is what the error is complaining about :
Adding But why is this happening? I have no clue 🤷 schemars is apparently needed in #[cfg(feature = "serde")]
impl schemars::JsonSchema for Name {
fn is_referenceable() -> bool {
String::is_referenceable()
}
... Because when I remove [features]
-serde = ["dep:serde", "ruff_text_size/serde", "dep:ruff_cache", "compact_str/serde", "dep:ruff_macros", "dep:schemars"]
+serde = ["dep:serde", "ruff_text_size/serde", "dep:ruff_cache", "compact_str/serde", "dep:ruff_macros"] That's where it complains about it being missing in ruff.log But even though schemars is included as a dep of serde, it's not being used. In other crates like ruff_python_formatter, we can see that schemars is defined independently from serde, so I don't know why it's different for Note: Another solution is to make schemars non-optional: non-optional-schemars.patch---
crates/ruff_python_ast/Cargo.toml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/crates/ruff_python_ast/Cargo.toml b/crates/ruff_python_ast/Cargo.toml
index bd41c71b6..e4e8e4304 100644
--- a/crates/ruff_python_ast/Cargo.toml
+++ b/crates/ruff_python_ast/Cargo.toml
@@ -25,12 +25,12 @@ is-macro = { workspace = true }
itertools = { workspace = true }
once_cell = { workspace = true }
rustc-hash = { workspace = true }
-schemars = { workspace = true, optional = true }
+schemars = { workspace = true }
serde = { workspace = true, optional = true }
compact_str = { workspace = true }
[features]
-serde = ["dep:serde", "ruff_text_size/serde", "dep:ruff_cache", "compact_str/serde", "dep:ruff_macros", "dep:schemars"]
+serde = ["dep:serde", "ruff_text_size/serde", "dep:ruff_cache", "compact_str/serde", "dep:ruff_macros"]
[lints]
workspace = true
--
2.45.1 |
Your analysis is correct. The part that I don't understand is that the error can only occur if some code adds a dependency to I haven't found any code that enables that feature or requires that feature from |
I finally found an explanation of why this is happening, from parcel-bundler/lightningcss#713 (comment):
As proposed by the PR above, to fix this issues for cargo-auditable, it's enough to just remove the [features]
-serde = ["dep:serde", "ruff_text_size/serde", "dep:ruff_cache", "compact_str/serde", "dep:ruff_macros", "dep:schemars"]
+serde = ["dep:serde", "ruff_text_size/serde", "dep:ruff_cache", "compact_str/serde", "dep:ruff_macros", "schemars"] With this, ruff compiled successfully both manually (with cargo) and in nixpkgs (with cargo-auditable). I tracked the main issue behind this down to rust-secure-code/cargo-auditable#124 which appears to be caused by cargo in which it passes the wrong features to cargo-auditable. It would be nice to fix this in ruff, but I'm also worried that it would be confusing as What do you think @MichaReiser @GaetanLepage ? |
Wow nice find! I think what I'll do is to split the feature into three:
Which is also more consistent with other crates and should reduce the risk of breaking in the future because someone readds the dep prefix |
Thanks so much @eljamm for this amazing deep dive ! |
I'll leave that call to @MichaReiser if he wants to add this change now or wait until he implements his suggestion. |
The exact command to reproduce the error is |
Summary
Context: Updating ruff from 0.5.0 to 0.5.1 on nixpkgs.
We noticed that since 5109b50,
ruff
was not building successfully in our pipeline:This patch by @eljamm seems to fix it on our end.
Test Plan
We were able to build
ruff
0.5.1 with this patch and its test suite is passing.