Skip to content

Commit

Permalink
Expose --resolver-version, deprecate --cache-ttl. (#11349)
Browse files Browse the repository at this point in the history
Update to the new and deprecated features of Pex 2.1.24 by exposing
--resolver-version and deprecating --cache-ttl. For now we keep the
pip-legacy-resolver default for --resolver-version, but encourage users
migrating to the pip-2020-resolver.
  • Loading branch information
jsirois committed Dec 20, 2020
1 parent 9a8e1f3 commit 938c945
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions pants.toml
Expand Up @@ -61,6 +61,7 @@ root_patterns = [
]

[python-setup]
resolver_version = "pip-2020-resolver"
requirement_constraints = "3rdparty/python/constraints.txt"
resolve_all_constraints = "nondeployables"
interpreter_constraints = [">=3.7,<3.9"]
Expand Down
5 changes: 4 additions & 1 deletion src/python/pants/backend/python/lint/flake8/subsystem.py
Expand Up @@ -12,7 +12,10 @@ class Flake8(PythonToolBase):

options_scope = "flake8"
default_version = "flake8>=3.7.9,<3.9"
default_extra_requirements = ["setuptools<45"] # NB: `<45` is for Python 2 support
default_extra_requirements = [
"setuptools<45; python_full_version == '2.7.*'",
"setuptools; python_version > '2.7'",
]
default_entry_point = "flake8"

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/python/util_rules/pex.py
Expand Up @@ -497,8 +497,8 @@ async def create_pex(
"--no-pypi",
*(f"--index={index}" for index in python_repos.indexes),
*(f"--repo={repo}" for repo in python_repos.repos),
"--cache-ttl",
str(python_setup.resolver_http_cache_ttl),
"--resolver-version",
python_setup.resolver_version.value,
*request.additional_args,
]

Expand Down
41 changes: 31 additions & 10 deletions src/python/pants/python/python_setup.py
Expand Up @@ -37,6 +37,13 @@ class ResolveAllConstraintsOption(Enum):
ALWAYS = "always"


class ResolverVersion(Enum):
"""The resolver implementation to use when resolving Python requirements."""

PIP_LEGACY = "pip-legacy-resolver"
PIP_2020 = "pip-2020-resolver"


class PythonSetup(Subsystem):
"""A Python environment."""

Expand Down Expand Up @@ -107,6 +114,22 @@ def register_options(cls, register):
'* "<PEXRC>", paths in the PEX_PYTHON_PATH variable in /etc/pexrc or ~/.pexrc'
),
)
register(
"--resolver-version",
advanced=True,
type=ResolverVersion,
default=ResolverVersion.PIP_LEGACY,
deprecation_start_version="2.3.0.dev1",
removal_version="2.5.0.dev1",
removal_hint="",
help=(
"The resolver implementation to use when resolving Python requirements. Support "
f"for the {ResolverVersion.PIP_LEGACY.value!r} will be removed in Pants 2.5; so "
f"you're encouraged to start using the {ResolverVersion.PIP_2020.value!r} early. "
"For more information on this change see "
"https://pip.pypa.io/en/latest/user_guide/#changes-to-the-pip-dependency-resolver-in-20-2-2020"
),
)
register(
"--resolver-manylinux",
advanced=True,
Expand All @@ -132,13 +155,11 @@ def register_options(cls, register):
register(
"--resolver-http-cache-ttl",
type=int,
default=3_600, # This matches PEX's default.
default=0,
advanced=True,
help=(
"The maximum time (in seconds) for items in the HTTP cache. When the cache expires,"
"the PEX resolver will make network requests to see if new versions of your "
"requirements are available."
),
removal_version="2.4.0.dev1",
removal_hint="Unused.",
help="Unused.",
)

@property
Expand All @@ -161,6 +182,10 @@ def resolve_all_constraints_was_set_explicitly(self) -> bool:
def interpreter_search_paths(self):
return self.expand_interpreter_search_paths(self.options.interpreter_search_paths)

@property
def resolver_version(self) -> ResolverVersion:
return cast(ResolverVersion, self.options.resolver_version)

@property
def manylinux(self) -> Optional[str]:
manylinux = cast(Optional[str], self.options.resolver_manylinux)
Expand All @@ -172,10 +197,6 @@ def manylinux(self) -> Optional[str]:
def resolver_jobs(self) -> int:
return cast(int, self.options.resolver_jobs)

@property
def resolver_http_cache_ttl(self) -> int:
return cast(int, self.options.resolver_http_cache_ttl)

@property
def scratch_dir(self):
return os.path.join(self.options.pants_workdir, *self.options_scope.split("."))
Expand Down

0 comments on commit 938c945

Please sign in to comment.