Ejemplo n.º 1
0
def construct_callback(
    _: AnonymousTelemetryCallbackFactoryRequest, anonymous_telemetry: AnonymousTelemetry
) -> WorkunitsCallbackFactory:
    enabled = anonymous_telemetry.enabled
    unhashed_repo_id = anonymous_telemetry.repo_id

    if anonymous_telemetry.options.is_default("enabled"):
        logger.warning(
            "Please either set `enabled = true` in the [anonymous-telemetry] section of "
            "pants.toml to enable sending anonymous stats to the Pants project to aid "
            "development, or set `enabled = false` to disable it. No telemetry sent "
            "for this run. An explicit setting will get rid of this message. "
            f"{_telemetry_docs_referral}."
        )
    if enabled:
        if unhashed_repo_id is None:
            logger.error(
                'Please set `repo_id = "<uuid>"` in the [anonymous-telemetry] section '
                "of pants.toml, where `<uuid>` is some fixed random identifier, such as "
                "one generated by uuidgen. No telemetry will be sent for this run. "
                f"{_telemetry_docs_referral}."
            )
            enabled = False
        elif not AnonymousTelemetryCallback.validate_repo_id(unhashed_repo_id):
            logger.error(
                "The repo_id option in the [anonymous-telemetry] scope must be between 30 and "
                "60 characters long, and consist of only alphanumeric characters, dashes "
                "and underscores."
            )
            enabled = False

    return WorkunitsCallbackFactory(
        lambda: AnonymousTelemetryCallback(cast(str, unhashed_repo_id)) if enabled else None
    )
Ejemplo n.º 2
0
def construct_workunits_logger_callback(
    _: WorkunitsLoggerRequest,
    opts: WorkunitsLoggerOptions,
) -> WorkunitsCallbackFactory:
    assert opts.dest is not None
    dest = opts.dest
    return WorkunitsCallbackFactory(lambda: WorkunitsLogger(dest))
Ejemplo n.º 3
0
def construct_callback(
    _: StatsAggregatorCallbackFactoryRequest, subsystem: StatsAggregatorSubsystem
) -> WorkunitsCallbackFactory:
    has_histogram_module = False
    if subsystem.log:
        try:
            import hdrh.histogram  # noqa: F401
        except ImportError:
            logger.warning(
                "Please run with `--plugins=hdrhistogram` if you would like histogram summaries to "
                "be shown at the end of the run, or permanently add "
                "`[GLOBAL].plugins = ['hdrhistogram']`. This will cause Pants to install "
                "the `hdrhistogram` dependency from PyPI."
            )
        else:
            has_histogram_module = True

    return WorkunitsCallbackFactory(
        lambda: (
            StatsAggregatorCallback(
                log=subsystem.log,
                memory=subsystem.memory_summary,
                has_histogram_module=has_histogram_module,
            )
            if subsystem.log or subsystem.memory_summary
            else None
        )
    )
Ejemplo n.º 4
0
def construct_workunits_logger_callback(
    _: WorkunitsLoggerRequest,
    opts: WorkunitsLoggerOptions,
) -> WorkunitsCallbackFactory:
    output_file = opts.options.dest
    return WorkunitsCallbackFactory(lambda: WorkunitsLogger(output_file))
Ejemplo n.º 5
0
def construct_callback(
        _: AnonymousTelemetryCallbackFactoryRequest,
        anonymous_telemetry: AnonymousTelemetry) -> WorkunitsCallbackFactory:
    return WorkunitsCallbackFactory(
        lambda: AnonymousTelemetryCallback(anonymous_telemetry))