コード例 #1
0
def test_uninitialized_global() -> None:
    Subsystem.reset()
    with pytest.raises(
            Subsystem.UninitializedSubsystemError,
            match=r"UninitializedSubsystem.*uninitialized-scope",
    ):
        UninitializedSubsystem.global_instance()
コード例 #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 global plugin state.
    BuildConfigInitializer.reset()
コード例 #3
0
    def test_uninitialized_scoped_instance(self) -> None:
        Subsystem.reset()

        class UninitializedOptional(Optionable):
            options_scope = "optional"

        optional = UninitializedOptional()
        with self.assertRaisesRegex(
                Subsystem.UninitializedSubsystemError,
                r"UninitializedSubsystem.*uninitialized-scope"):
            UninitializedSubsystem.scoped_instance(optional)
コード例 #4
0
def test_uninitialized_scoped_instance() -> None:
    Subsystem.reset()

    class UninitializedOptional(Optionable):
        options_scope = "optional"

    optional = UninitializedOptional()
    with pytest.raises(
            Subsystem.UninitializedSubsystemError,
            match=r"UninitializedSubsystem.*uninitialized-scope",
    ):
        UninitializedSubsystem.scoped_instance(optional)
コード例 #5
0
    def run(self, start_time: float) -> ExitCode:
        run_tracker = RunTracker.global_instance()
        self._start_run(run_tracker, start_time)

        with maybe_profiled(self.profile_path):
            global_options = self.options.for_global_scope()

            if self.options.help_request:
                return self._print_help(self.options.help_request)

            streaming_handlers = global_options.streaming_workunits_handlers
            callbacks = Subsystem.get_streaming_workunit_callbacks(
                streaming_handlers)
            streaming_reporter = StreamingWorkunitHandler(
                self.graph_session.scheduler_session,
                callbacks=callbacks,
                report_interval_seconds=global_options.
                streaming_workunits_report_interval,
            )

            goals = tuple(self.options.goals)
            with streaming_reporter.session():
                engine_result = PANTS_FAILED_EXIT_CODE
                try:
                    engine_result = self._run_v2(goals)
                except Exception as e:
                    ExceptionSink.log_exception(e)

                self._finish_run(run_tracker, engine_result)
            return engine_result
コード例 #6
0
 def test_streaming_workunit_callbacks_bad_module(self) -> None:
     import_str = "nonexistent_module.AClassThatDoesntActuallyExist"
     with self.captured_logging(level=logging.WARNING) as captured:
         callables_list = Subsystem.get_streaming_workunit_callbacks(
             [import_str])
         warnings = captured.warnings()
         assert len(warnings) == 1
         assert len(callables_list) == 0
         assert "No module named 'nonexistent_module'" in warnings[0]
コード例 #7
0
def test_streaming_workunit_callbacks_bad_module(caplog) -> None:
    import_str = "nonexistent_module.AClassThatDoesntActuallyExist"
    callables_list = Subsystem.get_streaming_workunit_callbacks([import_str])
    assert len(callables_list) == 0
    warnings = [
        record for record in caplog.records if record.levelname == "WARNING"
    ]
    assert len(warnings) == 1
    assert "No module named 'nonexistent_module'" in warnings[0].msg
コード例 #8
0
 def test_streaming_workunit_callbacks_with_invalid_subsystem(self) -> None:
     import_str = "pants.option.subsystem_test.DummySubsystem"
     with self.captured_logging(level=logging.WARNING) as captured:
         callables_list = Subsystem.get_streaming_workunit_callbacks(
             [import_str])
         warnings = captured.warnings()
         assert len(warnings) == 1
         assert "does not have a method named `handle_workunits` defined" in warnings[
             0]
         assert len(callables_list) == 0
コード例 #9
0
def test_streaming_workunit_callbacks_with_invalid_subsystem(caplog) -> None:
    import_str = "pants.option.subsystem_test.DummySubsystem"
    callables_list = Subsystem.get_streaming_workunit_callbacks([import_str])
    assert len(callables_list) == 0
    warnings = [
        record for record in caplog.records if record.levelname == "WARNING"
    ]
    assert len(warnings) == 1
    assert "does not have a method named `handle_workunits` defined" in warnings[
        0].msg
コード例 #10
0
 def test_streaming_workunit_callbacks_good_module_bad_class(self) -> None:
     import_str = "pants.option.subsystem_test.ANonexistentClass"
     with self.captured_logging(level=logging.WARNING) as captured:
         callables_list = Subsystem.get_streaming_workunit_callbacks(
             [import_str])
         warnings = captured.warnings()
         assert len(warnings) == 1
         assert len(callables_list) == 0
         assert (
             "module 'pants.option.subsystem_test' has no attribute 'ANonexistentClass'"
             in warnings[0])
コード例 #11
0
def test_streaming_workunit_callbacks_good_module_bad_class(caplog) -> None:
    import_str = "pants.option.subsystem_test.ANonexistentClass"
    callables_list = Subsystem.get_streaming_workunit_callbacks([import_str])
    assert len(callables_list) == 0
    warnings = [
        record for record in caplog.records if record.levelname == "WARNING"
    ]
    assert len(warnings) == 1
    assert (
        "module 'pants.option.subsystem_test' has no attribute 'ANonexistentClass'"
        in warnings[0].msg)
