Beispiel #1
0
    def create(cls, options_bootstrapper) -> "PantsDaemon":
        """
        :param OptionsBootstrapper options_bootstrapper: The bootstrap options.
        :param bool full_init: Whether or not to fully initialize an engine et al for the purposes
                                of spawning a new daemon. `full_init=False` is intended primarily
                                for lightweight lifecycle checks (since there is a ~1s overhead to
                                initialize the engine). See the impl of `maybe_launch` for an example
                                of the intended usage.
        """
        native = Native()
        native.override_thread_logging_destination_to_just_pantsd()

        bootstrap_options = options_bootstrapper.bootstrap_options
        bootstrap_options_values = bootstrap_options.for_global_scope()

        core = PantsDaemonCore(cls._setup_services)

        server = native.new_nailgun_server(
            bootstrap_options_values.pantsd_pailgun_port,
            DaemonPantsRunner(core),
        )

        return PantsDaemon(
            native=native,
            work_dir=bootstrap_options_values.pants_workdir,
            log_level=bootstrap_options_values.level,
            server=server,
            core=core,
            metadata_base_dir=bootstrap_options_values.pants_subprocessdir,
            bootstrap_options=bootstrap_options,
        )
Beispiel #2
0
    def create(cls, options_bootstrapper: OptionsBootstrapper,
               env: CompleteEnvironment) -> PantsDaemon:
        # Any warnings that would be triggered here are re-triggered later per-run of Pants, so we
        # silence them.
        with warnings.catch_warnings(record=True):
            bootstrap_options = options_bootstrapper.bootstrap_options
            bootstrap_options_values = bootstrap_options.for_global_scope()

        executor = GlobalOptions.create_py_executor(bootstrap_options_values)
        core = PantsDaemonCore(options_bootstrapper, env, executor,
                               cls._setup_services)

        server = native_engine.nailgun_server_create(
            executor,
            bootstrap_options_values.pantsd_pailgun_port,
            DaemonPantsRunner(core),
        )

        return PantsDaemon(
            work_dir=bootstrap_options_values.pants_workdir,
            log_level=bootstrap_options_values.level,
            server=server,
            core=core,
            metadata_base_dir=bootstrap_options_values.pants_subprocessdir,
            bootstrap_options=bootstrap_options,
        )
Beispiel #3
0
    def test_precompute_propagates_failures(self):
        """
    Tests that, when precompute returns a non-zero exit code (but doesn't raise exceptions),
    it will be propagated to the end of the run.

    May become obsolete after #8002 is resolved.
    """
        weird_return_value = 19

        non_zero_returning_scheduler_service = Mock()
        non_zero_returning_scheduler_service.prefork = Mock(
            return_value=(-1, -1, weird_return_value))

        with self.enable_creating_dpr():
            dpr = DaemonPantsRunner.create(
                sock=self.mock_sock,
                args=[],
                env={},
                services={},
                scheduler_service=non_zero_returning_scheduler_service)

            self.assertEqual(
                repr(dpr._exception),
                repr(
                    _PantsProductPrecomputeFailed(
                        _PantsRunFinishedWithFailureException(
                            exit_code=weird_return_value))))

            self.check_runs_exit_with_code(dpr, weird_return_value)
Beispiel #4
0
    def test_precompute_exceptions_propagated(self):
        """
    Test that exceptions raised at precompute time are propagated correctly.

    May become obsolete after #8002 is resolved.
    """
        raising_scheduler_service = Mock()
        raising_scheduler_service.prefork = Mock(
            side_effect=Exception('I called prefork'))

        with self.enable_creating_dpr():
            dpr = DaemonPantsRunner.create(
                sock=self.mock_sock,
                args=[],
                env={},
                services={},
                scheduler_service=raising_scheduler_service)

            self.assertEqual(
                repr(dpr._exception),
                repr(
                    _PantsProductPrecomputeFailed(
                        Exception('I called prefork'))))

            self.check_runs_exit_with_code(dpr, PANTS_FAILED_EXIT_CODE)
Beispiel #5
0
    def create(cls,
               options_bootstrapper: OptionsBootstrapper) -> "PantsDaemon":

        with warnings.catch_warnings(record=True):
            bootstrap_options = options_bootstrapper.bootstrap_options
            bootstrap_options_values = bootstrap_options.for_global_scope()

        setup_warning_filtering(bootstrap_options_values.ignore_pants_warnings
                                or [])

        native = Native()
        native.override_thread_logging_destination_to_just_pantsd()

        core = PantsDaemonCore(cls._setup_services)

        server = native.new_nailgun_server(
            bootstrap_options_values.pantsd_pailgun_port,
            DaemonPantsRunner(core),
        )

        return PantsDaemon(
            native=native,
            work_dir=bootstrap_options_values.pants_workdir,
            log_level=bootstrap_options_values.level,
            server=server,
            core=core,
            metadata_base_dir=bootstrap_options_values.pants_subprocessdir,
            bootstrap_options=bootstrap_options,
        )
Beispiel #6
0
    def create(cls, options_bootstrapper: OptionsBootstrapper) -> PantsDaemon:
        # Any warnings that would be triggered here are re-triggered later per-run of Pants, so we
        # silence them.
        with warnings.catch_warnings(record=True):
            bootstrap_options = options_bootstrapper.bootstrap_options
            bootstrap_options_values = bootstrap_options.for_global_scope()

        native = Native()
        native.override_thread_logging_destination_to_just_pantsd()

        executor = PyExecutor(
            *OptionsInitializer.compute_executor_arguments(bootstrap_options_values)
        )
        core = PantsDaemonCore(executor, cls._setup_services)

        server = native.new_nailgun_server(
            executor,
            bootstrap_options_values.pantsd_pailgun_port,
            DaemonPantsRunner(core),
        )

        return PantsDaemon(
            native=native,
            work_dir=bootstrap_options_values.pants_workdir,
            log_level=bootstrap_options_values.level,
            server=server,
            core=core,
            metadata_base_dir=bootstrap_options_values.pants_subprocessdir,
            bootstrap_options=bootstrap_options,
        )
Beispiel #7
0
        def _setup_services(
            build_root,
            bootstrap_options,
            legacy_graph_scheduler,
            native,
            watchman,
            union_membership: UnionMembership,
        ):
            """Initialize pantsd services.

            :returns: A PantsServices instance.
            """
            native.override_thread_logging_destination_to_just_pantsd()
            fs_event_service = (
                FSEventService(
                    watchman, scheduler=legacy_graph_scheduler.scheduler, build_root=build_root
                )
                if bootstrap_options.watchman_enable
                else None
            )

            invalidation_globs = OptionsInitializer.compute_pantsd_invalidation_globs(
                build_root, bootstrap_options
            )

            scheduler_service = SchedulerService(
                fs_event_service=fs_event_service,
                legacy_graph_scheduler=legacy_graph_scheduler,
                build_root=build_root,
                invalidation_globs=invalidation_globs,
                union_membership=union_membership,
            )

            pailgun_service = PailgunService(
                bootstrap_options.pantsd_pailgun_port,
                DaemonPantsRunner(scheduler_service),
                scheduler_service,
            )

            store_gc_service = StoreGCService(legacy_graph_scheduler.scheduler)

            return PantsServices(
                services=tuple(
                    service
                    for service in (
                        fs_event_service,
                        scheduler_service,
                        pailgun_service,
                        store_gc_service,
                    )
                    if service is not None
                ),
                port_map=dict(pailgun=pailgun_service.pailgun_port()),
            )