Skip to content

Commit

Permalink
Rename [python-setup] to [python] and move into the python backen…
Browse files Browse the repository at this point in the history
…d. (#13345)

This change renames the `[python-setup]` `Subsystem` -- which encapsulates most of the config of `pants.backend.python` -- to just `[python]`, and moves it into that backend (along with `[python-repos]`).

[ci skip-rust]
[ci skip-build-wheels]
  • Loading branch information
stuhood committed Oct 24, 2021
1 parent c6adf7a commit 18c1468
Show file tree
Hide file tree
Showing 66 changed files with 774 additions and 734 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test-cron.yaml
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Tell Pants to use Python ${{ matrix.python-version }}
run: 'echo "PY=python${{ matrix.python-version }}" >> $GITHUB_ENV
echo "PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
echo "PANTS_PYTHON_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
}}.*'']" >> $GITHUB_ENV
'
Expand Down Expand Up @@ -199,7 +199,7 @@ jobs:
- name: Tell Pants to use Python ${{ matrix.python-version }}
run: 'echo "PY=python${{ matrix.python-version }}" >> $GITHUB_ENV
echo "PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
echo "PANTS_PYTHON_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
}}.*'']" >> $GITHUB_ENV
'
Expand Down Expand Up @@ -324,7 +324,7 @@ jobs:
- name: Tell Pants to use Python ${{ matrix.python-version }}
run: 'echo "PY=python${{ matrix.python-version }}" >> $GITHUB_ENV
echo "PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
echo "PANTS_PYTHON_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
}}.*'']" >> $GITHUB_ENV
'
Expand Down Expand Up @@ -411,7 +411,7 @@ jobs:
- name: Tell Pants to use Python ${{ matrix.python-version }}
run: 'echo "PY=python${{ matrix.python-version }}" >> $GITHUB_ENV
echo "PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
echo "PANTS_PYTHON_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
}}.*'']" >> $GITHUB_ENV
'
Expand Down Expand Up @@ -494,7 +494,7 @@ jobs:
- name: Tell Pants to use Python ${{ matrix.python-version }}
run: 'echo "PY=python${{ matrix.python-version }}" >> $GITHUB_ENV
echo "PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
echo "PANTS_PYTHON_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
}}.*'']" >> $GITHUB_ENV
'
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test.yaml
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Tell Pants to use Python ${{ matrix.python-version }}
run: 'echo "PY=python${{ matrix.python-version }}" >> $GITHUB_ENV
echo "PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
echo "PANTS_PYTHON_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
}}.*'']" >> $GITHUB_ENV
'
Expand Down Expand Up @@ -198,7 +198,7 @@ jobs:
- name: Tell Pants to use Python ${{ matrix.python-version }}
run: 'echo "PY=python${{ matrix.python-version }}" >> $GITHUB_ENV
echo "PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
echo "PANTS_PYTHON_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
}}.*'']" >> $GITHUB_ENV
'
Expand Down Expand Up @@ -499,7 +499,7 @@ jobs:
- name: Tell Pants to use Python ${{ matrix.python-version }}
run: 'echo "PY=python${{ matrix.python-version }}" >> $GITHUB_ENV
echo "PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
echo "PANTS_PYTHON_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
}}.*'']" >> $GITHUB_ENV
'
Expand Down Expand Up @@ -585,7 +585,7 @@ jobs:
- name: Tell Pants to use Python ${{ matrix.python-version }}
run: 'echo "PY=python${{ matrix.python-version }}" >> $GITHUB_ENV
echo "PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
echo "PANTS_PYTHON_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
}}.*'']" >> $GITHUB_ENV
'
Expand Down Expand Up @@ -667,7 +667,7 @@ jobs:
- name: Tell Pants to use Python ${{ matrix.python-version }}
run: 'echo "PY=python${{ matrix.python-version }}" >> $GITHUB_ENV
echo "PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
echo "PANTS_PYTHON_INTERPRETER_CONSTRAINTS=[''==${{ matrix.python-version
}}.*'']" >> $GITHUB_ENV
'
Expand Down
6 changes: 3 additions & 3 deletions build-support/bin/_generate_all_lockfiles_helper.py
Expand Up @@ -26,10 +26,10 @@
from pants.backend.python.subsystems.ipython import IPython
from pants.backend.python.subsystems.lambdex import Lambdex
from pants.backend.python.subsystems.pytest import PyTest
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.subsystems.setuptools import Setuptools
from pants.backend.python.typecheck.mypy.subsystem import MyPy
from pants.backend.terraform.dependency_inference import TerraformHcl2Parser
from pants.python.python_setup import PythonSetup

