Exemple #1
0
 def test_source_control_repo(self):
     source_control_dirname = ".git"
     with self.physical_workdir_base() as bootstrap_options:
         safe_mkdir(os.path.join(self.build_root, source_control_dirname))
         init_workdir(bootstrap_options)
         self.assert_exists(
             os.path.join(self.physical_workdir(bootstrap_options),
                          source_control_dirname))
Exemple #2
0
 def test_source_control_disabled(self):
     source_control_dirname = ".git"
     with temporary_dir() as physical_workdir_base:
         bootstrap_options = self.get_bootstrap_options(
             [f"--pants-physical-workdir-base={physical_workdir_base}"])
         safe_mkdir(os.path.join(self.build_root, source_control_dirname))
         init_workdir(bootstrap_options)
         self.assert_not_exists(
             os.path.join(self.physical_workdir(bootstrap_options),
                          source_control_dirname))
Exemple #3
0
    def test_init_workdir(self) -> None:
        with self.physical_workdir_base() as bootstrap_options:
            # Assert pants_workdir exists
            self.assert_exists(self.pants_workdir)

            init_workdir(bootstrap_options)

            # Assert pants_workdir is a symlink after init_workdir above
            self.assert_symlink(self.pants_workdir)
            # Assert symlink target's physical dir exists
            self.assert_exists(
                os.path.join(self.physical_workdir(bootstrap_options)))
Exemple #4
0
def test_init_workdir() -> None:
    rule_runner = RuleRunner()
    with physical_workdir_base() as bootstrap_options:
        # Assert pants_workdir exists
        assert_exists(rule_runner.pants_workdir)

        init_workdir(bootstrap_options)

        # Assert pants_workdir is a symlink after init_workdir above
        assert_symlink(rule_runner.pants_workdir)
        # Assert symlink target's physical dir exists
        assert_exists(
            os.path.join(
                physical_workdir(rule_runner.pants_workdir,
                                 bootstrap_options)))
Exemple #5
0
    def run(self, start_time: float) -> ExitCode:
        self.scrub_pythonpath()

        options_bootstrapper = OptionsBootstrapper.create(env=self.env,
                                                          args=self.args,
                                                          allow_pantsrc=True)
        with warnings.catch_warnings(record=True):
            bootstrap_options = options_bootstrapper.bootstrap_options
            global_bootstrap_options = bootstrap_options.for_global_scope()

        # We enable logging here, and everything before it will be routed through regular
        # Python logging.
        setup_logging(global_bootstrap_options, stderr_logging=True)

        if self._should_run_with_pantsd(global_bootstrap_options):
            try:
                remote_runner = RemotePantsRunner(self.args, self.env,
                                                  options_bootstrapper)
                return remote_runner.run()
            except RemotePantsRunner.Fallback as e:
                logger.warning(
                    "Client exception: {!r}, falling back to non-daemon mode".
                    format(e))

        # N.B. Inlining this import speeds up the python thin client run by about 100ms.
        from pants.bin.local_pants_runner import LocalPantsRunner

        # We only install signal handling via ExceptionSink if the run will execute in this process.
        ExceptionSink.install(
            log_location=init_workdir(global_bootstrap_options),
            pantsd_instance=False)
        runner = LocalPantsRunner.create(
            env=self.env, options_bootstrapper=options_bootstrapper)
        return runner.run(start_time)
Exemple #6
0
    def run(self, start_time: float) -> ExitCode:
        self.scrub_pythonpath()

        options_bootstrapper = OptionsBootstrapper.create(
            env=self.env, args=self.args, allow_pantsrc=True
        )
        with warnings.catch_warnings(record=True):
            bootstrap_options = options_bootstrapper.bootstrap_options
            global_bootstrap_options = bootstrap_options.for_global_scope()

        # Initialize the workdir early enough to ensure that logging has a destination.
        workdir_src = init_workdir(global_bootstrap_options)
        ExceptionSink.reset_log_location(workdir_src)

        setup_warning_filtering(global_bootstrap_options.ignore_pants_warnings or [])
        # We enable logging here, and everything before it will be routed through regular
        # Python logging.
        setup_logging(global_bootstrap_options, stderr_logging=True)

        if self._should_run_with_pantsd(global_bootstrap_options):
            try:
                remote_runner = RemotePantsRunner(self.args, self.env, options_bootstrapper)
                return remote_runner.run()
            except RemotePantsRunner.Fallback as e:
                logger.warning("Client exception: {!r}, falling back to non-daemon mode".format(e))

        # N.B. Inlining this import speeds up the python thin client run by about 100ms.
        from pants.bin.local_pants_runner import LocalPantsRunner

        runner = LocalPantsRunner.create(env=self.env, options_bootstrapper=options_bootstrapper)
        return runner.run(start_time)
