def test_backend_plugin_ordering(self): def reg_alias(): return BuildFileAliases(targets={'override-alias': DummyTarget2}) self.working_set.add(self.get_mock_plugin('pluginalias', '0.0.1', alias=reg_alias)) plugins=['pluginalias==0.0.1']; aliases = BuildFileAliases(targets={'override-alias': DummyTarget}) with self.create_register(build_file_aliases=lambda: aliases) as backend_module: backends=[backend_module] load_backends_and_plugins(plugins, self.working_set, backends, build_configuration=self.build_configuration) # The backend should load first, then the plugins, therefore the alias registered in # the plugin will override the alias registered by the backend registered_aliases = self.build_configuration.registered_aliases() self.assertEqual(DummyTarget2, registered_aliases.target_types['override-alias'])
def test_backend_plugin_ordering(self): def reg_alias(): return BuildFileAliases(targets={'override-alias': DummyTarget2}) self.working_set.add(self.get_mock_plugin('pluginalias', '0.0.1', alias=reg_alias)) plugins=['pluginalias==0.0.1'] aliases = BuildFileAliases(targets={'override-alias': DummyTarget}) with self.create_register(build_file_aliases=lambda: aliases) as backend_module: backends=[backend_module] load_backends_and_plugins(plugins, self.working_set, backends, build_configuration=self.build_configuration) # The backend should load first, then the plugins, therefore the alias registered in # the plugin will override the alias registered by the backend registered_aliases = self.build_configuration.registered_aliases() self.assertEqual(DummyTarget2, registered_aliases.target_types['override-alias'])
def _load_plugins(self, working_set, python_paths, plugins, backend_packages): """Load backends and plugins. :returns: A `BuildConfiguration` object constructed during backend/plugin loading. """ # Add any extra paths to python path (e.g., for loading extra source backends). for path in python_paths: if path not in sys.path: sys.path.append(path) pkg_resources.fixup_namespace_packages(path) # Load plugins and backends. return load_backends_and_plugins(plugins, working_set, backend_packages)
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 _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