logger = logging.getLogger(__name__)

Expand All @@ -45,7 +45,7 @@ def main() -> None:
# `generate_all_lockfiles.sh` will have overridden this option to solve the chicken
# and egg problem from https://github.com/pantsbuild/pants/issues/12457. We must
# restore it here so that the lockfile gets generated properly.
"--python-setup-experimental-lockfile=3rdparty/python/lockfiles/user_reqs.txt",
"--python-experimental-lockfile=3rdparty/python/lockfiles/user_reqs.txt",
"generate-lockfiles",
"generate-user-lockfile",
"::",
Expand All @@ -60,7 +60,7 @@ def main() -> None:
[
"./pants",
"--concurrent",
f"--python-setup-interpreter-constraints={repr(PythonSetup.default_interpreter_constraints)}",
f"--python-interpreter-constraints={repr(PythonSetup.default_interpreter_constraints)}",
# Autoflake.
f"--autoflake-version={Autoflake.default_version}",
f"--autoflake-extra-requirements={repr(Autoflake.default_extra_requirements)}",
Expand Down
6 changes: 3 additions & 3 deletions build-support/bin/generate_all_lockfiles.sh
Expand Up @@ -13,13 +13,13 @@ source "${REPO_ROOT}/build-support/common.sh"
# To solve the chicken and egg problem of https://github.com/pantsbuild/pants/issues/12457, we
# temporarily disable the lockfile. This means that `./pants run` will ignore the lockfile. While
# the script is then running, it will set the option again to generate the lockfile where we want.
export PANTS_PYTHON_SETUP_EXPERIMENTAL_LOCKFILE=""
export PANTS_PYTHON_EXPERIMENTAL_LOCKFILE=""

if is_macos_arm; then
# Generate the lockfiles with the correct notated interpreter constraints, but make
# Pants execute with a version of Python that actually runs on MacOS ARM
unset PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS
exec ./pants run build-support/bin/_generate_all_lockfiles_helper.py --python-setup-interpreter-constraints="['==3.9.*']"
unset PANTS_PYTHON_INTERPRETER_CONSTRAINTS
exec ./pants run build-support/bin/_generate_all_lockfiles_helper.py --python-interpreter-constraints="['==3.9.*']"
else
exec ./pants run build-support/bin/_generate_all_lockfiles_helper.py
fi
2 changes: 1 addition & 1 deletion build-support/bin/generate_github_workflows.py
Expand Up @@ -253,7 +253,7 @@ def setup_primary_python() -> Sequence[Step]:
"run": dedent(
"""\
echo "PY=python${{ matrix.python-version }}" >> $GITHUB_ENV
echo "PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS=['==${{ matrix.python-version }}.*']" >> $GITHUB_ENV
echo "PANTS_PYTHON_INTERPRETER_CONSTRAINTS=['==${{ matrix.python-version }}.*']" >> $GITHUB_ENV
"""
),
},
Expand Down
2 changes: 1 addition & 1 deletion build-support/bin/release.sh
Expand Up @@ -31,6 +31,6 @@ fi
# a temporary venv to build 3rdparty wheels.
#
# NB: This must align with $PY for the native wheel to be built correctly.
export PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS="['${interpreter_constraint}']"
export PANTS_PYTHON_INTERPRETER_CONSTRAINTS="['${interpreter_constraint}']"