Exemple #7
0
    def run_sync(self):
        """Synchronously run pantsd."""
        os.environ.pop("PYTHONPATH")

        global_bootstrap_options = self._bootstrap_options.for_global_scope()
        # Set the process name in ps output to 'pantsd' vs './pants compile src/etc:: -ldebug'.
        set_process_title(f"pantsd [{self._build_root}]")

        # Switch log output to the daemon's log stream, and empty `env` and `argv` to encourage all
        # further usage of those variables to happen via engine APIs and options.
        self._close_stdio()
        with initialize_stdio(global_bootstrap_options), argv_as(
                tuple()), hermetic_environment_as():
            # Install signal and panic handling.
            ExceptionSink.install(
                log_location=init_workdir(global_bootstrap_options),
                pantsd_instance=True)
            native_engine.maybe_set_panic_handler()

            self._initialize_metadata()

            # Check periodically whether the core is valid, and exit if it is not.
            while self._core.is_valid():
                time.sleep(self.JOIN_TIMEOUT_SECONDS)

            # We're exiting: join the server to avoid interrupting ongoing runs.
            self._logger.info(
                "Waiting for ongoing runs to complete before exiting...")
            native_engine.nailgun_server_await_shutdown(self._server)
            self._logger.info("Exiting pantsd")
Exemple #8
0
    def run_sync(self):
        """Synchronously run pantsd."""
        os.environ.pop("PYTHONPATH")

        # Switch log output to the daemon's log stream from here forward.
        self._close_stdio()
        with self._pantsd_logging():
            # Install signal handling based on global bootstrap options.
            global_bootstrap_options = self._bootstrap_options.for_global_scope()
            ExceptionSink.install(
                log_location=init_workdir(global_bootstrap_options), pantsd_instance=True
            )

            self._native.set_panic_handler()

            # Set the process name in ps output to 'pantsd' vs './pants compile src/etc:: -ldebug'.
            set_process_title(f"pantsd [{self._build_root}]")

            self._initialize_metadata()

            # Check periodically whether the core is valid, and exit if it is not.
            while self._core.is_valid():
                time.sleep(self.JOIN_TIMEOUT_SECONDS)

            # We're exiting: join the server to avoid interrupting ongoing runs.
            self._logger.info("Waiting for ongoing runs to complete before exiting...")
            self._native.nailgun_server_await_shutdown(self._server)
            self._logger.info("Exiting pantsd")
Exemple #9
0
    def run(self, start_time: float) -> ExitCode:
        self.scrub_pythonpath()

        options_bootstrapper = OptionsBootstrapper.create(env=self.env,
                                                          args=self.args,
                                                          allow_pantsrc=True)
        with warnings.catch_warnings(record=True):
            bootstrap_options = options_bootstrapper.bootstrap_options
            global_bootstrap_options = bootstrap_options.for_global_scope()

        # We enable logging here, and everything before it will be routed through regular
        # Python logging.
        stdin_fileno = sys.stdin.fileno()
        stdout_fileno = sys.stdout.fileno()
        stderr_fileno = sys.stderr.fileno()
        with initialize_stdio(global_bootstrap_options), stdio_destination(
                stdin_fileno=stdin_fileno,
                stdout_fileno=stdout_fileno,
                stderr_fileno=stderr_fileno,
        ):
            # N.B. We inline imports to speed up the python thin client run, and avoids importing
            # engine types until after the runner has had a chance to set PANTS_BIN_NAME.

            if self._should_run_with_pantsd(global_bootstrap_options):
                from pants.bin.remote_pants_runner import RemotePantsRunner

                try:
                    remote_runner = RemotePantsRunner(self.args, self.env,
                                                      options_bootstrapper)
                    return remote_runner.run(start_time)
                except RemotePantsRunner.Fallback as e:
                    logger.warning(
                        f"Client exception: {e!r}, falling back to non-daemon mode"
                    )

            from pants.bin.local_pants_runner import LocalPantsRunner

            # We only install signal handling via ExceptionSink if the run will execute in this process.
            ExceptionSink.install(
                log_location=init_workdir(global_bootstrap_options),
                pantsd_instance=False)
            runner = LocalPantsRunner.create(
                env=CompleteEnvironment(self.env),
                options_bootstrapper=options_bootstrapper)
            return runner.run(start_time)
