Skip to content

Commit

Permalink
Add engine/unions.py to consolidate union types into one file (pant…
Browse files Browse the repository at this point in the history
…sbuild#9580)

Problems with the status quo:

1) `@union` and `UnionRule`/`UnionMembership` are split across two files
2) Unions are an advanced concept. Most rule authors can go by without using them, so they don't belong in `rules.py`.

[ci skip-jvm-tests]
  • Loading branch information
Eric-Arellano authored Apr 18, 2020
1 parent f4df20f commit cdb3cf9
Show file tree
Hide file tree
Showing 63 changed files with 188 additions and 130 deletions.
1 change: 1 addition & 0 deletions src/python/pants/backend/awslambda/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ python_library(
'src/python/pants/engine:rules',
'src/python/pants/engine:selectors',
'src/python/pants/engine:target',
'src/python/pants/engine:unions',
],
tags = {'partially_type_checked'},
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from pants.engine.console import Console
from pants.engine.fs import Digest, DirectoriesToMerge, DirectoryToMaterialize, Workspace
from pants.engine.goal import Goal, GoalSubsystem, LineOriented
from pants.engine.objects import union
from pants.engine.rules import UnionMembership, goal_rule
from pants.engine.rules import goal_rule
from pants.engine.selectors import Get, MultiGet
from pants.engine.target import Field, RegisteredTargetTypes, Target, Targets
from pants.engine.unions import UnionMembership, union