exec ./pants run build-support/bin/_release_helper.py -- "$@"
4 changes: 2 additions & 2 deletions pants.toml
Expand Up @@ -81,7 +81,7 @@ root_patterns = [
"/pants-plugins",
]

[python-setup]
[python]
experimental_lockfile = "3rdparty/python/lockfiles/user_reqs.txt"
interpreter_constraints = [">=3.7,<3.10"]
macos_big_sur_compatibility = true
Expand Down Expand Up @@ -119,7 +119,7 @@ execution_slot_var = "EXECUTION_SLOT"
[test]
extra_env_vars = [
# TODO: These are exposed to tests in order to allow for python interpreter discovery when
# Pants-tests-Pants: in particular, the [python-setup] subsystem consumes them.
# Pants-tests-Pants: in particular, the [python] subsystem consumes them.
# see https://github.com/pantsbuild/pants/issues/11638
"PYENV_ROOT",
"HOME",
Expand Down
Expand Up @@ -6,6 +6,7 @@
import logging

from pants.backend.python.goals.lockfile import PythonLockfile, PythonLockfileRequest
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.target_types import PythonRequirementsField
from pants.backend.python.util_rules.interpreter_constraints import InterpreterConstraints
from pants.backend.python.util_rules.pex import PexRequirements
Expand All @@ -14,7 +15,6 @@
from pants.engine.goal import Goal, GoalSubsystem
from pants.engine.rules import Get, collect_rules, goal_rule
from pants.engine.target import TransitiveTargets, TransitiveTargetsRequest
from pants.python.python_setup import PythonSetup
from pants.util.strutil import pluralize

logger = logging.getLogger(__name__)
Expand All @@ -39,7 +39,7 @@ async def generate_user_lockfile_goal(
) -> GenerateUserLockfileGoal:
if python_setup.lockfile is None:
logger.warning(
"You ran `./pants generate-user-lockfile`, but `[python-setup].experimental_lockfile` "
"You ran `./pants generate-user-lockfile`, but `[python].experimental_lockfile` "
"is not set. Please set this option to the path where you'd like the lockfile for "
"your code's dependencies to live."
)
Expand Down
Expand Up @@ -11,6 +11,7 @@
ParsePythonImportsRequest,
)
from pants.backend.python.dependency_inference.module_mapper import PythonModule, PythonModuleOwners
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.target_types import PythonSourceField, PythonTestSourceField
from pants.backend.python.util_rules import ancestor_files, pex
from pants.backend.python.util_rules.ancestor_files import AncestorFiles, AncestorFilesRequest
Expand All @@ -32,7 +33,6 @@
from pants.engine.unions import UnionRule
from pants.option.global_options import OwnersNotFoundBehavior
from pants.option.subsystem import Subsystem
from pants.python.python_setup import PythonSetup

logger = logging.getLogger(__name__)

