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

[internal] Refactor how call sites interact with Python resolves #14287

Merged
merged 2 commits into from
Jan 28, 2022

Conversation

Eric-Arellano
Copy link
Contributor

The first change bundles ResolveField.validate() and .value_or_default(), which makes call sites much less clunky.

Note that this contrasts with JVM where we use JvmSubsystem.resolves_for_target() - I stuck with Field-based methods because it gives us better MyPy typing between ResolveField vs CompatibleResolveFields.

--

The second change prepares for how we will calculate the resolve to use. Before, we had call sites like pytest_runner.py setting the resolve. Instead, pex_from_targets.py should choose the resolve based on the direct input addresses to the request. Then it validates that the transitive closure is correct. This implies:

  • test, package, and run are chosen by simply inspecting the single python_test or pex_binary target, but validating all deps
  • The onus is on MyPy and Pylint to partition so that the input targets to PexFromTargets are all compatible
  • For repl, we can't do any partitioning, only validation

For now, we simply use the default resolve. A followup will implement this algorithm, similar to our JVM code in coursier_fetch.py.

Note that this means --enable-resolves now gives you roughly the same behavior as [python].experimental_lockfile! That is, for now, we only support a single resolve, whatever is set by [python].default_resolve. This means that we can remove [python].experimental_lockfile and generate-user-lockfile to simplify this code.

# 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]
# 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]
Copy link
Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Description and change make sense. Thanks!

Comment on lines +449 to +450
# TODO: compute the resolve based on request.addresses, and validate that the
# transitive closure is compatible. See coursier_fetch.py for inspiration.
Copy link
Member

Choose a reason for hiding this comment

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

Should this point to a particular followup issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Normally, yeah, but I plan to land this change tomorrow :) I wanted to simplify things first, including an upcoming PR to kill generate-user-lockfiles

@Eric-Arellano Eric-Arellano enabled auto-merge (squash) January 28, 2022 00:55
@Eric-Arellano Eric-Arellano merged commit 1ef67ac into pantsbuild:main Jan 28, 2022
@Eric-Arellano Eric-Arellano deleted the refactor-python-resolve branch January 28, 2022 01:05
Eric-Arellano added a commit that referenced this pull request Jan 28, 2022
…le` in favor of `[python].experimental_resolves` (#14288)

Turns out that Pants only needs a single resolve. Our testprojects resolve wasn't actually used by anything. (We could always add this back for testing purposes.)

So, thanks to #14287, we can use `[python].experimental_resolves` just like `[python].experimental_lockfile` was being used: the feature currently supports a single resolve.

Benefits to this change:

1. Lockfile is now generated via `generate-lockfiles` rather than `generate-user-lockfiles`
2. Less confusing code for us to deal with. Now we just have constraints files vs. resolves

[ci skip-rust]
@wisechengyi wisechengyi mentioned this pull request Jan 29, 2022
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.

2 participants