Beispiel #1
0
 def setup_graph(
     options_bootstrapper: OptionsBootstrapper,
     build_configuration: BuildConfiguration,
 ) -> GraphScheduler:
     native = Native()
     build_root = get_buildroot()
     bootstrap_options = options_bootstrapper.bootstrap_options.for_global_scope()
     print_stacktrace = resolve_conflicting_options(
         old_option="print_exception_stacktrace",
         new_option="print_stacktrace",
         old_scope="",
         new_scope="",
         old_container=bootstrap_options,
         new_container=bootstrap_options,
     )
     return EngineInitializer.setup_graph_extended(
         options_bootstrapper,
         build_configuration,
         ExecutionOptions.from_bootstrap_options(bootstrap_options),
         pants_ignore_patterns=OptionsInitializer.compute_pants_ignore(
             build_root, bootstrap_options
         ),
         use_gitignore=bootstrap_options.pants_ignore_use_gitignore,
         local_store_dir=bootstrap_options.local_store_dir,
         local_execution_root_dir=bootstrap_options.local_execution_root_dir,
         named_caches_dir=bootstrap_options.named_caches_dir,
         ca_certs_path=bootstrap_options.ca_certs_path,
         build_root=build_root,
         native=native,
         include_trace_on_error=print_stacktrace,
     )
Beispiel #2
0
 def from_options(cls, options: OptionValueContainer) -> "ChangedOptions":
     since = resolve_conflicting_options(
         old_option="changes_since",
         new_option="since",
         old_scope="changed",
         new_scope="changed",
         old_container=options,
         new_container=options,
     )
     dependees = resolve_conflicting_options(
         old_option="include_dependees",
         new_option="dependees",
         old_scope="changed",
         new_scope="changed",
         old_container=options,
         new_container=options,
     )
     return cls(since, options.diffspec, dependees)
Beispiel #3
0
 def _resolve_conflicting_options(self, *, old_option: str, new_option: str):
   return resolve_conflicting_options(
     old_option=old_option,
     new_option=new_option,
     old_scope='lint-mypy',
     new_scope='mypy',
     old_container=self.get_options(),
     new_container=self._mypy_subsystem.options,
   )
Beispiel #4
0
 def _resolve_conflicting_options(self, *, old_option: str, new_option: str):
   return resolve_conflicting_options(
     old_option=old_option,
     new_option=new_option,
     old_scope='lint-checkstyle',
     new_scope='checkstyle',
     old_container=self.get_options(),
     new_container=CheckstyleSubsystem.global_instance().options,
   )
Beispiel #5
0
 def _resolve_conflicting_options(self, *, old_option: str, new_option: str):
   return resolve_conflicting_options(
     old_option=old_option,
     new_option=new_option,
     old_scope='lint-scalastyle',
     new_scope='scalastyle',
     old_container=self.get_options(),
     new_container=Scalastyle.global_instance().options,
   )
Beispiel #6
0
 def per_file_caching(self) -> bool:
     val = resolve_conflicting_options(
         old_option="per_target_caching",
         new_option="per_file_caching",
         old_container=self.options,
         new_container=self.options,
         old_scope=self.name,
         new_scope=self.name,
     )
     return cast(bool, val)
Beispiel #7
0
 def _resolve_conflicting_options(self, *, old_option: str,
                                  new_option: str):
     return resolve_conflicting_options(
         old_option=old_option,
         new_option=new_option,
         old_scope="lint-thrift",
         new_scope="scrooge-linter",
         old_container=self.get_options(),
         new_container=ScroogeLinter.global_instance().options,
     )
 def _resolve_conflicting_options(self, *, old_option: str,
                                  new_option: str):
     return resolve_conflicting_options(
         old_option=old_option,
         new_option=new_option,
         old_scope="node-distribution",
         new_scope='eslint',
         old_container=self.node_distribution.options,
         new_container=ESLint.global_instance().options,
     )
Beispiel #9
0
 def emit_warnings(self) -> bool:
     return cast(
         bool,
         resolve_conflicting_options(
             old_option="pex_emit_warnings",
             new_option="emit_warnings",
             old_scope=self.options_scope,
             new_scope=self.deprecated_options_scope,
             old_container=self.options,
             new_container=self.options,
         ),
     )
Beispiel #10
0
def extract_unmatched_build_file_globs(
    global_options: GlobalOptions, ) -> UnmatchedBuildFileGlobs:
    return cast(
        UnmatchedBuildFileGlobs,
        resolve_conflicting_options(
            old_option="files_not_found_behavior",
            new_option="unmatched_build_file_globs",
            old_scope=global_options.options_scope,
            new_scope=global_options.options_scope,
            old_container=global_options.options,
            new_container=global_options.options,
        ),
    )
 def resolve_conflicting_skip_options(self, old_scope: str, new_scope: str,
                                      subsystem: Subsystem):
     skip = resolve_conflicting_options(
         old_option="skip",
         new_option="skip",
         old_scope=old_scope,
         new_scope=new_scope,
         # Skip mypy because this is a temporary hack, and mypy doesn't follow the inheritance chain
         # properly.
         old_container=self.get_options(),  # type: ignore
         new_container=subsystem.options,
     )
     return self.resolve_only_as_skip(skip)
Beispiel #12
0
 def option_resolved(*, old_configured: bool = False, new_configured: bool = False):
     old_container_builder, new_container_builder = (
         OptionValueContainerBuilder(),
         OptionValueContainerBuilder(),
     )
     old_container_builder.my_opt = old_configured_rv if old_configured else old_default_rv
     new_container_builder.my_opt = new_configured_rv if new_configured else new_default_rv
     old_container = old_container_builder.build()
     new_container = new_container_builder.build()
     return resolve_conflicting_options(
         old_option="my_opt",
         new_option="my_opt",
         old_scope="old-scope",
         new_scope="new-scope",
         old_container=old_container,
         new_container=new_container,
     )
