pantsbuild / pants

The Pants Build System
https://www.pantsbuild.org
Apache License 2.0
3.2k stars 616 forks source link

Proposal: manage unstable/experimental/preview features with central "feature flags" #20987

Open huonw opened 1 month ago

huonw commented 1 month ago

Is your feature request related to a problem? Please describe.

Currently features that aren't ready for prime time have names that indicate this, e.g. experimental_test_shell_command target. environments-preview subsystem, pants.backend.experimental.tools.semgrep backend.

This has good attributes:

But, it has a few downsides:

Describe the solution you'd like

Something like cargo-feature flags in Rust's Cargo: a configuration variable that indicates which unstable features the user has opted in to. (This is also similar to the `#![feature(...)] attribute for unstable feature flags in Rust code itself: 1, 2). In particular, one adds a single element to the list to acknowledge "I understand this is unstable" and then can forge ahead using that feature in Cargo as normal. When the feature is stabilised, the only update required is to remove the element from the list, no matter how many times the code uses the feature in question.

A similar thing could work in Pants:

This leads to a few behaviours:

Example

Suppose we've implemented this feature, and renamed the experimental features above. Then we might have a repo with configuration like:

# pants.toml
[GLOBAL]
pants_version = "2.34.0"

backend_packages = [
  "pants.backend.shell", # provides `test_shell_command` etc.
  "pants.backend.tools.semgrep", # preview! 
]

[environments.names] # preview!
a = "b"
# BUILD
shell_command(...) # from pants.backend.shell, NOT preview
test_shell_command(...) # from pants.backend.shell, preview

Running pants against that configuration might emit errors like:

The pants.backend.experimental.tools.semgrep backend is in preview, and may change without notice in future. To opt-in to this, please include "semgrep" in the [GLOBAL].preview_features_opt_in list. See \ for more details.

The environments feature is in preview, and may change without notice in future. To opt-in to this, please include "environments" in the [GLOBAL].preview_features_opt_in list. See \ for more details.

The test_shell_command target is in preview, and may change without notice in future. To opt-in to this, please include "test_shell_command" in the [GLOBAL].preview_features_opt_in list. See \ for more details.

(The (optional?) link could be to a https://github.com/pantsbuild/pants/labels/stablization tracking issue.)

Then, as prompted, the user could adjust their pants.toml to:

# pants.toml
[GLOBAL]
pants_version = "2.34.0"

preview_features_opt_in = ["semgrep", "environments", "test_shell_command"]

# ... no other changes ...

This is of course normal TOML, so users can add comments with more discussion about each feature as required.

Describe alternatives you've considered

Additional context

N/A

sureshjoshi commented 1 month ago

I particularly like this idea as it would mean non-breaking changes when features become stable - which is one gripe I have with the current system. As in, a CLI command you used (or a target) might no longer be that thing (automatic migrations aside).

Rust and Cargo only allow using experimental features in nightly builds Yep, HARD pass here - for a language, I can see it. For a library/tool - it would be rough.

What happens when the a feature goes stable, and the "opt_in" flag is still present? I assume it will run, but just mention that flag is redundant?

benjyw commented 1 month ago

I like it a lot! Upvote from me .

cburroughs commented 1 month ago

This isn't directly related, something I've wanted a few times is "experimental flags". I don't think there is anything stopping this today, but it would be nice to have a pattern that was --experimental-super-long-string