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

Support newer pip versions. #17555

Merged
merged 3 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/python/pants/backend/python/goals/lockfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ async def _setup_pip_args_and_constraints_file(resolve_name: str) -> _PipArgsAnd

@rule(desc="Generate Python lockfile", level=LogLevel.DEBUG)
async def generate_lockfile(
req: GeneratePythonLockfile, generate_lockfiles_subsystem: GenerateLockfilesSubsystem
req: GeneratePythonLockfile,
generate_lockfiles_subsystem: GenerateLockfilesSubsystem,
python_setup: PythonSetup,
) -> GenerateLockfileResult:
pip_args_setup = await _setup_pip_args_and_constraints_file(req.resolve_name)

Expand All @@ -150,6 +152,8 @@ async def generate_lockfile(
# generate universal locks because they have the best compatibility. We may
# want to let users change this, as `style=strict` is safer.
"--style=universal",
"--pip-version",
python_setup.pip_version.value,
"--resolver-version",
"pip-2020-resolver",
# PEX files currently only run on Linux and Mac machines; so we hard code this
Expand Down
12 changes: 12 additions & 0 deletions src/python/pants/backend/python/subsystems/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
logger = logging.getLogger(__name__)


@enum.unique
class PipVersion(enum.Enum):
V20_3_4 = "20.3.4-patched"
V22_2_2 = "22.2.2"
V22_3 = "22.3"


@enum.unique
class InvalidLockfileBehavior(enum.Enum):
error = "error"
Expand Down Expand Up @@ -180,6 +187,11 @@ class PythonSetup(Subsystem):
"""
),
)
pip_version = EnumOption(
default=PipVersion.V22_3,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is potentially controversial, as we're also upgrading everyone to newer pip, rather than making it opt-in.

I think that's fine, since pip is very heavily tested, and ubiquitous, and we want to bias towards doing the right thing for new users who will not be expecting to be going back to some ancient pip.

We have an escape hatch for those who encounter an unexpected and unlikely problem in an upgrade.

help="Use this version of Pip for resolving requirements and generating lockfiles.",
advanced=True,
)
_resolves_to_interpreter_constraints = DictOption["list[str]"](
help=softwrap(
"""
Expand Down
17 changes: 13 additions & 4 deletions src/python/pants/backend/python/util_rules/pex_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Iterable, List, Mapping, Optional, Tuple

from pants.backend.python.subsystems.python_native_code import PythonNativeCodeSubsystem
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.util_rules import pex_environment
from pants.backend.python.util_rules.pex_environment import (
PexEnvironment,
Expand Down Expand Up @@ -37,9 +38,9 @@ class PexCli(TemplatedExternalTool):
name = "pex"
help = "The PEX (Python EXecutable) tool (https://github.com/pantsbuild/pex)."

default_version = "v2.1.111"
default_version = "v2.1.113"
default_url_template = "https://github.com/pantsbuild/pex/releases/download/{version}/pex"
version_constraints = ">=2.1.111,<3.0"
version_constraints = ">=2.1.113,<3.0"

@classproperty
def default_known_versions(cls):
Expand All @@ -48,8 +49,8 @@ def default_known_versions(cls):
(
cls.default_version,
plat,
"9787e9712aba67ccc019415060a33e850675174be3331d35014e39219212b669",
"4063422",
"cde8eecc5e8e1c9fcca89f36c125a2c4b1c55cdb1073220b1be645e60c0c36e6",
"4067306",
)
)
for plat in ["macos_arm64", "macos_x86_64", "linux_x86_64", "linux_arm64"]
Expand Down Expand Up @@ -125,6 +126,7 @@ async def setup_pex_cli_process(
python_native_code: PythonNativeCodeSubsystem.EnvironmentAware,
global_options: GlobalOptions,
pex_subsystem: PexSubsystem,
python_setup: PythonSetup,
) -> Process:
tmpdir = ".tmp"
gets: List[Get] = [Get(Digest, CreateDigest([Directory(tmpdir)]))]
Expand Down Expand Up @@ -165,10 +167,17 @@ async def setup_pex_cli_process(
if request.set_resolve_args
else []
)
# All old-style pex runs take the --pip-version flag, but only certain subcommands of the
# `pex3` console script do. So if invoked with a subcommand, the caller must selectively
# set --pip-version only on subcommands that take it.
pip_version_args = (
[] if request.subcommand else ["--pip-version", python_setup.pip_version.value]
)
args = [
*request.subcommand,
*global_args,
*verbosity_args,
*pip_version_args,
*resolve_args,
# NB: This comes at the end because it may use `--` passthrough args, # which must come at
# the end.
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/core/goals/generate_lockfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def filter_tool_lockfile_requests(

class GenerateLockfilesSubsystem(GoalSubsystem):
name = "generate-lockfiles"
help = "Generate lockfiles for Python third-party dependencies."
help = "Generate lockfiles for third-party dependencies."

@classmethod
def activated(cls, union_membership: UnionMembership) -> bool:
Expand Down