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 plugins to use range requirements by applying constraints to plugin resolution #14058

Merged

Conversation

stuhood
Copy link
Sponsor Member

@stuhood stuhood commented Jan 4, 2022

As discussed in #14053, currently if a plugin uses a range requirement (even if it matches the requirement used by Pants itself), a different version might be chosen than what is already installed in the virtualenv for Pants, triggering a conflict when we try to add it to the working set (i.e. sys.path).

This change uses the current working set to constrain the plugin resolve, so that plugins with range requirements will choose matching versions from those ranges (if possible). To do that, it consumes #14064 to specify the working set as constraints in the PluginResolver.

Fixes #14053.

[ci skip-rust]

@stuhood
Copy link
Sponsor Member Author

stuhood commented Jan 4, 2022

Commits are useful to review independently.

This still needs a test: ideas welcome. I started to refactor the PluginResolver tests to ease that, but it looks like I'll either need to:

  1. add support for the synthetic plugins created in the test having dependencies
  2. require the root plugin itself with a range, create multiple copies of the plugin, ensure that the right one is chosen
  3. ...?

Copy link
Contributor

@jsirois jsirois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have useful feedback from my phone, but constraining the plugin resolve LGTM.

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Thoughts on breaking out the second commit as prework? It's a fairly substantial refactor of code orthogonal to plugins.

@stuhood
Copy link
Sponsor Member Author

stuhood commented Jan 4, 2022

Thoughts on breaking out the second commit as prework? It's a fairly substantial refactor of code orthogonal to plugins.

Yea, reasonable.

@stuhood

This comment has been minimized.

stuhood added a commit to stuhood/pants that referenced this pull request Jan 4, 2022
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
stuhood added a commit that referenced this pull request Jan 4, 2022
…raints. (#14064)

Some callers (#14058) of `PexRequirements` will soon need to be able to specify explicit constraints for building a PEX which are _not_ the global constraints. Additionally, consuming the `constraints` directly as a file (rather than parsing and re-materializing the file) forces whitespace/comment edits to the constraints file to invalidate all resolves ([reported here](pantsbuild/requirements-perf#1 (comment))).

To fix this, replace `apply_constraints: bool` (for the global constraints) with an explicit list of constraints.

[ci skip-rust]
[ci skip-build-wheels]
[ci skip-rust]
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
…ement is constrained by the working set.

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@stuhood stuhood force-pushed the stuhood/pants-requirements-as-constraints branch from b02028b to 714a4da Compare January 4, 2022 19:17
interpreter_constraints: InterpreterConstraints | None
# Requirement constraints to resolve with. If plugins will be loaded into the global working_set
# (i.e., onto the `sys.path`), then these should be the current contents of the working_set.
constraints: tuple[Requirement, ...]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be our PipRequirement?

Copy link
Sponsor Member Author

@stuhood stuhood Jan 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe...? But it doesn't look like that class does anything right now. cc @benjyw

I think that can wait until the class is differentiated in some way, at which point the type system will be able to guide us through replacement fairly easily.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to allow you to have optional args like --hash be preserved.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure... but it doesn't do that right now.

@stuhood stuhood merged commit 5baf325 into pantsbuild:main Jan 4, 2022
@stuhood stuhood deleted the stuhood/pants-requirements-as-constraints branch January 4, 2022 21:57
@stuhood stuhood added this to the 2.9.x milestone Jan 4, 2022
@stuhood stuhood removed this from the 2.9.x milestone Jan 4, 2022
@stuhood
Copy link
Sponsor Member Author

stuhood commented Jan 6, 2022

I've added https://www.pantsbuild.org/v2.9/docs/plugins-overview#publishing-a-plugin to document this support.

@Eric-Arellano
Copy link
Contributor

Looks great, thanks!

stuhood added a commit that referenced this pull request Jan 28, 2022
As described in #14246, #14058 caused plugin loading to run twice when we missed the cache. This was because after loading plugins, the working set has changed, and represents a new set of constraints on plugin loading.

While the current behavior is accurate, it isn't useful. Instead, we adjust `PluginResolver` to make the inputs to plugin loading idempotent, even if the outputs cannot be.

Fixes #14246.

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

Successfully merging this pull request may close these issues.

Fix or disable compatibility checks for plugin loading
3 participants