-
-
Notifications
You must be signed in to change notification settings - Fork 836
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
feat: allow rust hooks to specify crate features #3235
base: main
Are you sure you want to change the base?
feat: allow rust hooks to specify crate features #3235
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rebase out the unrelated formatting changes -- those are not welcome
pre_commit/languages/rust.py
Outdated
# Features starts with "--feature=" | ||
features = { | ||
dep.replace(FEATURE_PREFIX, '') | ||
for dep in additional_dependencies | ||
if dep.startswith(FEATURE_PREFIX) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can probably just filter out anything that starts with --
or doesn't have :
?
we don't do conventional commits either, please just use a normal commit message |
Now the rust hooks can use the parameter `additional_dependencies` to receive build-time features for the crate. The features must start with the string "--feature=" following the name of the feature; e.g. "--feature=full". Fixes pre-commit#3230
19f46ae
to
bd153a6
Compare
pre_commit/languages/rust.py
Outdated
if dep.startswith(FEATURE_PREFIX): | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be here at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, the features never reach this function.
pre_commit/languages/rust.py
Outdated
@@ -130,6 +133,12 @@ def install_environment( | |||
cli_deps = { | |||
dep for dep in additional_dependencies if dep.startswith('cli:') | |||
} | |||
# Features starts with "--feature=" | |||
features = { | |||
dep.replace(FEATURE_PREFIX, '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you should need a replace(...)
-- we should be able to pass along arguments verbatim I would hope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I've implemented uses a custom syntax, so e.g. --feature=foo --feature=bar
is translated as --features foo bar
when invoking Cargo.
If I understood you correctly you want to receive arbitrary Cargo arguments in additional_dependencies
so we could pass, for example, --features foo bar --locked
.
Is that what you're suggesting?
In that case, every value in additional_dependencies
after a flag will be interpreted as a Cargo argument, because after a --features
flag we cannot distinguish between a feature name or a dependency name.
ideally I'd also like this solution to solve #3162 |
We've replaced the previous "--feature=" format with a single parameter "--" which marks the start of the "cargo install" arguments, so now we can use "-- --features foo", "-- --locked", etc. Fixes pre-commit#3162
hmmm can it work if we just treat things starting with |
Features, they have the syntax "--features feat1 feat2 feat3". |
afaict that's not valid:
it'd have to be |
@asottile The current implementation can accept any |
What about
|
I tried Why
|
pre-commit/pre_commit/languages/rust.py Lines 124 to 129 in 0f8f383
This is exactly what the feature selection for |
in 2024 yeah I'm all for killing the |
personally I'd rather be more constrained such that if we need to do something later we have the opportunity to do so rather than being stuck with "allow arbitrary arguments" decision today. not to mention completely arbitrary arguments likely allows one to break out of the intended isolation |
The reason behind this originally was to allow you to override specific library versions used to build the hook binary if needed, similar to how you can use |
I opened #3278. Thanks for the historic rationale. The cargo docs don't really preserve historic info like that, so I was completely unaware. I've only been using rust for about a year, but you could probably tell that already 😜 |
Now the rust hooks can use the parameter
additional_dependencies
to receive build-time features for the crate.The features must start with the string "--feature=" following the name of the feature; e.g. "--feature=full".
Fixes #3230