Expand Down
16 changes: 8 additions & 8 deletions src/python/pants/backend/python/goals/lockfile.py
Expand Up @@ -21,6 +21,8 @@
NO_TOOL_LOCKFILE,
PythonToolRequirementsBase,
)
from pants.backend.python.subsystems.repos import PythonRepos
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.target_types import (
EntryPoint,
InterpreterConstraintsField,
Expand Down Expand Up @@ -48,8 +50,6 @@
from pants.engine.rules import Get, MultiGet, collect_rules, goal_rule, rule
from pants.engine.target import AllTargets, TransitiveTargets, TransitiveTargetsRequest
from pants.engine.unions import UnionMembership, union
from pants.python.python_repos import PythonRepos
from pants.python.python_setup import PythonSetup
from pants.util.logging import LogLevel
from pants.util.ordered_set import FrozenOrderedSet

Expand Down Expand Up @@ -78,7 +78,7 @@ def register_options(cls, register) -> None:
"Only generate lockfiles for the specified resolve(s).\n\n"
"Resolves are the logical names for the different lockfiles used in your project. "
"For your own code's dependencies, these come from the option "
"`[python-setup].experimental_resolves_to_lockfiles`. For tool lockfiles, resolve "
"`[python].experimental_resolves_to_lockfiles`. For tool lockfiles, resolve "
"names are the options scope for that tool such as `black`, `pytest`, and "
"`mypy-protobuf`.\n\n"
"For example, you can run `./pants generate-lockfiles --resolve=black "
Expand Down Expand Up @@ -127,7 +127,7 @@ class PythonLockfileRequest:
interpreter_constraints: InterpreterConstraints
resolve_name: str
lockfile_dest: str
# Only kept for `[python-setup].experimental_lockfile`, which is not using the new
# Only kept for `[python].experimental_lockfile`, which is not using the new
# "named resolve" semantics yet.
_description: str | None = None
_regenerate_command: str | None = None
Expand Down Expand Up @@ -379,7 +379,7 @@ def warn_python_repos(option: str) -> None:
"`[tool].lockfile = '<none>'`, e.g. setting `[black].lockfile`. You can also manually "
"generate a lockfile, such as by using pip-compile or `pip freeze`. Set the "
"`[tool].lockfile` option to the path you manually generated. When manually maintaining "
"lockfiles, set `[python-setup].invalid_lockfile_behavior = 'ignore'."
"lockfiles, set `[python].invalid_lockfile_behavior = 'ignore'."
)


Expand All @@ -388,18 +388,18 @@ def __init__(self, ambiguous_names: list[str]) -> None:
if len(ambiguous_names) == 1:
first_paragraph = (
"A resolve name from the option "
"`[python-setup].experimental_resolves_to_lockfiles` collides with the name of a "
"`[python].experimental_resolves_to_lockfiles` collides with the name of a "
f"tool resolve: {ambiguous_names[0]}"
)
else:
first_paragraph = (
"Some resolve names from the option "
"`[python-setup].experimental_resolves_to_lockfiles` collide with the names of "
"`[python].experimental_resolves_to_lockfiles` collide with the names of "
f"tool resolves: {sorted(ambiguous_names)}"
)
super().__init__(
f"{first_paragraph}\n\n"
"To fix, please update `[python-setup].experimental_resolves_to_lockfiles` to use "
"To fix, please update `[python].experimental_resolves_to_lockfiles` to use "
"different resolve names."
)

Expand Down
Expand Up @@ -5,6 +5,7 @@
from dataclasses import dataclass
from typing import Tuple

from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.target_types import (
PexAlwaysWriteCacheField,
PexBinaryDefaults,
Expand Down Expand Up @@ -43,7 +44,6 @@
targets_with_sources_types,
)
from pants.engine.unions import UnionMembership, UnionRule
from pants.python.python_setup import PythonSetup
from pants.util.docutil import doc_url
from pants.util.logging import LogLevel

Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/python/goals/pytest_runner.py
Expand Up @@ -12,6 +12,7 @@
PytestCoverageData,
)
from pants.backend.python.subsystems.pytest import PyTest, PythonTestFieldSet
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.util_rules.interpreter_constraints import InterpreterConstraints
from pants.backend.python.util_rules.local_dists import LocalDistsPex, LocalDistsPexRequest
from pants.backend.python.util_rules.pex import Pex, PexRequest, VenvPex, VenvPexProcess
Expand Down Expand Up @@ -58,7 +59,6 @@
from pants.engine.target import Target, TransitiveTargets, TransitiveTargetsRequest, WrappedTarget
from pants.engine.unions import UnionMembership, UnionRule, union
from pants.option.global_options import GlobalOptions
from pants.python.python_setup import PythonSetup
from pants.util.logging import LogLevel

