Skip to content

Commit

Permalink
[internal] Hook up [python-repos] and manylinux to Pex lockfile g…
Browse files Browse the repository at this point in the history
…eneration (#14282)

[ci skip-rust]
  • Loading branch information
Eric-Arellano committed Jan 27, 2022
1 parent 94cef33 commit 0eda46f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 30 deletions.
16 changes: 13 additions & 3 deletions src/python/pants/backend/python/goals/lockfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ class MaybeWarnPythonRepos:
pass


class MaybeWarnPythonReposRequest:
pass


@rule
def maybe_warn_python_repos(python_repos: PythonRepos) -> MaybeWarnPythonRepos:
def maybe_warn_python_repos(
_: MaybeWarnPythonReposRequest, python_repos: PythonRepos
) -> MaybeWarnPythonRepos:
def warn_python_repos(option: str) -> None:
logger.warning(
f"The option `[python-repos].{option}` is configured, but it does not currently work "
Expand All @@ -132,22 +138,25 @@ async def generate_lockfile(
req: GeneratePythonLockfile,
poetry_subsystem: PoetrySubsystem,
generate_lockfiles_subsystem: GenerateLockfilesSubsystem,
_: MaybeWarnPythonRepos,
python_repos: PythonRepos,
python_setup: PythonSetup,
) -> GenerateLockfileResult:
if req.use_pex:
result = await Get(
ProcessResult,
PexCliProcess(
subcommand=("lock", "create"),
# TODO: Hook up to [python-repos]. Don't call `MaybeWarnPythonRepos` in this case.
extra_args=(
"--output=lock.json",
"--no-emit-warnings",
# See https://github.com/pantsbuild/pants/issues/12458. For now, we always
# generate universal locks because they have the best compatibility. We may
# want to let users change this, as `style=strict` is safer.
"--style=universal",
"--resolver-version",
"pip-2020-resolver",
*python_repos.pex_args,
*python_setup.manylinux_pex_args,
*req.interpreter_constraints.generate_pex_arg_list(),
*req.requirements,
),
Expand All @@ -167,6 +176,7 @@ async def generate_lockfile(
),
)
else:
await Get(MaybeWarnPythonRepos, MaybeWarnPythonReposRequest())
_pyproject_toml = create_pyproject_toml(
req.requirements, req.interpreter_constraints
).encode()
Expand Down
22 changes: 17 additions & 5 deletions src/python/pants/backend/python/subsystems/repos.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from typing import List, cast
from __future__ import annotations

from typing import Iterator, cast

from pants.option.subsystem import Subsystem

Expand Down Expand Up @@ -41,9 +43,19 @@ def register_options(cls, register):
)

@property
def repos(self) -> List[str]:
return cast(List[str], self.options.repos)
def repos(self) -> list[str]:
return cast("list[str]", self.options.repos)

@property
def indexes(self) -> list[str]:
return cast("list[str]", self.options.indexes)

@property
def indexes(self) -> List[str]:
return cast(List[str], self.options.indexes)
def pex_args(self) -> Iterator[str]:
# NB: In setting `--no-pypi`, we rely on the default value of `--python-repos-indexes`
# including PyPI, which will override `--no-pypi` and result in using PyPI in the default
# case. Why set `--no-pypi`, then? We need to do this so that
# `--python-repos-repos=['custom_url']` will only point to that index and not include PyPI.
yield "--no-pypi"
yield from (f"--index={index}" for index in self.indexes)
yield from (f"--repo={repo}" for repo in self.repos)
10 changes: 9 additions & 1 deletion src/python/pants/backend/python/subsystems/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import enum
import logging
import os
from typing import Iterable, Optional, cast
from typing import Iterable, Iterator, Optional, cast

from pants.option.custom_types import file_option
from pants.option.subsystem import Subsystem
Expand Down Expand Up @@ -339,6 +339,14 @@ def manylinux(self) -> str | None:
return None
return manylinux

@property
def manylinux_pex_args(self) -> Iterator[str]:
if self.manylinux:
yield "--manylinux"
yield self.manylinux
else:
yield "--no-manylinux"

@property
def resolver_jobs(self) -> int:
return cast(int, self.options.resolver_jobs)
Expand Down
29 changes: 8 additions & 21 deletions src/python/pants/backend/python/util_rules/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,13 @@ async def build_pex(
pex_runtime_env: PexRuntimeEnvironment,
) -> BuildPexResult:
"""Returns a PEX with the given settings."""
argv = ["--output-file", request.output_filename, *request.additional_args]
argv = [
"--output-file",
request.output_filename,
"--no-emit-warnings",
*python_setup.manylinux_pex_args,
*request.additional_args,
]

repository_pex = (
request.requirements.repository_pex
Expand All @@ -366,19 +372,7 @@ async def build_pex(
if repository_pex:
argv.extend(["--pex-repository", repository_pex.name])
else:
# NB: In setting `--no-pypi`, we rely on the default value of `--python-repos-indexes`
# including PyPI, which will override `--no-pypi` and result in using PyPI in the default
# case. Why set `--no-pypi`, then? We need to do this so that
# `--python-repos-repos=['custom_url']` will only point to that index and not include PyPI.
argv.extend(
[
"--no-pypi",
*(f"--index={index}" for index in python_repos.indexes),
*(f"--repo={repo}" for repo in python_repos.repos),
"--resolver-version",
"pip-2020-resolver",
]
)
argv.extend([*python_repos.pex_args, "--resolver-version", "pip-2020-resolver"])

python: PythonExecutable | None = None

Expand Down Expand Up @@ -406,13 +400,6 @@ async def build_pex(
if python:
argv.extend(["--python", python.path])

argv.append("--no-emit-warnings")

if python_setup.manylinux:
argv.extend(["--manylinux", python_setup.manylinux])
else:
argv.append("--no-manylinux")

if request.main is not None:
argv.extend(request.main.iter_pex_args())

Expand Down

0 comments on commit 0eda46f

Please sign in to comment.