pantsbuild / pants

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

Fix lockfile generation for shadowed resolves #21642

Closed lilatomic closed 1 day ago

lilatomic commented 1 week ago

When a user resolve shadows a tool resolve, pants generate-lockfiles will generate the lockfile twice. This is because only the --request arg is deduplicated. Without one specified, all known resolves are added to a non-deduplicated collection. The resolves are added separately for each backend and ExportableTool. This can introduce duplicates into this list. And, although the shadowing is correct, the resolve is exported twice. For example, the tool Black and a user resolve named "black" will both use the same resolve name, resulting in a list of resolves to export like RequestedPythonUserResolveNames(['black', 'python-default', 'coverage-py', 'pytest', 'ipython', 'black']).

This MR makes 3 adjustments to this process:

  1. RequestedUserResolveNames is now a DeduplicatedCollection. This mitigates the most proximate issue of specifying the same resolve.
  2. Python deduplicates GeneratePythonLockfile. This may already be covered by 1, but can't hurt
  3. Python does not present tool resolves for tools that are using a user resolve. For example, if [black].install_from_resolve="linters", its default resolve "black" will not be exposed.

Note that in the case of shadowing without install_from_resolve, although the shadowed resolve is not surfaced (for export), Pants will still correctly use the default lockfile.

closes #21625