class AWSLambdaError(Exception):
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/awslambda/python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ python_library(
'src/python/pants/engine:rules',
'src/python/pants/engine:selectors',
'src/python/pants/engine:target',
'src/python/pants/engine:unions',
'src/python/pants/python',
],
tags = {"type_checked"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
from pants.engine.addresses import Addresses
from pants.engine.fs import Digest, DirectoriesToMerge
from pants.engine.isolated_process import Process, ProcessResult
from pants.engine.rules import UnionRule, named_rule, subsystem_rule
from pants.engine.rules import named_rule, subsystem_rule
from pants.engine.selectors import Get
from pants.engine.unions import UnionRule
from pants.python.python_setup import PythonSetup


Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/awslambda/python/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Match, Optional, Tuple, cast

from pants.backend.python.rules.targets import COMMON_PYTHON_FIELDS, PythonSources
from pants.build_graph.address import Address
from pants.engine.addresses import Address
from pants.engine.target import InvalidFieldException, StringField, Target


Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/python/lint/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ python_library(
'src/python/pants/core/util_rules',
'src/python/pants/engine/legacy:structs',
'src/python/pants/engine:rules',
'src/python/pants/engine:unions',
],
tags = {"type_checked"},
)
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/python/lint/bandit/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ python_library(
'src/python/pants/engine:isolated_process',
'src/python/pants/engine:rules',
'src/python/pants/engine:selectors',
'src/python/pants/engine:unions',
'src/python/pants/option',
'src/python/pants/python',
],
Expand Down
3 changes: 2 additions & 1 deletion src/python/pants/backend/python/lint/bandit/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
)
from pants.engine.fs import Digest, DirectoriesToMerge, PathGlobs, Snapshot
from pants.engine.isolated_process import FallibleProcessResult, Process
from pants.engine.rules import UnionRule, named_rule, subsystem_rule
from pants.engine.rules import named_rule, subsystem_rule
from pants.engine.selectors import Get
from pants.engine.unions import UnionRule
from pants.option.global_options import GlobMatchErrorBehavior
from pants.python.python_setup import PythonSetup

Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/python/lint/black/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ python_library(
'src/python/pants/engine:isolated_process',
'src/python/pants/engine:rules',
'src/python/pants/engine:selectors',
'src/python/pants/engine:unions',
'src/python/pants/option',
'src/python/pants/python',
],
Expand Down
3 changes: 2 additions & 1 deletion src/python/pants/backend/python/lint/black/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
)
from pants.engine.fs import Digest, DirectoriesToMerge, PathGlobs, Snapshot
from pants.engine.isolated_process import FallibleProcessResult, Process, ProcessResult
from pants.engine.rules import UnionRule, named_rule, rule, subsystem_rule
from pants.engine.rules import named_rule, rule, subsystem_rule
from pants.engine.selectors import Get
from pants.engine.unions import UnionRule
from pants.option.global_options import GlobMatchErrorBehavior
from pants.python.python_setup import PythonSetup

Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/python/lint/docformatter/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ python_library(
'src/python/pants/engine:isolated_process',
'src/python/pants/engine:rules',
'src/python/pants/engine:selectors',
'src/python/pants/engine:unions',
'src/python/pants/option',
'src/python/pants/python',
],
Expand Down
3 changes: 2 additions & 1 deletion src/python/pants/backend/python/lint/docformatter/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
)
from pants.engine.fs import Digest, DirectoriesToMerge
from pants.engine.isolated_process import FallibleProcessResult, Process, ProcessResult
from pants.engine.rules import UnionRule, named_rule, rule, subsystem_rule
from pants.engine.rules import named_rule, rule, subsystem_rule
from pants.engine.selectors import Get
from pants.engine.unions import UnionRule
from pants.python.python_setup import PythonSetup


Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/python/lint/flake8/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ python_tests(
'src/python/pants/engine:fs',
'src/python/pants/engine:rules',
'src/python/pants/engine:selectors',
'src/python/pants/engine:unions',
'src/python/pants/engine/legacy:structs',
'src/python/pants/source',
'src/python/pants/testutil:interpreter_selection_utils',
Expand Down
3 changes: 2 additions & 1 deletion src/python/pants/backend/python/lint/flake8/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
)
from pants.engine.fs import Digest, DirectoriesToMerge, PathGlobs, Snapshot
from pants.engine.isolated_process import FallibleProcessResult, Process
from pants.engine.rules import UnionRule, named_rule, subsystem_rule
from pants.engine.rules import named_rule, subsystem_rule
from pants.engine.selectors import Get
from pants.engine.unions import UnionRule
from pants.option.global_options import GlobMatchErrorBehavior
from pants.python.python_setup import PythonSetup

Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/python/lint/isort/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ python_tests(
'src/python/pants/engine:fs',
'src/python/pants/engine:rules',
'src/python/pants/engine:selectors',
'src/python/pants/engine:unions',
'src/python/pants/engine/legacy:structs',
'src/python/pants/source',
'src/python/pants/testutil:test_base',
Expand Down
3 changes: 2 additions & 1 deletion src/python/pants/backend/python/lint/isort/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
)
from pants.engine.fs import Digest, DirectoriesToMerge, PathGlobs, Snapshot
from pants.engine.isolated_process import FallibleProcessResult, Process, ProcessResult
from pants.engine.rules import UnionRule, named_rule, rule, subsystem_rule
from pants.engine.rules import named_rule, rule, subsystem_rule
from pants.engine.selectors import Get
from pants.engine.unions import UnionRule
from pants.option.custom_types import GlobExpansionConjunction
from pants.option.global_options import GlobMatchErrorBehavior
from pants.python.python_setup import PythonSetup
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/python/lint/pylint/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ python_library(
'src/python/pants/engine:isolated_process',
'src/python/pants/engine:rules',
'src/python/pants/engine:selectors',
'src/python/pants/engine:unions',
'src/python/pants/option',
],
tags = {"partially_type_checked"},
Expand Down
3 changes: 2 additions & 1 deletion src/python/pants/backend/python/lint/pylint/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
from pants.engine.addresses import Addresses
from pants.engine.fs import Digest, DirectoriesToMerge, PathGlobs, Snapshot
from pants.engine.isolated_process import FallibleProcessResult, Process
from pants.engine.rules import UnionRule, named_rule, subsystem_rule
from pants.engine.rules import named_rule, subsystem_rule
from pants.engine.selectors import Get
from pants.engine.target import Dependencies, Targets
from pants.engine.unions import UnionRule
from pants.option.global_options import GlobMatchErrorBehavior
from pants.python.python_setup import PythonSetup

Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/python/lint/python_fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
)
from pants.core.util_rules.determine_source_files import AllSourceFilesRequest, SourceFiles
from pants.engine.fs import Digest, Snapshot
from pants.engine.objects import union
from pants.engine.rules import UnionMembership, UnionRule, rule
from pants.engine.rules import rule
from pants.engine.selectors import Get
from pants.engine.unions import UnionMembership, UnionRule, union


@dataclass(frozen=True)
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/python/rules/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ python_library(
'src/python/pants/engine:rules',
'src/python/pants/engine:selectors',
'src/python/pants/engine:target',
'src/python/pants/engine:unions',
'src/python/pants/option',
'src/python/pants/python',
'src/python/pants/source:source',
Expand Down
3 changes: 2 additions & 1 deletion src/python/pants/backend/python/rules/pytest_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
InputFilesContent,
)
from pants.engine.isolated_process import Process, ProcessResult
from pants.engine.rules import RootRule, UnionRule, named_rule, rule, subsystem_rule
from pants.engine.rules import RootRule, named_rule, rule, subsystem_rule
from pants.engine.selectors import Get, MultiGet
from pants.engine.target import Sources, Targets, TransitiveTargets
from pants.engine.unions import UnionRule
from pants.python.python_setup import PythonSetup
from pants.source.source_root import SourceRootConfig

