<commit_before># coding=utf-8
# Copyright 2014 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)

import logging
import multiprocessing
import os
import sys

from pants.base.build_environment import (get_buildroot, get_default_pants_config_file,
                                          get_pants_cachedir, get_pants_configdir, pants_version)
from pants.option.arg_splitter import GLOBAL_SCOPE
from pants.option.custom_types import dir_option
from pants.option.optionable import Optionable
from pants.option.scope import ScopeInfo
from pants.subsystem.subsystem_client_mixin import SubsystemClientMixin
from pants.util.memo import memoized_classproperty
from pants.util.objects import datatype


class GlobMatchErrorBehavior(datatype(['failure_behavior'])):
  """Describe the action to perform when matching globs in BUILD files to source files.

  NB: this object is interpreted from within Snapshot::lift_path_globs() -- that method will need to
  be aware of any changes to this object's definition.
  """

  IGNORE = 'ignore'
  WARN = 'warn'
  ERROR = 'error'

  allowed_values = [IGNORE, WARN, ERROR]

  default_value = IGNORE

  default_option_value = WARN

  @memoized_classproperty
  def _singletons(cls):
    return { behavior: cls(behavior) for behavior in cls.allowed_values }

  @classmethod
  def create(cls, value=None):
    if isinstance(value, cls):
      return value
    if not value:
      value = cls.default_value
    return cls._singletons[value]

  def __new__(cls, *args, **kwargs):
    this_object = super(GlobMatchErrorBehavior, cls).__new__(cls, *args, **kwargs)

    if this_object.failure_behavior not in cls.allowed_values:
      raise cls.make_type_error("Value {!r} for failure_behavior must be one of: {!r}."
                                .format(this_object.failure_behavior, cls.allowed_values))

    return this_object


class ExecutionOptions(datatype([
  'remote_store_server',
  'remote_store_thread_count',
  'remote_execution_server',
  'remote_store_chunk_bytes',
  'remote_store_chunk_upload_timeout_seconds',
  'process_execution_parallelism',
])):
  """A collection of all options related to (remote) execution of processes.

  TODO: These options should move to a Subsystem once we add support for "bootstrap" Subsystems (ie,
  allowing Subsystems to be consumed before the Scheduler has been created).
  """

  @classmethod
  def from_bootstrap_options(cls, bootstrap_options):
    cls(
      remote_store_server=bootstrap_options.remote_store_server,
      remote_execution_server=bootstrap_options.remote_execution_server,
      remote_store_thread_count=bootstrap_options.remote_store_thread_count,
      remote_store_chunk_bytes=bootstrap_options.remote_store_chunk_bytes,
      remote_store_chunk_upload_timeout_seconds=bootstrap_options.remote_store_chunk_upload_timeout_seconds,
      process_execution_parallelism=bootstrap_options.process_execution_parallelism,
    )


DEFAULT_EXECUTION_OPTIONS = ExecutionOptions(
    remote_store_server=None,
    remote_store_thread_count=1,
    remote_execution_server=None,
    remote_store_chunk_bytes=1024*1024,
    remote_store_chunk_upload_timeout_seconds=60,
    process_execution_parallelism=multiprocessing.cpu_count()*2,
  )

<commit_msg>Actually return options (#6019)<commit_after># coding=utf-8
# Copyright 2014 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)

import logging
import multiprocessing
import os
import sys

from pants.base.build_environment import (get_buildroot, get_default_pants_config_file,
                                          get_pants_cachedir, get_pants_configdir, pants_version)
from pants.option.arg_splitter import GLOBAL_SCOPE
from pants.option.custom_types import dir_option
from pants.option.optionable import Optionable
from pants.option.scope import ScopeInfo
from pants.subsystem.subsystem_client_mixin import SubsystemClientMixin
from pants.util.memo import memoized_classproperty
from pants.util.objects import datatype


class GlobMatchErrorBehavior(datatype(['failure_behavior'])):
  """Describe the action to perform when matching globs in BUILD files to source files.

  NB: this object is interpreted from within Snapshot::lift_path_globs() -- that method will need to
  be aware of any changes to this object's definition.
  """

  IGNORE = 'ignore'
  WARN = 'warn'
  ERROR = 'error'

  allowed_values = [IGNORE, WARN, ERROR]

  default_value = IGNORE

  default_option_value = WARN

  @memoized_classproperty
  def _singletons(cls):
    return { behavior: cls(behavior) for behavior in cls.allowed_values }

  @classmethod
  def create(cls, value=None):
    if isinstance(value, cls):
      return value
    if not value:
      value = cls.default_value
    return cls._singletons[value]

  def __new__(cls, *args, **kwargs):
    this_object = super(GlobMatchErrorBehavior, cls).__new__(cls, *args, **kwargs)

    if this_object.failure_behavior not in cls.allowed_values:
      raise cls.make_type_error("Value {!r} for failure_behavior must be one of: {!r}."
                                .format(this_object.failure_behavior, cls.allowed_values))

    return this_object


class ExecutionOptions(datatype([
  'remote_store_server',
  'remote_store_thread_count',
  'remote_execution_server',
  'remote_store_chunk_bytes',
  'remote_store_chunk_upload_timeout_seconds',
  'process_execution_parallelism',
])):
  """A collection of all options related to (remote) execution of processes.

  TODO: These options should move to a Subsystem once we add support for "bootstrap" Subsystems (ie,
  allowing Subsystems to be consumed before the Scheduler has been created).
  """

  @classmethod
  def from_bootstrap_options(cls, bootstrap_options):
    return cls(
      remote_store_server=bootstrap_options.remote_store_server,
      remote_execution_server=bootstrap_options.remote_execution_server,
      remote_store_thread_count=bootstrap_options.remote_store_thread_count,
      remote_store_chunk_bytes=bootstrap_options.remote_store_chunk_bytes,
      remote_store_chunk_upload_timeout_seconds=bootstrap_options.remote_store_chunk_upload_timeout_seconds,
      process_execution_parallelism=bootstrap_options.process_execution_parallelism,
    )


DEFAULT_EXECUTION_OPTIONS = ExecutionOptions(
    remote_store_server=None,
    remote_store_thread_count=1,
    remote_execution_server=None,
    remote_store_chunk_bytes=1024*1024,
    remote_store_chunk_upload_timeout_seconds=60,
    process_execution_parallelism=multiprocessing.cpu_count()*2,
  )


{'fraction_non_alphanumeric': 0.07010220238952065, 'fraction_numerical': 0.006045775154743055, 'mean_word_length': 4.794829024186822, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2260920', 'n_tokens_mistral': 2092, 'n_tokens_neox': 1996, 'n_words': 490}