Exemple #10
0
    def run(self):
        self.scrub_pythonpath()

        options_bootstrapper = OptionsBootstrapper.create(env=self._env,
                                                          args=self._args)
        bootstrap_options = options_bootstrapper.bootstrap_options
        global_bootstrap_options = bootstrap_options.for_global_scope()

        # Initialize the workdir early enough to ensure that logging has a destination.
        workdir_src = init_workdir(global_bootstrap_options)
        ExceptionSink.reset_log_location(workdir_src)

        # We enable Rust logging here,
        # and everything before it will be routed through regular Python logging.
        self._enable_rust_logging(global_bootstrap_options)

        ExceptionSink.reset_should_print_backtrace_to_terminal(
            global_bootstrap_options.print_exception_stacktrace)
        ExceptionSink.reset_log_location(
            global_bootstrap_options.pants_workdir)

        for message_regexp in global_bootstrap_options.ignore_pants_warnings:
            warnings.filterwarnings(action='ignore', message=message_regexp)

        # TODO https://github.com/pantsbuild/pants/issues/7205
        if self._should_run_with_pantsd(global_bootstrap_options):
            try:
                return RemotePantsRunner(self._exiter, self._args, self._env,
                                         options_bootstrapper).run()
            except RemotePantsRunner.Fallback as e:
                logger.warning(
                    'caught client exception: {!r}, falling back to non-daemon mode'
                    .format(e))

        # N.B. Inlining this import speeds up the python thin client run by about 100ms.
        from pants.bin.local_pants_runner import LocalPantsRunner

        if self.will_terminate_pantsd():
            logger.debug("Pantsd terminating goal detected: {}".format(
                self._args))

        runner = LocalPantsRunner.create(
            self._args, self._env, options_bootstrapper=options_bootstrapper)
        runner.set_start_time(self._start_time)
        return runner.run()
Exemple #11
0
    def run(self, start_time: float) -> ExitCode:
        self.scrub_pythonpath()

        options_bootstrapper = OptionsBootstrapper.create(env=self.env, args=self.args)
        bootstrap_options = options_bootstrapper.bootstrap_options
        global_bootstrap_options = bootstrap_options.for_global_scope()

        # Initialize the workdir early enough to ensure that logging has a destination.
        workdir_src = init_workdir(global_bootstrap_options)
        ExceptionSink.reset_log_location(workdir_src)

        # We enable logging here, and everything before it will be routed through regular
        # Python logging.
        setup_logging(global_bootstrap_options)

        ExceptionSink.reset_should_print_backtrace_to_terminal(
            global_bootstrap_options.print_exception_stacktrace
        )

        # TODO: When we remove this deprecation, we'll change the default for the option to true.
        deprecated_conditional(
            lambda: global_bootstrap_options.is_default("enable_pantsd"),
            removal_version="1.30.0.dev0",
            entity_description="--enable-pantsd defaulting to False",
            hint_message=(
                "Pantsd improves runtime performance and will be enabled by default in the 1.30.x "
                "stable releases. To prepare for that change, we recommend setting the "
                "`[GLOBAL] enable_pantsd` setting to `True` in your pants.toml or pants.ini file."
            ),
        )

        if self._should_run_with_pantsd(global_bootstrap_options):
            try:
                return RemotePantsRunner(self.args, self.env, options_bootstrapper).run(start_time)
            except RemotePantsRunner.Fallback as e:
                logger.warning("Client exception: {!r}, falling back to non-daemon mode".format(e))

        # N.B. Inlining this import speeds up the python thin client run by about 100ms.
        from pants.bin.local_pants_runner import LocalPantsRunner

        runner = LocalPantsRunner.create(env=self.env, options_bootstrapper=options_bootstrapper)
        return runner.run(start_time)
Exemple #12
0
    def run(self, start_time: float) -> None:
        self.scrub_pythonpath()

        # TODO could options-bootstrapper be parsed in the runners?
        options_bootstrapper = OptionsBootstrapper.create(env=self.env,
                                                          args=self.args)
        bootstrap_options = options_bootstrapper.bootstrap_options
        global_bootstrap_options = bootstrap_options.for_global_scope()

        # Initialize the workdir early enough to ensure that logging has a destination.
        workdir_src = init_workdir(global_bootstrap_options)
        ExceptionSink.reset_log_location(workdir_src)

        # We enable Rust logging here,
        # and everything before it will be routed through regular Python logging.
        self._enable_rust_logging(global_bootstrap_options)

        ExceptionSink.reset_should_print_backtrace_to_terminal(
            global_bootstrap_options.print_exception_stacktrace)

        if self._should_run_with_pantsd(global_bootstrap_options):
            try:
                RemotePantsRunner(self._exiter, self.args, self.env,
                                  options_bootstrapper).run()
                return
            except RemotePantsRunner.Fallback as e:
                logger.warning(
                    "Client exception: {!r}, falling back to non-daemon mode".
                    format(e))

        # N.B. Inlining this import speeds up the python thin client run by about 100ms.
        from pants.bin.local_pants_runner import LocalPantsRunner

        runner = LocalPantsRunner.create(
            env=self.env, options_bootstrapper=options_bootstrapper)
        runner.set_start_time(start_time)
        runner.run()