Exemplo n.º 1
0
def clean_global_runtime_state(reset_subsystem=False):
    """Resets the global runtime state of a pants runtime for cleaner forking.

    :param bool reset_subsystem: Whether or not to clean Subsystem global state.
    """
    if reset_subsystem:
        # Reset subsystem state.
        Subsystem.reset()

    # Reset global plugin state.
    BuildConfigInitializer.reset()
Exemplo n.º 2
0
def clean_global_runtime_state(reset_subsystem=False):
  """Resets the global runtime state of a pants runtime for cleaner forking.

  :param bool reset_subsystem: Whether or not to clean Subsystem global state.
  """
  if reset_subsystem:
    # Reset subsystem state.
    Subsystem.reset()

  # Reset Goals and Tasks.
  Goal.clear()

  # Reset global plugin state.
  BuildConfigInitializer.reset()
Exemplo n.º 3
0
    def single_daemonized_run(
            self, working_dir: str,
            cancellation_latch: PySessionCancellationLatch) -> ExitCode:
        """Run a single daemonized run of Pants.

        All aspects of the `sys` global should already have been replaced in `__call__`, so this
        method should not need any special handling for the fact that it's running in a proxied
        environment.
        """

        # Capture the client's start time, which we propagate here in order to get an accurate
        # view of total time.
        env_start_time = os.environ.get("PANTSD_RUNTRACKER_CLIENT_START_TIME",
                                        None)
        start_time = float(env_start_time) if env_start_time else time.time()

        # Clear global mutable state before entering `LocalPantsRunner`. Note that we use
        # `sys.argv` and `os.environ`, since they have been mutated to maintain the illusion
        # of a local run: once we allow for concurrent runs, this information should be
        # propagated down from the caller.
        #   see https://github.com/pantsbuild/pants/issues/7654
        BuildConfigInitializer.reset()
        options_bootstrapper = OptionsBootstrapper.create(env=os.environ,
                                                          args=sys.argv,
                                                          allow_pantsrc=True)
        bootstrap_options = options_bootstrapper.bootstrap_options
        global_bootstrap_options = bootstrap_options.for_global_scope()

        # Run using the pre-warmed Session.
        with self._stderr_logging(global_bootstrap_options):
            try:
                scheduler = self._core.prepare_scheduler(options_bootstrapper)
                runner = LocalPantsRunner.create(
                    os.environ,
                    options_bootstrapper,
                    scheduler=scheduler,
                    cancellation_latch=cancellation_latch,
                )
                return runner.run(start_time)
            except Exception as e:
                logger.exception(e)
                return PANTS_FAILED_EXIT_CODE
            except KeyboardInterrupt:
                print("Interrupted by user.\n", file=sys.stderr)
                return PANTS_FAILED_EXIT_CODE
Exemplo n.º 4
0
def clean_global_runtime_state() -> None:
    """Resets the global runtime state of a pants runtime."""

    # Reset global plugin state.
    BuildConfigInitializer.reset()