Expand Down
3 changes: 2 additions & 1 deletion src/python/pants/backend/python/rules/pytest_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
from pants.engine.fs import Digest, DirectoriesToMerge, InputFilesContent
from pants.engine.interactive_runner import InteractiveProcessRequest
from pants.engine.isolated_process import FallibleProcessResult, Process
from pants.engine.rules import UnionRule, named_rule, rule, subsystem_rule
from pants.engine.rules import named_rule, rule, subsystem_rule
from pants.engine.selectors import Get, MultiGet
from pants.engine.target import Targets, TransitiveTargets
from pants.engine.unions import UnionRule
from pants.option.global_options import GlobalOptions
from pants.python.python_setup import PythonSetup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
from pants.core.goals.binary import BinaryConfiguration, CreatedBinary
from pants.core.util_rules.determine_source_files import AllSourceFilesRequest, SourceFiles
from pants.engine.addresses import Addresses
from pants.engine.rules import UnionRule, rule
from pants.engine.rules import rule
from pants.engine.selectors import Get
from pants.engine.unions import UnionRule


@dataclass(frozen=True)
Expand Down
3 changes: 2 additions & 1 deletion src/python/pants/backend/python/rules/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from pants.backend.python.subsystems.ipython import IPython
from pants.core.goals.repl import ReplBinary, ReplImplementation
from pants.engine.addresses import Addresses
from pants.engine.rules import UnionRule, rule, subsystem_rule
from pants.engine.rules import rule, subsystem_rule
from pants.engine.selectors import Get
from pants.engine.unions import UnionRule


class PythonRepl(ReplImplementation):
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/bin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ python_library(
'src/python/pants/engine:mapper',
'src/python/pants/engine:native',
'src/python/pants/engine:parser',
'src/python/pants/engine:rules',
'src/python/pants/engine:scheduler',
'src/python/pants/engine:unions',
'src/python/pants/goal',
'src/python/pants/goal:context',
'src/python/pants/goal:run_tracker',
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/bin/daemon_pants_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pants.base.exception_sink import ExceptionSink
from pants.base.exiter import PANTS_FAILED_EXIT_CODE, PANTS_SUCCEEDED_EXIT_CODE, ExitCode, Exiter
from pants.bin.local_pants_runner import LocalPantsRunner
from pants.engine.rules import UnionMembership
from pants.engine.unions import UnionMembership
from pants.help.help_printer import HelpPrinter
from pants.init.specs_calculator import SpecsCalculator
from pants.init.util import clean_global_runtime_state
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/bin/local_pants_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pants.bin.goal_runner import GoalRunner
from pants.build_graph.build_configuration import BuildConfiguration
from pants.engine.native import Native
from pants.engine.rules import UnionMembership
from pants.engine.unions import UnionMembership
from pants.goal.run_tracker import RunTracker
from pants.help.help_printer import HelpPrinter
from pants.init.engine_initializer import EngineInitializer, LegacyGraphSession
Expand Down
2 changes: 2 additions & 0 deletions src/python/pants/core/goals/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ python_library(
'src/python/pants/engine:rules',
'src/python/pants/engine:selectors',
'src/python/pants/engine:target',
'src/python/pants/engine:unions',
'src/python/pants/option',
'src/python/pants/util:contextutil',
],
Expand All @@ -40,6 +41,7 @@ python_tests(
'src/python/pants/engine:interactive_runner',
'src/python/pants/engine:rules',
'src/python/pants/engine:target',
'src/python/pants/engine:unions',
'src/python/pants/testutil/engine:util',
'src/python/pants/testutil:test_base',
'src/python/pants/option',
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/core/goals/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from pants.engine.console import Console
from pants.engine.fs import Digest, DirectoriesToMerge, DirectoryToMaterialize, Workspace
from pants.engine.goal import Goal, GoalSubsystem, LineOriented
from pants.engine.objects import union
from pants.engine.rules import UnionMembership, goal_rule
from pants.engine.rules import goal_rule
from pants.engine.selectors import Get, MultiGet
from pants.engine.target import Field, RegisteredTargetTypes, Target, TargetsWithOrigins
from pants.engine.unions import UnionMembership, union


# TODO: Factor this out once porting fmt.py and lint.py to the Target API.
Expand Down
5 changes: 3 additions & 2 deletions src/python/pants/core/goals/fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
)
from pants.engine.goal import Goal, GoalSubsystem
from pants.engine.isolated_process import ProcessResult
from pants.engine.objects import Collection, union
from pants.engine.rules import UnionMembership, goal_rule
from pants.engine.objects import Collection
from pants.engine.rules import goal_rule
from pants.engine.selectors import Get, MultiGet
from pants.engine.target import Field, Target, TargetsWithOrigins, TargetWithOrigin
from pants.engine.unions import UnionMembership, union


@dataclass(frozen=True)
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/core/goals/fmt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
FileContent,
Workspace,
)
from pants.engine.rules import UnionMembership
from pants.engine.target import Sources, Target, TargetsWithOrigins, TargetWithOrigin
from pants.engine.unions import UnionMembership
from pants.testutil.engine.util import MockConsole, MockGet, create_goal_subsystem, run_rule
from pants.testutil.test_base import TestBase
from pants.util.ordered_set import OrderedSet
Expand Down
5 changes: 3 additions & 2 deletions src/python/pants/core/goals/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
from pants.engine.console import Console
from pants.engine.goal import Goal, GoalSubsystem
from pants.engine.isolated_process import FallibleProcessResult
from pants.engine.objects import Collection, union
from pants.engine.rules import UnionMembership, goal_rule
from pants.engine.objects import Collection
from pants.engine.rules import goal_rule
from pants.engine.selectors import Get, MultiGet
from pants.engine.target import Field, Sources, Target, TargetsWithOrigins, TargetWithOrigin
from pants.engine.unions import UnionMembership, union


@dataclass(frozen=True)
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/core/goals/lint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
ConfigurationsWithSourcesRequest,
)
from pants.engine.addresses import Address
from pants.engine.rules import UnionMembership
from pants.engine.target import Sources, Target, TargetsWithOrigins, TargetWithOrigin
from pants.engine.unions import UnionMembership
from pants.testutil.engine.util import MockConsole, MockGet, create_goal_subsystem, run_rule
from pants.testutil.test_base import TestBase
from pants.util.ordered_set import OrderedSet
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/core/goals/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from pants.engine.fs import Digest, DirectoryToMaterialize, Workspace
from pants.engine.goal import Goal, GoalSubsystem
from pants.engine.interactive_runner import InteractiveProcessRequest, InteractiveRunner
from pants.engine.objects import union
from pants.engine.rules import UnionMembership, goal_rule
from pants.engine.rules import goal_rule
from pants.engine.selectors import Get
from pants.engine.target import Field, Target, Targets, TransitiveTargets
from pants.engine.unions import UnionMembership, union
from pants.option.global_options import GlobalOptions
from pants.util.contextutil import temporary_dir

Expand Down
3 changes: 2 additions & 1 deletion src/python/pants/core/goals/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
from pants.engine.fs import DirectoryToMaterialize, Workspace
from pants.engine.goal import Goal, GoalSubsystem
from pants.engine.interactive_runner import InteractiveProcessRequest, InteractiveRunner
from pants.engine.rules import UnionMembership, goal_rule
from pants.engine.rules import goal_rule
from pants.engine.selectors import Get
from pants.engine.target import RegisteredTargetTypes, TargetsWithOrigins
from pants.engine.unions import UnionMembership
from pants.option.custom_types import shell_str
from pants.option.global_options import GlobalOptions
from pants.util.contextutil import temporary_dir
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/core/goals/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from pants.engine.addresses import Address
from pants.engine.fs import Digest, FileContent, InputFilesContent, Workspace
from pants.engine.interactive_runner import InteractiveProcessRequest, InteractiveRunner
from pants.engine.rules import UnionMembership
from pants.engine.target import RegisteredTargetTypes, Target, TargetsWithOrigins, TargetWithOrigin
from pants.engine.unions import UnionMembership
from pants.option.global_options import GlobalOptions
from pants.testutil.engine.util import (
MockConsole,
Expand Down
5 changes: 3 additions & 2 deletions src/python/pants/core/goals/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from pants.engine.goal import Goal, GoalSubsystem
from pants.engine.interactive_runner import InteractiveProcessRequest, InteractiveRunner
from pants.engine.isolated_process import FallibleProcessResult
from pants.engine.objects import Collection, union
from pants.engine.rules import UnionMembership, goal_rule, rule
from pants.engine.objects import Collection
from pants.engine.rules import goal_rule, rule
from pants.engine.selectors import Get, MultiGet
from pants.engine.target import (
Field,
Expand All @@ -34,6 +34,7 @@
TargetsWithOrigins,
TargetWithOrigin,
)
from pants.engine.unions import UnionMembership, union

# TODO(#6004): use proper Logging singleton, rather than static logger.
logger = logging.getLogger(__name__)
Expand Down
Loading

0 comments on commit cdb3cf9

Please sign in to comment.