Skip to content

Commit

Permalink
Split TargetRoots and TargetRootsCalculator to allow TargetRoots to b…
Browse files Browse the repository at this point in the history
…e used more widely without a cycle.
  • Loading branch information
stuhood committed Mar 13, 2018
1 parent 502c30a commit b0c2139
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 28 deletions.
8 changes: 8 additions & 0 deletions src/python/pants/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ python_library(
],
)

python_library(
name = 'target_roots',
sources = ['target_roots.py'],
dependencies = [
'src/python/pants/util:objects',
],
)

python_library(
name = 'worker_pool',
sources = ['worker_pool.py'],
Expand Down
28 changes: 28 additions & 0 deletions src/python/pants/base/target_roots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# coding=utf-8
# Copyright 2016 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from pants.util.objects import datatype


class InvalidSpecConstraint(Exception):
"""Raised when invalid constraints are given via target specs and arguments like --changed*."""


class TargetRoots(object):
"""Determines the target roots for a given pants run."""


class ChangedTargetRoots(datatype('ChangedTargetRoots', ['addresses']), TargetRoots):
"""Target roots that have been altered by `--changed` functionality.
Contains a list of `Address`es rather than `Spec`s, because all inputs have already been
resolved, and are known to exist.
"""


class LiteralTargetRoots(datatype('LiteralTargetRoots', ['specs']), TargetRoots):
"""User defined target roots, as pants.base.specs.Spec objects."""
2 changes: 1 addition & 1 deletion src/python/pants/bin/engine_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from pants.base.build_environment import get_buildroot, get_scm
from pants.base.file_system_project_tree import FileSystemProjectTree
from pants.base.target_roots import ChangedTargetRoots, LiteralTargetRoots
from pants.engine.build_files import BuildFileAddresses, create_graph_rules
from pants.engine.fs import create_fs_rules
from pants.engine.isolated_process import create_process_rules
Expand All @@ -25,7 +26,6 @@
from pants.engine.parser import SymbolTable
from pants.engine.scheduler import LocalScheduler
from pants.init.options_initializer import OptionsInitializer
from pants.init.target_roots import ChangedTargetRoots, LiteralTargetRoots
from pants.option.options_bootstrapper import OptionsBootstrapper
from pants.scm.change_calculator import EngineChangeCalculator

Expand Down
12 changes: 7 additions & 5 deletions src/python/pants/bin/goal_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import logging
import sys

from twitter.common.collections import OrderedSet

from pants.base.cmd_line_spec_parser import CmdLineSpecParser
from pants.base.workunit import WorkUnit, WorkUnitLabel
from pants.bin.engine_initializer import EngineInitializer
Expand All @@ -21,11 +23,11 @@
from pants.goal.run_tracker import RunTracker
from pants.help.help_printer import HelpPrinter
from pants.init.subprocess import Subprocess
from pants.init.target_roots import TargetRoots
from pants.init.target_roots_calculator import TargetRootsCalculator
from pants.java.nailgun_executor import NailgunProcessGroup
from pants.option.ranked_value import RankedValue
from pants.reporting.reporting import Reporting
from pants.scm.subsystems.changed import Changed
from pants.scm.subsystems.changed import Changed, ChangedRequest
from pants.source.source_root import SourceRootConfig
from pants.task.task import QuietTaskMixin
from pants.util.filtering import create_filters, wrap_filters
Expand Down Expand Up @@ -104,9 +106,9 @@ def _init_graph(self, pants_ignore_patterns, build_ignore_patterns,
include_trace_on_error=self._options.for_global_scope().print_exception_stacktrace
)

target_roots = TargetRoots.create(options=self._options,
build_root=self._root_dir,
change_calculator=graph_helper.change_calculator)
target_roots = TargetRootsCalculator.create(options=self._options,
build_root=self._root_dir,
change_calculator=graph_helper.change_calculator)
graph, address_mapper = graph_helper.create_build_graph(target_roots, self._root_dir)
return graph, address_mapper, graph_helper.scheduler, target_roots

Expand Down
1 change: 1 addition & 0 deletions src/python/pants/build_graph/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ python_library(
'src/python/pants/base:payload',
'src/python/pants/base:payload_field',
'src/python/pants/base:specs',
'src/python/pants/base:target_roots',
'src/python/pants/base:validation',
'src/python/pants/option',
'src/python/pants/source',
Expand Down
1 change: 0 additions & 1 deletion src/python/pants/build_graph/build_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from pants.build_graph.address_lookup_error import AddressLookupError
from pants.build_graph.injectables_mixin import InjectablesMixin
from pants.build_graph.target import Target
from pants.init.target_roots import ChangedTargetRoots, LiteralTargetRoots
from pants.util.meta import AbstractClass


Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/engine/legacy/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pants.base.exceptions import TargetDefinitionException
from pants.base.parse_context import ParseContext
from pants.base.specs import SingleAddress
from pants.base.target_roots import ChangedTargetRoots, LiteralTargetRoots
from pants.build_graph.address import Address
from pants.build_graph.address_lookup_error import AddressLookupError
from pants.build_graph.build_graph import BuildGraph
Expand All @@ -24,7 +25,6 @@
from pants.engine.mapper import ResolveError
from pants.engine.rules import TaskRule, rule
from pants.engine.selectors import Select, SelectDependencies, SelectProjection, SelectTransitive
from pants.init.target_roots import ChangedTargetRoots, LiteralTargetRoots
from pants.source.wrapped_globs import EagerFilesetWithSpec, FilesetRelPathWrapper
from pants.util.dirutil import fast_relpath
from pants.util.objects import datatype
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/init/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ python_library(
'src/python/pants:version',
'src/python/pants/base:build_environment',
'src/python/pants/base:exceptions',
'src/python/pants/base:target_roots',
'src/python/pants/binaries:binary_util',
'src/python/pants/build_graph',
'src/python/pants/core_tasks',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pants.base.build_environment import get_buildroot
from pants.base.cmd_line_spec_parser import CmdLineSpecParser
from pants.base.specs import SingleAddress
from pants.base.target_roots import ChangedTargetRoots, LiteralTargetRoots
from pants.scm.subsystems.changed import ChangedRequest
from pants.util.objects import datatype

Expand All @@ -23,7 +24,7 @@ class InvalidSpecConstraint(Exception):
"""Raised when invalid constraints are given via target specs and arguments like --changed*."""


class TargetRoots(object):
class TargetRootsCalculator(object):
"""Determines the target roots for a given pants run."""

@classmethod
Expand Down Expand Up @@ -68,15 +69,3 @@ def create(cls, options, build_root=None, change_calculator=None):
return ChangedTargetRoots(tuple(changed_addresses))

return LiteralTargetRoots(spec_roots)


class ChangedTargetRoots(datatype('ChangedTargetRoots', ['addresses']), TargetRoots):
"""Target roots that have been altered by `--changed` functionality.
Contains a list of `Address`es rather than `Spec`s, because all inputs have already been
resolved, and are known to exist.
"""


class LiteralTargetRoots(datatype('LiteralTargetRoots', ['specs']), TargetRoots):
"""User defined target roots, as pants.base.specs.Spec objects."""
4 changes: 2 additions & 2 deletions src/python/pants/pantsd/pants_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

from pants.base.build_environment import get_buildroot
from pants.base.exiter import Exiter
from pants.init.target_roots_calculator import TargetRootsCalculator
from pants.bin.daemon_pants_runner import DaemonExiter, DaemonPantsRunner
from pants.bin.engine_initializer import EngineInitializer
from pants.engine.native import Native
from pants.init.target_roots import TargetRoots
from pants.logging.setup import setup_logging
from pants.option.arg_splitter import GLOBAL_SCOPE
from pants.option.options_bootstrapper import OptionsBootstrapper
Expand Down Expand Up @@ -146,7 +146,7 @@ def _setup_services(build_root, bootstrap_options, legacy_graph_helper, watchman
bind_addr=(bootstrap_options.pantsd_pailgun_host, bootstrap_options.pantsd_pailgun_port),
exiter_class=DaemonExiter,
runner_class=DaemonPantsRunner,
target_roots_class=TargetRoots,
target_roots_calculator=TargetRootsCalculator,
scheduler_service=scheduler_service
)

Expand Down
9 changes: 5 additions & 4 deletions src/python/pants/pantsd/service/pailgun_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@
class PailgunService(PantsService):
"""A service that runs the Pailgun server."""

def __init__(self, bind_addr, exiter_class, runner_class, target_roots_class, scheduler_service):
def __init__(self, bind_addr, exiter_class, runner_class, target_roots_calculator, scheduler_service):
"""
:param tuple bind_addr: The (hostname, port) tuple to bind the Pailgun server to.
:param class exiter_class: The `Exiter` class to be used for Pailgun runs.
:param class runner_class: The `PantsRunner` class to be used for Pailgun runs.
:param class target_roots_class: The `TargetRoots` class to be used for target root parsing.
:param class target_roots_calculator: The `TargetRootsCalculator` class to be used for target
root parsing.
:param SchedulerService scheduler_service: The SchedulerService instance for access to the
resident scheduler.
"""
super(PailgunService, self).__init__()
self._bind_addr = bind_addr
self._exiter_class = exiter_class
self._runner_class = runner_class
self._target_roots_class = target_roots_class
self._target_roots_calculator = target_roots_calculator
self._scheduler_service = scheduler_service

self._logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -63,7 +64,7 @@ def runner_factory(sock, arguments, environment):

self._logger.debug('execution commandline: %s', arguments)
options, _ = OptionsInitializer(OptionsBootstrapper(args=arguments)).setup(init_logging=False)
target_roots = self._target_roots_class.create(
target_roots = self._target_roots_calculator.create(
options,
change_calculator=self._scheduler_service.change_calculator
)
Expand Down
2 changes: 1 addition & 1 deletion tests/python/pants_test/engine/legacy/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

import mock

from pants.base.target_roots import TargetRoots
from pants.bin.engine_initializer import EngineInitializer
from pants.build_graph.address import Address
from pants.build_graph.address_lookup_error import AddressLookupError
from pants.build_graph.build_file_aliases import BuildFileAliases, TargetMacro
from pants.build_graph.target import Target
from pants.init.options_initializer import OptionsInitializer
from pants.init.target_roots import TargetRoots
from pants.option.options_bootstrapper import OptionsBootstrapper
from pants.subsystem.subsystem import Subsystem
from pants.util.contextutil import temporary_dir
Expand Down

0 comments on commit b0c2139

Please sign in to comment.