Skip to content

Commit

Permalink
fingerprint=True -> daemon=True
Browse files Browse the repository at this point in the history
  • Loading branch information
kwlzn committed Nov 4, 2017
1 parent dc0b9b9 commit 279678a
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 86 deletions.
4 changes: 2 additions & 2 deletions src/python/pants/bin/pants_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def __init__(self, exiter, args=None, env=None):

def run(self):
options_bootstrapper = OptionsBootstrapper(env=self._env, args=self._args)
bootstrap_options = options_bootstrapper.get_bootstrap_options().for_global_scope()
bootstrap_options = options_bootstrapper.get_bootstrap_options()

if bootstrap_options.enable_pantsd:
if bootstrap_options.for_global_scope().enable_pantsd:
try:
return RemotePantsRunner(self._exiter, self._args, self._env, bootstrap_options).run()
except RemotePantsRunner.Fallback as e:
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/bin/remote_pants_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def handle_control_c(signum, frame):

def _setup_logging(self):
"""Sets up basic stdio logging for the thin client."""
log_level = logging.getLevelName(self._bootstrap_options.level.upper())
log_level = logging.getLevelName(self._bootstrap_options.for_global_scope().level.upper())

formatter = logging.Formatter('%(levelname)s] %(message)s')
handler = logging.StreamHandler(sys.stdout)
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/core_tasks/pantsd_kill.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class PantsDaemonKill(Task):

