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

Allow Targets to express that fields are mutually exclusive #9561

Closed
Eric-Arellano opened this issue Apr 16, 2020 · 3 comments · Fixed by #12855
Closed

Allow Targets to express that fields are mutually exclusive #9561

Eric-Arellano opened this issue Apr 16, 2020 · 3 comments · Fixed by #12855
Assignees

Comments

@Eric-Arellano
Copy link
Contributor

Eric-Arellano commented Apr 16, 2020

Two times now while writing bindings for the Target API, I've encountered mutually exclusive fields. That is, if one is configured, the other should not be.

For example, platforms should not be specified at the same time as compatibility for python_binary.

--

There is no way to validate that because all validation happens at the Field level, independent of any other Field.

Almost certainly, we should have a new entry_point on Target called something like additional_validation().

@jsirois
Copy link
Contributor

jsirois commented Jan 23, 2021

For example, platforms should not be specified at the same time as compatibility for python_binary.

In the context of what rule? Those two fields are definitely not mutually exclusive in the context of creating a PEX file. You can specify both directly to the Pex CLI and get a sensible result.

@Eric-Arellano
Copy link
Contributor Author

In the context of what rule?

Sorry for my delay in replying...As discussed in #12612 (comment), agreed that Pex does not enforce --platform and --interpreter-constraint are mutually exclusive, but Pants does that.

--

Another case for this issue: With #12612, I'd like to require that lockfile is set on the pex_binary if platforms is also set. The issue sketches out "platform-aware" vs "platform-agnostic" lockfiles, and [python-setup].lockfile should (de facto?) be platform-agnostic. So, using the default won't work. You either need to turn off lockfiles or use a platform-specific lockfile.

We could enforce that in the rule, but it would be nice to use the Target API because it allows for the error to be more eager, e.g. to trigger when running ./pants dependencies ::.

@Eric-Arellano
Copy link
Contributor Author

Eric-Arellano commented Sep 9, 2021

Another example: I'm adding script as a field to pex_binary for console script support. I want to require that either entry_point or script are set, but not both. only one of entry_point or script are set, if any.

Eric-Arellano added a commit that referenced this issue Sep 10, 2021
Closes #11619.

This will benefit from #9561 to ensure both `script` and `entry_point` are not set at the same time. For now, `entry_point` wins out.

This means that we no longer make `entry_point` required because it's valid to set `script` instead. So, we deprecate `entry_point="<none>"` to indicate there is no entry point - now you leave off both the `script` and `entry_point` fields.

[ci skip-rust]
[ci skip-build-wheels]
Eric-Arellano added a commit that referenced this issue Sep 12, 2021
Closes #9561, and applies this new mechanism to validate that a `pex_binary` does not set both `script` and `entry_point`.

At first, I considered a more constrained solution like plugin authors indicating which fields are mutually exclusive. Instead, this is more flexible.

[ci skip-rust]
[ci skip-build-wheels]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants