Added support for [tool.uv.preview-features] in TOML configs (#15767)#16452
Added support for [tool.uv.preview-features] in TOML configs (#15767)#16452j-helland wants to merge 8 commits into
Conversation
|
Some docker CI jobs failing, all due to I've checked other recent PRs and I'm seeing similar failures (example), so I suspect this is a transient issue not related to my changes. |
|
This being my first PR in |
|
Cool thanks! Some quick high-level thoughts (I haven't looked at the code yet)
I think we should actually combine them. If we get feedback that people need to be able to disable specific features, then the canonical way to do so in uv's interface would be to add a Don't worry about those Depot authentication failures — we're working with them to resolve those. |
Got it, thanks for explaining. That should be an easy fix, I’ll get to that later today. |
|
@zanieb I want to clarify one thing before submitting my revision. Suppose we pass preview = false
preview-features = ["format"]
I would intuitively expect that
|
b920a3e to
f4d3d7d
Compare
|
I pushed what made intuitive sense to me:
Happy to change this if requested! |
9b37414 to
b3dad59
Compare
|
Nice, no more Depot auth failures. I'm curious if anyone will get a chance to look at this PR? It would be nice to have this functionality at my current job. I'm sure it's very low-priority, though, so no worries. If I made any mistakes in my approach that makes this work too time-consuming to review, I'd be happy to take that feedback so I can contribute more productively to |
b3dad59 to
598773d
Compare
Preview features are specified as a list of strings in TOML, which parse to PreviewFeatures values. CLI arguments like --preview and --no-preview take precedence over config values. --preview-features combines with config values.
598773d to
46bf1ff
Compare
laundmo
left a comment
There was a problem hiding this comment.
I'm just a random python/rust dev who was looking for something like this, but to me the code looks reasonable and seems to match how other config options are written.
Would be nice to get this feature, I specifically want to enable python-upgrade globally
I think if we see a config file like preview = false
preview-features = ["format"]we should probably just fail? |
I think I'd expect us just to activate the subset of preview features specified in the CLI since the CLI takes precedence over the configuration file, though I'm not entirely sure and don't feel strongly. |
|
Sorry for the delayed review, we've just had a lot on our backlog — it's not anything you did wrong. |
That makes intuitive sense to me, but doesn't match the current behavior of the commandline arguments, where you can pass Unless I'm missing something (very possible), it seems like implementing the validation you suggest is nontrivial. The closest thing I can find is validate_uv_toml, seems like we'd have to add an entirely new validation flow. Does that sound right? Does it make sense to add that validation in this PR or in a separate effort to keep the scope here limited? I'm open to either option. |
|
I think we can be more strict in the configuration file than in the CLI.
Ah, hm. That's a little unfortunate. It does seem useful long-term though.
I think the only trouble with doing it in a separate pull request is that we don't want to release support for including both fields then "break" it in a subsequent release. Would you mind sketching it in a separate pull request and we can merge them together? |
…e fields * Instead of merging commandline `--preview-features` with config file `preview-features`, now the commandline arguments take precedence. This matches the semantics of how uv handles other commandline arguments. * Removed unnecessary `PreviewFeaturesMode` type. * Fixed bug with `PreviewFeatures` serde serializer that produced a list of lists instead of a flat list as expected.
6e70259 to
7b2c211
Compare
Sure thing! I'll try to get to that this weekend. |
|
Sorry I lost track of this over the holidays! Will revisit. |
…17670) ## Summary This PR replaces `bitflags` in favour of `enumflags2` (which we already transitively depended on) so that `PreviewFeatures` can be replaced with `PreviewFeature` which is an enum. This clarifies intent in cases where we only care about one specific `PreviewFeature`. To avoid a bunch of boilerplate changes, the `Preview` wrapper has been kept and creation now involves a `&[PreviewFeature]` in all cases. The alternative was to have everything which initialises a `Preview` use `BitFlags` directly and possibly to remove `Preview` entirely but this keeps things simpler and limits the changes throughout the rest of the codebase solely to changes which deal with the name changes (ALL_CAPS to PascalCase) and the impact on `--show-settings` which I don't believe we care about stability of output for? The changes to `--show-settings` could be avoided with some custom `Debug` implementation but that seems excessive. This PR will impact #16452. But the changes were inspired by trying to remove the need for that particular PR to add more runtime type checking. ## Test Plan Existing tests were adjusted (I also fixed some missing cases). The test for panicking in cases which are now prevented through the use of type changes has been dropped. All the rest of the tests were ran, snapshot changes reviewed and applied.
|
It hurt my soul to do a merge for this but hey, the precedent was set 🤷 . I've fixed up the conflicts with the Preview changes, as a bonus the code is cleaner and doesn't do runtime type checking anymore. I'll rebase the other PR onto this one once this one passes CI. |
5fd3464 to
8f330a6
Compare
5694446 to
44d7749
Compare
|
Work has been busy lately and I lost track of this myself! Thanks @EliteTK for fixing this up, I really like your simplifications with the I believe what remains here is deciding how to proceed with #17202 (259a9d4), specifically #17202 (comment). Happy to continue working on it if you all have feedback! |
|
There's a potential issue here that now if I have a local But that could be fixed by having That being said, I am wondering if there's justification to have It kind of breaks with the established convention we've had going in this regard with It would mean that |
That's true, that should be fixed. I agree that denormalized data leads to clunkier code here. I'd personally be fine with # boolean values
preview = true
preview = false
preview = { features = ["foo", "bar", "baz"] }as a compromise between the implementation's elegance and the clarity of having config fields correspond one-to-one with commandline args per the original design. I'll defer to you all about whether the convention is worth breaking, though. I could see a reasonable argument for the clarity of the UI taking priority here. |
|
We discussed this internally, there's a few other options which follow the same duplicate pattern, so in that regard, we are going to keep Keep Add Use |
Relates to (#15767)
Summary
Before this PR, specific preview features could only be specified via a comma-separated list in CLI
--preview-features. Now, preview features can be specified as a list of strings inpyproject.tomloruv.toml. For example,Commandline arguments (
--preview,--no-preview, and--preview-features) take precedence over config settings (tool.uv.preview,tool.uv.preview-features), which matches the semantics of other settings inuv.Alternatives Considered
From #15767 (comment):
I chose not to take this approach because it adds complexity and the semantics don't align with
uvtoday. For example,--no-previewwill currently take priority, even ifpyproject.tomlhasuv.tool.preview = true. I think drivinguvfrom the top-down like this is generally the right decision (and changing the semantics for a small feature like this would certainly not be).Test Plan
cargo nextest runcargo buildIn addition to the above, I also tried a small test project:
pyproject.tomltestFrom the
uv/project root: