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(
        'Version mismatch: Requested version was {}, our version is {}.'
        .format(global_bootstrap_options.pants_version, pants_version())
      )

    pants_runtime_python_version = global_bootstrap_options.pants_runtime_python_version
    current_python_version = '.'.join(map(str, sys.version_info[0:2]))
    if pants_runtime_python_version and pants_runtime_python_version != current_python_version:
      raise BuildConfigurationError(
        'Running Pants with a different Python interpreter version than requested. '
        'You requested {}, but are running with {}.\n\n'
        'Note that Pants cannot use the value you give for `--pants-runtime-python-version` to '
        'dynamically change the interpreter it uses, as it is too late for it to change once the program '
        'is already running. Instead, your setup script (e.g. `./pants`) must configure which Python '
        'interpreter and virtualenv to use. For example, the setup script we distribute '
        'at https://www.pantsbuild.org/install.html#recommended-installation will read the '
        '`pants_runtime_python_version` defined in your pants.ini to determine which Python '
        'version to run with.'.format(pants_runtime_python_version, current_python_version)
      )

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

    GlobalOptionsRegistrar.validate_instance(options.for_global_scope())

    if init_subsystems:
      Subsystem.set_options(options)

    return options
Exemple #2
0
  def setup(self, init_logging=True):
    """Initializes logging, loads backends/plugins and parses options.

    :param bool init_logging: Whether or not to initialize logging as part of setup.
    :returns: A tuple of (options, build_configuration).
    """
    global_bootstrap_options = self._options_bootstrapper.get_bootstrap_options().for_global_scope()

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

    # Get logging setup prior to loading backends so that they can log as needed.
    if init_logging:
      self._setup_logging(global_bootstrap_options.quiet,
                          global_bootstrap_options.level,
                          global_bootstrap_options.logdir)

    # Conditionally load backends/plugins and materialize a `BuildConfiguration` object.
    if not self._has_build_configuration():
      build_configuration = self._load_plugins(self._working_set,
                                               global_bootstrap_options.pythonpath,
                                               global_bootstrap_options.plugins,
                                               global_bootstrap_options.backend_packages)
      self._set_build_configuration(build_configuration)
    else:
      build_configuration = self._get_build_configuration()

    # Parse and register options.
    options = self._install_options(self._options_bootstrapper, build_configuration)

    return options, build_configuration
Exemple #3
0
    def setup(self, init_logging=True):
        """Initializes logging, loads backends/plugins and parses options.

    :param bool init_logging: Whether or not to initialize logging as part of setup.
    :returns: A tuple of (options, build_configuration).
    """
        global_bootstrap_options = self._options_bootstrapper.get_bootstrap_options(
        ).for_global_scope()

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

        # Get logging setup prior to loading backends so that they can log as needed.
        if init_logging:
            self._setup_logging(global_bootstrap_options.quiet,
                                global_bootstrap_options.level,
                                global_bootstrap_options.logdir)

        # Conditionally load backends/plugins and materialize a `BuildConfiguration` object.
        if not self._has_build_configuration():
            missing = (set(
                global_bootstrap_options.default_backend_packages).difference(
                    global_bootstrap_options.backend_packages))
            deprecated_conditional(
                lambda: len(missing) > 0, '1.3.0',
                'default_backend_packages option',
                'You are relying on the following backends being listed in the deprecated '
                'default_backend_packages option: {}.\n  '
                'This is probably because you are overwriting the value of the backend_packages option '
                'in your pants.ini, instead of appending to it.\n  To get rid of this message, consider '
                'changing backend_packages: [...] to backend_packages: +[...] in your pants.ini. '
                'Once you are happy with the state of your backend_packages option, you can set '
                'default_backend_packages to [] to silence this warning.'.
                format(', '.join(missing)))

            backends = (global_bootstrap_options.default_backend_packages +
                        global_bootstrap_options.backend_packages)
            build_configuration = self._load_plugins(
                self._working_set, global_bootstrap_options.pythonpath,
                global_bootstrap_options.plugins, backends)
            self._set_build_configuration(build_configuration)
        else:
            build_configuration = self._get_build_configuration()

        # Parse and register options.
        options = self._install_options(self._options_bootstrapper,
                                        build_configuration)

        return options, build_configuration
Exemple #4
0
    def _setup_options(self, options_bootstrapper, working_set):
        # TODO: This inline import is currently necessary to resolve a ~legitimate cycle between
        # `GoalRunner`->`EngineInitializer`->`OptionsInitializer`->`GoalRunner`.
        from pants.bin.goal_runner import GoalRunner

        bootstrap_options = options_bootstrapper.get_bootstrap_options()
        global_bootstrap_options = bootstrap_options.for_global_scope()

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

        # Get logging setup prior to loading backends so that they can log as needed.
        if self._init_logging:
            self._setup_logging(global_bootstrap_options)

        # Add any extra paths to python path (e.g., for loading extra source backends).
        for path in global_bootstrap_options.pythonpath:
            sys.path.append(path)
            pkg_resources.fixup_namespace_packages(path)

        # Load plugins and backends.
        plugins = global_bootstrap_options.plugins
        backend_packages = global_bootstrap_options.backend_packages
        build_configuration = load_backends_and_plugins(
            plugins, working_set, backend_packages)

        # Now that plugins and backends are loaded, we can gather the known scopes.
        known_scope_infos = [GlobalOptionsRegistrar.get_scope_info()]

        # Add scopes for all needed subsystems via a union of all known subsystem sets.
        subsystems = Subsystem.closure(GoalRunner.subsystems()
                                       | Goal.subsystems()
                                       | build_configuration.subsystems())
        for subsystem in subsystems:
            known_scope_infos.append(subsystem.get_scope_info())

        # Add scopes for all tasks in all goals.
        for goal in Goal.all():
            known_scope_infos.extend(filter(None, goal.known_scope_infos()))

        # Now that we have the known scopes we can get the full options.
        options = options_bootstrapper.get_full_options(known_scope_infos)
        self._register_options(subsystems, options)

        # Make the options values available to all subsystems.
        Subsystem.set_options(options)

        return options, build_configuration
    def full_options(self, build_configuration: BuildConfiguration) -> Options:
        global_bootstrap_options = self.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.
        known_scope_infos = [
            subsystem.get_scope_info() for subsystem in build_configuration.all_subsystems
        ]
        options = self.full_options_for_scopes(
            known_scope_infos, allow_unknown_options=build_configuration.allow_unknown_options
        )
        GlobalOptions.validate_instance(options.for_global_scope())
        return options
    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
Exemple #7
0
    def create(
        cls,
        options_bootstrapper: OptionsBootstrapper,
        build_configuration: BuildConfiguration,
    ) -> Options:
        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.
        known_scope_infos = [
            si for optionable in build_configuration.all_optionables
            for si in optionable.known_scope_infos()
        ]
        options = options_bootstrapper.get_full_options(known_scope_infos)
        GlobalOptions.validate_instance(options.for_global_scope())
        return options
    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(
                'Version mismatch: Requested version was {}, our version is {}.'
                .format(global_bootstrap_options.pants_version,
                        pants_version()))

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

        if init_subsystems:
            Subsystem.set_options(options)

        return options