logger = logging.getLogger()
Expand Down
Expand Up @@ -17,6 +17,7 @@
from pants.backend.python.macros.python_artifact import PythonArtifact
from pants.backend.python.subsystems.pytest import PythonTestFieldSet
from pants.backend.python.subsystems.pytest import rules as pytest_subsystem_rules
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.subsystems.setuptools import rules as setuptools_rules
from pants.backend.python.target_types import (
PexBinary,
Expand All @@ -39,7 +40,6 @@
from pants.engine.rules import Get, rule
from pants.engine.target import Target
from pants.engine.unions import UnionRule
from pants.python.python_setup import PythonSetup
from pants.testutil.python_interpreter_selection import (
all_major_minor_python_versions,
skip_unless_python27_and_python3_present,
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_passing(rule_runner: RuleRunner, major_minor_interpreter: str) -> None:
result = run_pytest(
rule_runner,
tgt,
extra_args=[f"--python-setup-interpreter-constraints=['=={major_minor_interpreter}.*']"],
extra_args=[f"--python-interpreter-constraints=['=={major_minor_interpreter}.*']"],
)
assert result.xml_results is not None
assert result.exit_code == 0
Expand Down
Expand Up @@ -8,13 +8,13 @@
from pants.backend.codegen.protobuf.target_types import ProtobufSourceTarget
from pants.backend.python.goals import repl as python_repl
from pants.backend.python.subsystems.ipython import rules as ipython_subsystem_rules
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.target_types import PythonSourcesGeneratorTarget
from pants.backend.python.util_rules import local_dists, pex_from_targets
from pants.backend.python.util_rules.pex import PexProcess
from pants.core.goals.repl import Repl
from pants.core.goals.repl import rules as repl_rules
from pants.engine.process import Process
from pants.python.python_setup import PythonSetup
from pants.testutil.python_interpreter_selection import all_major_minor_python_versions
from pants.testutil.rule_runner import GoalRuleResult, QueryRule, RuleRunner, mock_console

Expand Down Expand Up @@ -73,7 +73,7 @@ def test_ipython(rule_runner: RuleRunner, major_minor_interpreter: str) -> None:
rule_runner,
extra_args=[
"--repl-shell=ipython",
f"--python-setup-interpreter-constraints=['=={major_minor_interpreter}.*']",
f"--python-interpreter-constraints=['=={major_minor_interpreter}.*']",
],
).exit_code
== 0
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/python/goals/run_pex_binary.py
Expand Up @@ -4,6 +4,7 @@
import os

from pants.backend.python.goals.package_pex_binary import PexBinaryFieldSet
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.target_types import (
PexBinaryDefaults,
ResolvedPexEntryPoint,
Expand All @@ -22,7 +23,6 @@
from pants.engine.rules import Get, MultiGet, collect_rules, rule
from pants.engine.target import TransitiveTargets, TransitiveTargetsRequest
from pants.engine.unions import UnionRule
from pants.python.python_setup import PythonSetup
from pants.util.logging import LogLevel


Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/python/goals/setup_py.py
Expand Up @@ -15,6 +15,7 @@
from typing import Any, DefaultDict, Dict, List, Mapping, Tuple, cast

from pants.backend.python.macros.python_artifact import PythonArtifact
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.subsystems.setuptools import PythonDistributionFieldSet
from pants.backend.python.target_types import (
GenerateSetupField,
Expand Down Expand Up @@ -78,7 +79,6 @@
)
from pants.engine.unions import UnionMembership, UnionRule, union
from pants.option.subsystem import Subsystem
from pants.python.python_setup import PythonSetup
from pants.util.docutil import doc_url
from pants.util.frozendict import FrozenDict
from pants.util.logging import LogLevel
Expand Down

0 comments on commit 18c1468

Please sign in to comment.