Beispiel #13
0
    def _init_graph_session(
        options_bootstrapper: OptionsBootstrapper,
        build_config: BuildConfiguration,
        options: Options,
        scheduler: Optional[LegacyGraphScheduler] = None,
    ) -> LegacyGraphSession:
        native = Native()
        native.set_panic_handler()
        graph_scheduler_helper = scheduler or EngineInitializer.setup_legacy_graph(
            options_bootstrapper, build_config)

        global_scope = options.for_global_scope()

        if global_scope.v2:
            dynamic_ui = resolve_conflicting_options(
                old_option="v2_ui",
                new_option="dynamic_ui",
                old_scope=GLOBAL_SCOPE,
                new_scope=GLOBAL_SCOPE,
                old_container=global_scope,
                new_container=global_scope,
            )
        else:
            dynamic_ui = False
        use_colors = global_scope.get("colors", True)

        zipkin_trace_v2 = options.for_scope("reporting").zipkin_trace_v2
        # TODO(#8658) This should_report_workunits flag must be set to True for
        # StreamingWorkunitHandler to receive WorkUnits. It should eventually
        # be merged with the zipkin_trace_v2 flag, since they both involve most
        # of the same engine functionality, but for now is separate to avoid
        # breaking functionality associated with zipkin tracing while iterating on streaming workunit reporting.
        stream_workunits = len(
            options.for_global_scope().streaming_workunits_handlers) != 0
        return graph_scheduler_helper.new_session(
            zipkin_trace_v2,
            RunTracker.global_instance().run_id,
            dynamic_ui=dynamic_ui,
            use_colors=use_colors,
            should_report_workunits=stream_workunits,
        )
Beispiel #14
0
def setup_logging(global_bootstrap_options: OptionValueContainer,
                  stderr_logging: bool) -> None:
    """Sets up logging for a Pants run.

    This is called in two contexts: 1) PantsRunner, 2) DaemonPantsRunner. In the latter case, the
    loggers are saved and restored around this call, so in both cases it runs with no handlers
    configured (and asserts so!).
    """
    if get_logging_handlers():
        raise AssertionError(
            "setup_logging should not be called while Handlers are installed.")

    global_level = global_bootstrap_options.level
    log_dir = global_bootstrap_options.logdir

    log_show_rust_3rdparty = global_bootstrap_options.log_show_rust_3rdparty
    use_color = global_bootstrap_options.colors
    show_target = global_bootstrap_options.show_log_target
    log_levels_by_target = get_log_levels_by_target(global_bootstrap_options)

    init_rust_logger(global_level, log_show_rust_3rdparty, use_color,
                     show_target, log_levels_by_target)

    print_stacktrace = resolve_conflicting_options(
        old_option="print_exception_stacktrace",
        new_option="print_stacktrace",
        old_scope="",
        new_scope="",
        old_container=global_bootstrap_options,
        new_container=global_bootstrap_options,
    )
    if stderr_logging:
        setup_logging_to_stderr(global_level, print_stacktrace)

    if log_dir:
        setup_logging_to_file(global_level, log_dir=log_dir)
Beispiel #15
0
    def create(
        cls,
        env: Mapping[str, str],
        config: Config,
        known_scope_infos: Iterable[ScopeInfo],
        args: Sequence[str],
        bootstrap_option_values: Optional[OptionValueContainer] = None,
    ) -> "Options":
        """Create an Options instance.

        :param env: a dict of environment variables.
        :param config: data from a config file.
        :param known_scope_infos: ScopeInfos for all scopes that may be encountered.
        :param args: a list of cmd-line args; defaults to `sys.argv` if None is supplied.
        :param bootstrap_option_values: An optional namespace containing the values of bootstrap
               options. We can use these values when registering other options.
        """
        # We need parsers for all the intermediate scopes, so inherited option values
        # can propagate through them.
        complete_known_scope_infos = cls.complete_scopes(known_scope_infos)
        splitter = ArgSplitter(complete_known_scope_infos, get_buildroot())
        split_args = splitter.split_args(args)

        if split_args.passthru and len(split_args.goals) > 1:
            raise cls.AmbiguousPassthroughError(
                f"Specifying multiple goals (in this case: {split_args.goals}) "
                "along with passthrough args (args after `--`) is ambiguous.\n"
                "Try either specifying only a single goal, or passing the passthrough args "
                "directly to the relevant consumer via its associated flags.")

        if bootstrap_option_values:
            spec_files = resolve_conflicting_options(
                old_option="spec_file",
                new_option="spec_files",
                old_scope="",
                new_scope="",
                old_container=bootstrap_option_values,
                new_container=bootstrap_option_values,
            )
            # TODO: After --spec-file is removed, replace the above with:
            # spec_files = bootstrap_option_values.spec_files

            if spec_files:
                for spec_file in spec_files:
                    with open(spec_file, "r") as f:
                        split_args.specs.extend([
                            line for line in [line.strip() for line in f]
                            if line
                        ])

        help_request = splitter.help_request

        parser_hierarchy = ParserHierarchy(env, config,
                                           complete_known_scope_infos)
        known_scope_to_info = {s.scope: s for s in complete_known_scope_infos}
        return cls(
            goals=split_args.goals,
            scope_to_flags=split_args.scope_to_flags,
            specs=split_args.specs,
            passthru=split_args.passthru,
            help_request=help_request,
            parser_hierarchy=parser_hierarchy,
            bootstrap_option_values=bootstrap_option_values,
            known_scope_to_info=known_scope_to_info,
            unknown_scopes=split_args.unknown_scopes,
        )