コード例 #12
0
    def create(cls,
               options_bootstrapper,
               build_configuration,
               init_subsystems=True):
        global_bootstrap_options = options_bootstrapper.get_bootstrap_options(
        ).for_global_scope()

        if global_bootstrap_options.pants_version != pants_version():
            raise BuildConfigurationError(
                f"Version mismatch: Requested version was {global_bootstrap_options.pants_version}, "
                f"our version is {pants_version()}.")

        # Parse and register options.
        options = cls._construct_options(options_bootstrapper,
                                         build_configuration)

        GlobalOptions.validate_instance(options.for_global_scope())

        if init_subsystems:
            Subsystem.set_options(options)

        return options
コード例 #13
0
def select(argv):
    # Parse positional arguments to the script.
    args = _create_bootstrap_binary_arg_parser().parse_args(argv[1:])
    # Resolve bootstrap options with a fake empty command line.
    options_bootstrapper = OptionsBootstrapper.create(env=os.environ,
                                                      args=[argv[0]],
                                                      allow_pantsrc=True)
    subsystems = (GlobalOptions, BinaryUtil.Factory)
    known_scope_infos = reduce(set.union,
                               (ss.known_scope_infos() for ss in subsystems),
                               set())
    options = options_bootstrapper.get_full_options(known_scope_infos)
    # Initialize Subsystems.
    Subsystem.set_options(options)

    # If the filename provided ends in a known archive extension (such as ".tar.gz"), then we get the
    # appropriate Archiver to pass to BinaryUtil.
    archiver_for_current_binary = None
    filename = args.filename or args.util_name
    try:
        archiver_for_current_binary = archiver_for_path(filename)
        # BinaryRequest requires the `name` field to be provided without an extension, as it appends the
        # archiver's extension if one is provided, so we have to remove it here.
        filename = filename[:-(len(archiver_for_current_binary.extension) + 1)]
    except ValueError:
        pass

    binary_util = BinaryUtil.Factory.create()
    binary_request = BinaryRequest(
        supportdir="bin/{}".format(args.util_name),
        version=args.version,
        name=filename,
        platform_dependent=True,
        external_url_generator=None,
        archiver=archiver_for_current_binary,
    )

    return binary_util.select(binary_request)
コード例 #14
0
ファイル: local_pants_runner.py プロジェクト: Spacerat/pants
    def run(self, start_time: float) -> ExitCode:
        self._set_start_time(start_time)

        with maybe_profiled(self.profile_path):
            global_options = self.options.for_global_scope()
            streaming_handlers = global_options.streaming_workunits_handlers
            report_interval = global_options.streaming_workunits_report_interval
            callbacks = Subsystem.get_streaming_workunit_callbacks(
                streaming_handlers)
            streaming_reporter = StreamingWorkunitHandler(
                self.graph_session.scheduler_session,
                callbacks=callbacks,
                report_interval_seconds=report_interval,
            )

            if self.options.help_request:
                all_help_info = HelpInfoExtracter.get_all_help_info(
                    self.options,
                    self.union_membership,
                    self.graph_session.goal_consumed_subsystem_scopes,
                )
                help_printer = HelpPrinter(
                    bin_name=global_options.pants_bin_name,
                    help_request=self.options.help_request,
                    all_help_info=all_help_info,
                    use_color=global_options.colors,
                )
                return help_printer.print_help()

            with streaming_reporter.session():
                engine_result = PANTS_FAILED_EXIT_CODE
                try:
                    engine_result = self._run_v2()
                except Exception as e:
                    ExceptionSink.log_exception(e)
                run_tracker_result = self._finish_run(engine_result)
            return self._merge_exit_codes(engine_result, run_tracker_result)
コード例 #15
0
 def check_false(s: str) -> None:
     assert not Subsystem.is_valid_scope_name(s)
コード例 #16
0
 def check_true(s: str) -> None:
     assert Subsystem.is_valid_scope_name(s)
コード例 #17
0
 def tearDown(self):
     """
     :API: public
     """
     super().tearDown()
     Subsystem.reset()
コード例 #18
0
 def setUp(self):
     super().setUp()
     # Some integration tests rely on clean subsystem state (e.g., to set up a DistributionLocator).
     Subsystem.reset()
コード例 #19
0
 def test_get_streaming_workunit_callbacks(self) -> None:
     import_str = "pants.option.subsystem_test.WorkunitSubscriptableSubsystem"
     callables_list = Subsystem.get_streaming_workunit_callbacks(
         [import_str])
     assert len(callables_list) == 1
コード例 #20
0
 def test_uninitialized_global(self) -> None:
     Subsystem.reset()
     with self.assertRaisesRegex(
             Subsystem.UninitializedSubsystemError,
             r"UninitializedSubsystem.*uninitialized-scope"):
         UninitializedSubsystem.global_instance()