def execute(self):
try:
PantsDaemon.Factory.create(self.get_options()).terminate()
PantsDaemon.Factory.create(self.context.options).terminate()
except ProcessManager.NonResponsiveProcess as e:
raise TaskError('failure while terminating pantsd: {}'.format(e))
74 changes: 39 additions & 35 deletions src/python/pants/option/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def register_bootstrap_options(cls, register):
# setup a 'WARN' logging level name that maps to 'WARNING'.
logging.addLevelName(logging.WARNING, 'WARN')
register('-l', '--level', choices=['debug', 'info', 'warn'], default='info', recursive=True,
help='Set the logging level.')
daemon=True, help='Set the logging level.')
register('-q', '--quiet', type=bool, recursive=True,
help='Squelches most console output. NOTE: Some tasks default to behaving quietly: '
'inverting this option supports making them noisier than they would be otherwise.')
Expand All @@ -63,15 +63,15 @@ def register_bootstrap_options(cls, register):
# setup scripts, runner scripts, IDE plugins, etc., may grep this out of pants.ini
# and use it to select the right version.
# Note that to print the version of the pants instance you're running, use -v, -V or --version.
register('--pants-version', advanced=True, default=pants_version(),
register('--pants-version', advanced=True, default=pants_version(), daemon=True,
help='Use this pants version.')

register('--plugins', advanced=True, type=list, help='Load these plugins.')
register('--plugin-cache-dir', advanced=True,
register('--plugins', advanced=True, type=list, daemon=True, help='Load these plugins.')
register('--plugin-cache-dir', advanced=True, daemon=True,
default=os.path.join(get_pants_cachedir(), 'plugins'),
help='Cache resolved plugin requirements here.')

register('--backend-packages', advanced=True, type=list,
register('--backend-packages', advanced=True, type=list, daemon=True,
default=['pants.backend.graph_info',
'pants.backend.python',
'pants.backend.jvm',
Expand All @@ -88,86 +88,87 @@ def register_bootstrap_options(cls, register):
'Add contrib and custom backends to this list.')

register('--pants-bootstrapdir', advanced=True, metavar='<dir>', default=get_pants_cachedir(),
help='Use this dir for global cache.')
daemon=True, help='Use this dir for global cache.')
register('--pants-configdir', advanced=True, metavar='<dir>', default=get_pants_configdir(),
help='Use this dir for global config files.')
register('--pants-workdir', advanced=True, metavar='<dir>',
daemon=True, help='Use this dir for global config files.')
register('--pants-workdir', advanced=True, metavar='<dir>', daemon=True,
default=os.path.join(buildroot, '.pants.d'),
help='Write intermediate output files to this dir.')
register('--pants-supportdir', advanced=True, metavar='<dir>',
register('--pants-supportdir', advanced=True, metavar='<dir>', daemon=True,
default=os.path.join(buildroot, 'build-support'),
help='Use support files from this dir.')
register('--pants-distdir', advanced=True, metavar='<dir>',
register('--pants-distdir', advanced=True, metavar='<dir>', daemon=True,
default=default_distdir,
help='Write end-product artifacts to this dir. If you modify this path, you '
'should also update --build-ignore and --pants-ignore to include the '
'custom dist dir path as well.')
register('--pants-subprocessdir', advanced=True, default=os.path.join(buildroot, '.pids'),
daemon=True,
help='The directory to use for tracking subprocess metadata, if any. This should '
'live outside of the dir used by `--pants-workdir` to allow for tracking '
'subprocesses that outlive the workdir data (e.g. `./pants server`).')
register('--pants-config-files', advanced=True, type=list,
register('--pants-config-files', advanced=True, type=list, daemon=True,
default=[get_default_pants_config_file()], help='Paths to Pants config files.')
# TODO: Deprecate the --pantsrc/--pantsrc-files options? This would require being able
# to set extra config file locations in an initial bootstrap config file.
register('--config-override', advanced=True, type=list, metavar='<path>',
register('--config-override', advanced=True, type=list, metavar='<path>', daemon=True,
removal_version='1.6.0.dev0',
removal_hint='Use --pants-config-files=<second config file path> instead.',
help='A second config file, to override pants.ini.')
register('--pantsrc', advanced=True, type=bool, default=True,
register('--pantsrc', advanced=True, type=bool, default=True, daemon=True,
help='Use pantsrc files.')
register('--pantsrc-files', advanced=True, type=list, metavar='<path>',
register('--pantsrc-files', advanced=True, type=list, metavar='<path>', daemon=True,
default=['/etc/pantsrc', '~/.pants.rc'],
help='Override config with values from these files. '
'Later files override earlier ones.')
register('--pythonpath', advanced=True, type=list,
register('--pythonpath', advanced=True, type=list, daemon=True,
help='Add these directories to PYTHONPATH to search for plugins.')
register('--target-spec-file', type=list, dest='target_spec_files',
help='Read additional specs from this file, one per line')
register('--verify-config', type=bool, default=True,
help='Verify that all config file values correspond to known options.')
register('--build-ignore', advanced=True, type=list, fromfile=True,
register('--build-ignore', advanced=True, type=list, fromfile=True, daemon=True,
default=['.*/', default_rel_distdir, 'bower_components/',
'node_modules/', '*.egg-info/'],
help='Paths to ignore when identifying BUILD files. '
'This does not affect any other filesystem operations. '
'Patterns use the gitignore pattern syntax (https://git-scm.com/docs/gitignore).')
register('--pants-ignore', advanced=True, type=list, fromfile=True,
register('--pants-ignore', advanced=True, type=list, fromfile=True, daemon=True,
default=['.*/', default_rel_distdir],
help='Paths to ignore for all filesystem operations performed by pants '
'(e.g. BUILD file scanning, glob matching, etc). '
'Patterns use the gitignore syntax (https://git-scm.com/docs/gitignore). '
'This currently only affects the v2 engine. '
'To experiment with v2 engine, try --enable-v2-engine option.')
register('--exclude-target-regexp', advanced=True, type=list, default=[],
metavar='<regexp>',
help='Exclude target roots that match these regexes.')
metavar='<regexp>', help='Exclude target roots that match these regexes.')
register('--subproject-roots', type=list, advanced=True, fromfile=True, default=[],
daemon=True,
help='Paths that correspond with build roots for any subproject that this '
'project depends on.')

# These logging options are registered in the bootstrap phase so that plugins can log during
# registration and not so that their values can be interpolated in configs.
register('-d', '--logdir', advanced=True, metavar='<dir>',
register('-d', '--logdir', advanced=True, metavar='<dir>', daemon=True,
help='Write logs to files under this directory.')

# This facilitates bootstrap-time configuration of pantsd usage such that we can
# determine whether or not to use the Pailgun client to invoke a given pants run
# without resorting to heavier options parsing.
register('--enable-pantsd', advanced=True, type=bool, default=False,
register('--enable-pantsd', advanced=True, type=bool, default=False, daemon=True,
help='Enables use of the pants daemon (and implicitly, the v2 engine). (Beta)')

# This facilitates use of the v2 engine, sans daemon.
# TODO: Add removal_version='1.5.0.dev0' before 1.4 lands.
register('--enable-v2-engine', advanced=True, type=bool, default=True,
register('--enable-v2-engine', advanced=True, type=bool, default=True, daemon=True,
help='Enables use of the v2 engine.')

# These facilitate configuring the native engine.
register('--native-engine-version', advanced=True, default='DEPRECATED',
register('--native-engine-version', advanced=True, default='DEPRECATED', daemon=True,
removal_version='1.6.0.dev0',
removal_hint='Unused, the native engine is now embedded in the pantsbuild.pants wheel',
help='Native engine version.')
register('--native-engine-supportdir', advanced=True, default='DEPRECATED',
register('--native-engine-supportdir', advanced=True, default='DEPRECATED', daemon=True,
removal_version='1.6.0.dev0',
removal_hint='Unused, the native engine is now embedded in the pantsbuild.pants wheel',
help='Find native engine binaries under this dir. Used as part of the path to '
Expand All @@ -177,43 +178,46 @@ def register_bootstrap_options(cls, register):
'of the directory will be overwritten if any filenames collide.')

# BinaryUtil options.
register('--binaries-baseurls', type=list, advanced=True,
register('--binaries-baseurls', type=list, advanced=True, daemon=True,
default=['https://binaries.pantsbuild.org'],
help='List of URLs from which binary tools are downloaded. URLs are '
'searched in order until the requested path is found.')
register('--binaries-fetch-timeout-secs', type=int, default=30, advanced=True,
daemon=True,
help='Timeout in seconds for URL reads when fetching binary tools from the '
'repos specified by --baseurls.')
register('--binaries-path-by-id', type=dict, advanced=True,
register('--binaries-path-by-id', type=dict, advanced=True, daemon=True,
help=('Maps output of uname for a machine to a binary search path. e.g. '
'{("darwin", "15"): ["mac", "10.11"]), ("linux", "arm32"): ["linux"'
', "arm32"]}'))

# Pants Daemon options.
register('--pantsd-pailgun-host', advanced=True, default='127.0.0.1',
register('--pantsd-pailgun-host', advanced=True, default='127.0.0.1', daemon=True,
help='The host to bind the pants nailgun server to.')
register('--pantsd-pailgun-port', advanced=True, type=int, default=0,
register('--pantsd-pailgun-port', advanced=True, type=int, default=0, daemon=True,
help='The port to bind the pants nailgun server to. Defaults to a random port.')
register('--pantsd-log-dir', advanced=True, default=None,
register('--pantsd-log-dir', advanced=True, default=None, daemon=True,
help='The directory to log pantsd output to.')
register('--pantsd-fs-event-detection', advanced=True, type=bool,
register('--pantsd-fs-event-detection', advanced=True, type=bool, daemon=True,
removal_version='1.5.0.dev0',
removal_hint='This option is now implied by `--enable-pantsd`.',
help='Whether or not to use filesystem event detection.')
register('--pantsd-fs-event-workers', advanced=True, type=int, default=4,
register('--pantsd-fs-event-workers', advanced=True, type=int, default=4, daemon=True,
help='The number of workers to use for the filesystem event service executor pool.')

# Watchman options.
register('--watchman-version', advanced=True, default='4.5.0', help='Watchman version.')
register('--watchman-supportdir', advanced=True, default='bin/watchman',
register('--watchman-version', advanced=True, default='4.5.0', daemon=True,
help='Watchman version.')
register('--watchman-supportdir', advanced=True, default='bin/watchman', daemon=True,
help='Find watchman binaries under this dir. Used as part of the path to lookup '
'the binary with --binary-util-baseurls and --pants-bootstrapdir.')
register('--watchman-startup-timeout', type=float, advanced=True, default=30.0,
daemon=True,
help='The watchman socket timeout (in seconds) for the initial `watch-project` command. '
'This may need to be set higher for larger repos due to watchman startup cost.')
register('--watchman-socket-timeout', type=float, advanced=True, default=5.0,
register('--watchman-socket-timeout', type=float, advanced=True, default=5.0, daemon=True,
help='The watchman client socket timeout in seconds.')
register('--watchman-socket-path', type=str, advanced=True, default=None,
register('--watchman-socket-path', type=str, advanced=True, default=None, daemon=True,
help='The path to the watchman UNIX socket. This can be overridden if the default '
'absolute path length exceeds the maximum allowed by the OS.')

Expand Down
22 changes: 0 additions & 22 deletions src/python/pants/option/option_value_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
unicode_literals, with_statement)

import copy
import hashlib

import six

from pants.option.ranked_value import RankedValue

Expand Down Expand Up @@ -146,22 +143,3 @@ def __copy__(self):
ret = type(self)()
ret._value_map = copy.copy(self._value_map)
return ret

def sha1(self, exclude_keys=None):
"""Computes and returns the current sha1 fingerprint for this `OptionValueContainer`.
:param list exclude_keys: A list of keys to exclude from fingerprint computation.
"""
exclude_keys = set(exclude_keys or [])
acceptable_types = set((bytes, str, list, tuple, dict, int, float, bool, type(None)))
hasher = hashlib.sha1()
# N.B. This is pre-`sorted()` in `__iter__` above for determinism.
for k in self:
if k in exclude_keys: continue
hasher.update(k)
v = self.get(k)
assert type(v) in acceptable_types, 'unhashable option type: {}'.format(type(v))
# N.B. This relies on implicit string conversion to do the right thing for
# primitive types (e.g. `str([1, 2, 3])` -> "[1, 2, 3]").
hasher.update(six.binary_type(v))
return hasher.hexdigest()
9 changes: 6 additions & 3 deletions src/python/pants/option/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,20 @@ def for_scope(self, scope, inherit_from_enclosing_scope=True):

return values

def get_fingerprintable_for_scope(self, scope, include_passthru=False):
def get_fingerprintable_for_scope(self, scope, include_passthru=False, fingerprint_key=None):
"""Returns a list of fingerprintable (option type, option value) pairs for the given scope.
Fingerprintable options are options registered via a "fingerprint=True" kwarg.
Fingerprintable options are options registered via a "fingerprint=True" kwarg. This flag
can be parameterized with `fingerprint_key` for special cases.
:param str scope: The scope to gather fingerprintable options for.
:param bool include_passthru: Whether to include passthru args captured by `scope` in the
fingerprintable options.
:param string fingerprint_key: The option kwarg to match against (defaults to 'fingerprint').
:API: public
"""
fingerprint_key = fingerprint_key or 'fingerprint'
pairs = []

if include_passthru:
Expand All @@ -341,7 +344,7 @@ def get_fingerprintable_for_scope(self, scope, include_passthru=False):
for (_, kwargs) in sorted(parser.option_registrations_iter()):
if kwargs.get('recursive') and not kwargs.get('recursive_root'):
continue # We only need to fprint recursive options once.
if kwargs.get('fingerprint') is not True:
if kwargs.get(fingerprint_key) is not True:
continue
# Note that we read the value from scope, even if the registration was on an enclosing
# scope, to get the right value for recursive options (and because this mirrors what
Expand Down
32 changes: 31 additions & 1 deletion src/python/pants/option/options_fingerprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import os
from hashlib import sha1

import six

from pants.base.build_environment import get_buildroot
from pants.option.custom_types import UnsetBool, dict_with_files_option, file_option, target_option

Expand All @@ -34,7 +36,32 @@ class OptionsFingerprinter(object):
:API: public
"""

def __init__(self, build_graph):
@classmethod
def combined_options_fingerprint_for_scope(cls, scope, options, fingerprint_key=None,
build_graph=None):
"""Given options and a scope, compute a combined fingerprint for the scope.
:param string scope: The scope to fingerprint.
:param Options options: The `Options` object to fingerprint.
:param string fingerprint_key: The options kwarg to filter against.
:param BuildGraph build_graph: A `BuildGraph` instance, only needed if fingerprinting
target options.
"""
fingerprinter = cls(build_graph)
hasher = sha1()
for (
option_type, option_value
) in options.get_fingerprintable_for_scope(scope, fingerprint_key=fingerprint_key):
hasher.update(
# N.B. `OptionsFingerprinter.fingerprint()` can return `None`,
# so we always cast to bytes here.
six.binary_type(
fingerprinter.fingerprint(option_type, option_value)
)
)
return hasher.hexdigest()

def __init__(self, build_graph=None):
self._build_graph = build_graph

def fingerprint(self, option_type, option_val):
Expand Down Expand Up @@ -63,6 +90,9 @@ def fingerprint(self, option_type, option_val):

def _fingerprint_target_specs(self, specs):
"""Returns a fingerprint of the targets resolved from given target specs."""
assert self._build_graph is not None, (
'cannot fingerprint specs `{}` without a `BuildGraph`'.format(specs)
)
hasher = sha1()
for spec in sorted(specs):
for target in sorted(self._build_graph.resolve(spec)):
Expand Down
3 changes: 2 additions & 1 deletion src/python/pants/option/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ def _check_deprecated(self, dest, kwargs):
_allowed_registration_kwargs = {
'type', 'member_type', 'choices', 'dest', 'default', 'implicit_value', 'metavar',
'help', 'advanced', 'recursive', 'recursive_root', 'registering_class',
'fingerprint', 'removal_version', 'removal_hint', 'fromfile', 'mutually_exclusive_group'
'fingerprint', 'removal_version', 'removal_hint', 'fromfile', 'mutually_exclusive_group',
'daemon'
}

# TODO: Remove dict_option from here after deprecation is complete.
Expand Down
Loading

0 comments on commit 279678a

Please sign in to comment.