def test_global_options_validation(self): # Specify an invalid combination of options. ob = OptionsBootstrapper.create(args=['--loop', '--v1']) build_config = BuildConfigInitializer.get(ob) with self.assertRaises(OptionsError) as exc: OptionsInitializer.create(ob, build_config) self.assertIn('loop option only works with', str(exc.exception))
def test_create_bootstrapped_options(self): # Check that we can set a bootstrap option from a cmd-line flag and have that interpolate # correctly into regular config. with temporary_file(binary_mode=False) as fp: fp.write( dedent(""" [foo] bar: %(pants_workdir)s/baz [fruit] apple: %(pants_supportdir)s/banana """)) fp.close() args = ['--pants-workdir=/qux'] + self._config_path(fp.name) bootstrapper = OptionsBootstrapper.create( env={'PANTS_SUPPORTDIR': '/pear'}, args=args) opts = bootstrapper.get_full_options(known_scope_infos=[ ScopeInfo('', ScopeInfo.GLOBAL), ScopeInfo('foo', ScopeInfo.TASK), ScopeInfo('fruit', ScopeInfo.TASK) ]) # So we don't choke on these on the cmd line. opts.register('', '--pants-workdir') opts.register('', '--pants-config-files') opts.register('foo', '--bar') opts.register('fruit', '--apple') self.assertEqual('/qux/baz', opts.for_scope('foo').bar) self.assertEqual('/pear/banana', opts.for_scope('fruit').apple)
def execute(self): try: pantsd = PantsDaemon.Factory.create(OptionsBootstrapper.create(), full_init=False) with pantsd.lifecycle_lock: pantsd.terminate() except ProcessManager.NonResponsiveProcess as e: raise TaskError('failure while terminating pantsd: {}'.format(e))
def test_full_options_caching(self): with temporary_file_path() as config: args = self._config_path(config) bootstrapper = OptionsBootstrapper.create(env={}, args=args) opts1 = bootstrapper.get_full_options(known_scope_infos=[ ScopeInfo('', ScopeInfo.GLOBAL), ScopeInfo('foo', ScopeInfo.TASK) ]) opts2 = bootstrapper.get_full_options(known_scope_infos=[ ScopeInfo('foo', ScopeInfo.TASK), ScopeInfo('', ScopeInfo.GLOBAL) ]) self.assertIs(opts1, opts2) opts3 = bootstrapper.get_full_options(known_scope_infos=[ ScopeInfo('', ScopeInfo.GLOBAL), ScopeInfo('foo', ScopeInfo.TASK), ScopeInfo('', ScopeInfo.GLOBAL) ]) self.assertIs(opts1, opts3) opts4 = bootstrapper.get_full_options( known_scope_infos=[ScopeInfo('', ScopeInfo.GLOBAL)]) self.assertIsNot(opts1, opts4) opts5 = bootstrapper.get_full_options( known_scope_infos=[ScopeInfo('', ScopeInfo.GLOBAL)]) self.assertIs(opts4, opts5) self.assertIsNot(opts1, opts5)
def test_create_bootstrapped_options(self): # Check that we can set a bootstrap option from a cmd-line flag and have that interpolate # correctly into regular config. with temporary_file(binary_mode=False) as fp: fp.write(dedent(""" [foo] bar: %(pants_workdir)s/baz [fruit] apple: %(pants_supportdir)s/banana """)) fp.close() args = ['--pants-workdir=/qux'] + self._config_path(fp.name) bootstrapper = OptionsBootstrapper.create(env={ 'PANTS_SUPPORTDIR': '/pear' }, args=args) opts = bootstrapper.get_full_options(known_scope_infos=[ ScopeInfo('', ScopeInfo.GLOBAL), ScopeInfo('foo', ScopeInfo.TASK), ScopeInfo('fruit', ScopeInfo.TASK) ]) # So we don't choke on these on the cmd line. opts.register('', '--pants-workdir') opts.register('', '--pants-config-files') opts.register('foo', '--bar') opts.register('fruit', '--apple') self.assertEqual('/qux/baz', opts.for_scope('foo').bar) self.assertEqual('/pear/banana', opts.for_scope('fruit').apple)
def get_bootstrap_options(self, cli_options=()): """Retrieves bootstrap options. :param cli_options: An iterable of CLI flags to pass as arguments to `OptionsBootstrapper`. """ args = tuple(['--pants-config-files=[]']) + tuple(cli_options) return OptionsBootstrapper.create(args=args).bootstrap_options.for_global_scope()
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(args=[argv[0]]) subsystems = (GlobalOptionsRegistrar, 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)
def plugin_resolution(self, *, interpreter=None, chroot=None, plugins=None, sdist=True): @contextmanager def provide_chroot(existing): if existing: yield existing, False else: with temporary_dir() as new_chroot: yield new_chroot, True with provide_chroot(chroot) as (root_dir, create_artifacts): env = {} repo_dir = None if plugins: repo_dir = os.path.join(root_dir, "repo") env.update( PANTS_PYTHON_REPOS_REPOS=f"[{repo_dir!r}]", PANTS_PYTHON_REPOS_INDEXES="[]", PANTS_PYTHON_SETUP_RESOLVER_CACHE_TTL="1", ) plugin_list = [] for plugin in plugins: version = None if isinstance(plugin, tuple): plugin, version = plugin plugin_list.append( f"{plugin}=={version}" if version else plugin) if create_artifacts: setup_py_args = [ "sdist" if sdist else "bdist_wheel", "--dist-dir", "dist/" ] self._run_setup_py(plugin, version, setup_py_args, repo_dir) env["PANTS_PLUGINS"] = f"[{','.join(map(repr, plugin_list))}]" env["PANTS_PLUGIN_CACHE_DIR"] = os.path.join( root_dir, "plugin-cache") configpath = os.path.join(root_dir, "pants.toml") if create_artifacts: touch(configpath) args = [f"--pants-config-files=['{configpath}']"] options_bootstrapper = OptionsBootstrapper.create( env=env, args=args, allow_pantsrc=False) plugin_resolver = PluginResolver(options_bootstrapper, interpreter=interpreter) cache_dir = plugin_resolver.plugin_cache_dir working_set = plugin_resolver.resolve(WorkingSet(entries=[])) for dist in working_set: assert (Path(os.path.realpath(cache_dir)) in Path(os.path.realpath(dist.location)).parents) yield working_set, root_dir, repo_dir, cache_dir
def get_bootstrap_options(self, cli_options=()): """Retrieves bootstrap options. :param cli_options: An iterable of CLI flags to pass as arguments to `OptionsBootstrapper`. """ args = tuple(['--pants-config-files=[]']) + tuple(cli_options) return OptionsBootstrapper.create( args=args).bootstrap_options.for_global_scope()
def launch_new_pantsd_instance(): """An external entrypoint that spawns a new pantsd instance.""" options_bootstrapper = OptionsBootstrapper.create( env=os.environ, args=sys.argv, allow_pantsrc=True ) daemon = PantsDaemon.create(options_bootstrapper) daemon.run_sync()
def test_bootstrapped_options_ignore_irrelevant_env(self) -> None: included = "PANTS_DISTDIR" excluded = "NON_PANTS_ENV" bootstrapper = OptionsBootstrapper.create( env={excluded: "pear", included: "banana"}, args=[], allow_pantsrc=False ) self.assertIn(included, bootstrapper.env) self.assertNotIn(excluded, bootstrapper.env)
def test_global_options_validation(self): # Specify an invalid combination of options. ob = OptionsBootstrapper.create( args=['--backend-packages=[]', '--loop', '--v1']) build_config = BuildConfigInitializer.get(ob) with self.assertRaises(OptionsError) as exc: OptionsInitializer.create(ob, build_config) self.assertIn('loop option only works with', str(exc.exception))
def get_bootstrap_options(self, cli_options=()): """Retrieves bootstrap options. :param cli_options: An iterable of CLI flags to pass as arguments to `OptionsBootstrapper`. """ # Can't parse any options without a pants.ini. self.create_file('pants.ini') return OptionsBootstrapper.create(args=cli_options).bootstrap_options.for_global_scope()
def create_options_bootstrapper( args: Iterable[str] | None = None, *, env: Mapping[str, str] | None = None ) -> OptionsBootstrapper: return OptionsBootstrapper.create( args=("--pants-config-files=[]", *(args or [])), env=env or {}, allow_pantsrc=False, )
def test_bootstrapped_options_ignore_irrelevant_env(self) -> None: included = "PANTS_SUPPORTDIR" excluded = "NON_PANTS_ENV" bootstrapper = OptionsBootstrapper.create(env={ excluded: "pear", included: "banana" }) self.assertIn(included, bootstrapper.env) self.assertNotIn(excluded, bootstrapper.env)
def test_global_options_validation(self): # Specify an invalid combination of options. ob = OptionsBootstrapper.create( args=['--backend-packages=[]', '--backend-packages2=[]', '--v2', '--no-v1', '--loop', '--no-enable-pantsd']) build_config = BuildConfigInitializer.get(ob) with self.assertRaises(OptionsError) as exc: OptionsInitializer.create(ob, build_config) self.assertIn('The `--loop` option requires `--enable-pantsd`', str(exc.exception))
def test_invalidation_globs() -> None: # Confirm that an un-normalized relative path in the pythonpath is filtered out. suffix = "something-ridiculous" ob = OptionsBootstrapper.create(env={}, args=[f"--pythonpath=../{suffix}"], allow_pantsrc=False) globs = GlobalOptions.compute_pantsd_invalidation_globs( get_buildroot(), ob.bootstrap_options.for_global_scope() ) for glob in globs: assert suffix not in glob
def test_global_options_validation(self): # Specify an invalid combination of options. ob = OptionsBootstrapper.create( env={}, args=["--backend-packages=[]", "--remote-execution"], allow_pantsrc=False ) env = CompleteEnvironment({}) with self.assertRaises(OptionsError) as exc: OptionsInitializer(ob, env).build_config_and_options(ob, env, raise_=True) self.assertIn("The `--remote-execution` option requires", str(exc.exception))
def parse_options( args: List[str], env: Dict[str, str], options_bootstrapper: Optional[OptionsBootstrapper] = None, ) -> Tuple[Options, BuildConfiguration, OptionsBootstrapper]: options_bootstrapper = options_bootstrapper or OptionsBootstrapper.create(args=args, env=env) build_config = BuildConfigInitializer.get(options_bootstrapper) options = OptionsInitializer.create(options_bootstrapper, build_config) return options, build_config, options_bootstrapper
def parse_options(args, env, setup_logging=False, options_bootstrapper=None): options_bootstrapper = options_bootstrapper or OptionsBootstrapper.create(args=args, env=env) bootstrap_options = options_bootstrapper.get_bootstrap_options().for_global_scope() if setup_logging: # Bootstrap logging and then fully initialize options. setup_logging_from_options(bootstrap_options) build_config = BuildConfigInitializer.get(options_bootstrapper) options = OptionsInitializer.create(options_bootstrapper, build_config) return options, build_config, options_bootstrapper
def create_options_bootstrapper( *, args: Optional[Iterable[str]] = None, env: Optional[Dict[str, str]] = None, ) -> OptionsBootstrapper: return OptionsBootstrapper.create( args=("--pants-config-files=[]", *(args or [])), env=env or {}, )
def test_invalid_version(self): options_bootstrapper = OptionsBootstrapper.create(args=[ "--backend-packages=[]", "--backend-packages2=[]", "--pants-version=99.99.9999" ]) build_config = BuildConfigInitializer.get(options_bootstrapper) with self.assertRaises(BuildConfigurationError): OptionsInitializer.create(options_bootstrapper, build_config)
def kill_daemon(pid_dir=None): args = ["./pants"] if pid_dir: args.append(f"--pants-subprocessdir={pid_dir}") pantsd_client = PantsDaemonClient( OptionsBootstrapper.create(env=os.environ, args=args, allow_pantsrc=False).bootstrap_options ) with pantsd_client.lifecycle_lock: pantsd_client.terminate()
def test_bootstrapped_options_ignore_irrelevant_env(self): included = 'PANTS_SUPPORTDIR' excluded = 'NON_PANTS_ENV' bootstrapper = OptionsBootstrapper.create(env={ excluded: 'pear', included: 'banana', }) self.assertIn(included, bootstrapper.env) self.assertNotIn(excluded, bootstrapper.env)
def get_bootstrap_options(cli_options=()): """Retrieves bootstrap options. :param cli_options: An iterable of CLI flags to pass as arguments to `OptionsBootstrapper`. """ args = tuple(["--pants-config-files=[]"]) + tuple(cli_options) return OptionsBootstrapper.create( env={}, args=args, allow_pantsrc=False ).bootstrap_options.for_global_scope()
def test_invalid_version(self): options_bootstrapper = OptionsBootstrapper.create( env={}, args=["--backend-packages=[]", "--pants-version=99.99.9999"], allow_pantsrc=False, ) with self.assertRaises(BuildConfigurationError): OptionsInitializer(options_bootstrapper).build_config_and_options( options_bootstrapper, raise_=True)
def _ob(self, args=tuple(), env=tuple()): self.create_file('pants.ini') options_bootstrap = OptionsBootstrapper.create( args=tuple(args), env=dict(env), ) # NB: BuildConfigInitializer has sideeffects on first-run: in actual usage, these # sideeffects will happen during setup. We force them here. BuildConfigInitializer.get(options_bootstrap) return options_bootstrap
def test_global_options_validation(self): # Specify an invalid combination of options. ob = OptionsBootstrapper.create( env={}, args=["--backend-packages=[]", "--remote-execution"], allow_pantsrc=False) build_config = BuildConfigInitializer.get(ob) with self.assertRaises(OptionsError) as exc: OptionsInitializer.create(ob, build_config) self.assertIn("The `--remote-execution` option requires", str(exc.exception))
def test_bootstrapped_options_ignore_irrelevant_env(self): included = 'PANTS_SUPPORTDIR' excluded = 'NON_PANTS_ENV' bootstrapper = OptionsBootstrapper.create( env={ excluded: 'pear', included: 'banana', } ) self.assertIn(included, bootstrapper.env) self.assertNotIn(excluded, bootstrapper.env)
def _ob(self, args=tuple(), env=None): self.create_file("pants.toml") options_bootstrap = OptionsBootstrapper.create( args=tuple(args), env=env or {}, allow_pantsrc=False, ) # NB: BuildConfigInitializer has sideeffects on first-run: in actual usage, these # sideeffects will happen during setup. We force them here. BuildConfigInitializer.get(options_bootstrap) return options_bootstrap
def test_invalid_version(self) -> None: options_bootstrapper = OptionsBootstrapper.create( env={}, args=["--backend-packages=[]", "--pants-version=99.99.9999"], allow_pantsrc=False, ) env = CompleteEnvironment({}) with self.assertRaises(ExecutionError): OptionsInitializer(options_bootstrapper).build_config_and_options( options_bootstrapper, env, raise_=True)
def test_invalidation_globs() -> None: # Confirm that an un-normalized relative path in the pythonpath is filtered out, and that an # empty entry (i.e.: a relative path for the current directory) doesn't cause an error. suffix = "something-ridiculous" ob = OptionsBootstrapper.create( env={}, args=[f"--pythonpath=../{suffix}", "--pythonpath="], allow_pantsrc=False) globs = GlobalOptions.compute_pantsd_invalidation_globs( get_buildroot(), ob.bootstrap_options.for_global_scope()) for glob in globs: assert suffix not in glob
def test_setting_pants_config_in_config(self, tmp_path: Path) -> None: # Test that setting pants_config in the config file has no effect. config1 = tmp_path / "config1" config2 = tmp_path / "config2" config1.write_text(f"[DEFAULT]\npants_config_files = ['{config2}']\nlogdir = 'logdir1'\n") config2.write_text("[DEFAULT]\nlogdir = 'logdir2'\n") ob = OptionsBootstrapper.create( env={}, args=[f"--pants-config-files=['{config1.as_posix()}']"], allow_pantsrc=False ) logdir = ob.get_bootstrap_options().for_global_scope().logdir assert "logdir1" == logdir
def test_setting_pants_config_in_config(self) -> None: # Test that setting pants_config in the config file has no effect. with temporary_dir() as tmpdir: config1 = os.path.join(tmpdir, 'config1') config2 = os.path.join(tmpdir, 'config2') with open(config1, 'w') as out1: out1.write(f"[DEFAULT]\npants_config_files: ['{config2}']\nlogdir: logdir1\n") with open(config2, 'w') as out2: out2.write('[DEFAULT]\nlogdir: logdir2\n') ob = OptionsBootstrapper.create(env={}, args=[f"--pants-config-files=['{config1}']"]) logdir = ob.get_bootstrap_options().for_global_scope().logdir self.assertEqual('logdir1', logdir)
def test_setting_pants_config_in_config(self): # Test that setting pants_config in the config file has no effect. with temporary_dir() as tmpdir: config1 = os.path.join(tmpdir, 'config1') config2 = os.path.join(tmpdir, 'config2') with open(config1, 'w') as out1: out1.write("[DEFAULT]\npants_config_files: ['{}']\nlogdir: logdir1\n".format(config2)) with open(config2, 'w') as out2: out2.write('[DEFAULT]\nlogdir: logdir2\n') ob = OptionsBootstrapper.create(env={}, args=["--pants-config-files=['{}']".format(config1)]) logdir = ob.get_bootstrap_options().for_global_scope().logdir self.assertEqual('logdir1', logdir)
def __init__( self, *, rules: Optional[Iterable] = None, target_types: Optional[Iterable[Type[Target]]] = None, objects: Optional[Dict[str, Any]] = None, context_aware_object_factories: Optional[Dict[str, Any]] = None, ) -> None: self.build_root = os.path.realpath(mkdtemp(suffix="_BUILD_ROOT")) safe_mkdir(self.build_root, clean=True) safe_mkdir(self.pants_workdir) BuildRoot().path = self.build_root # TODO: Redesign rule registration for tests to be more ergonomic and to make this less # special-cased. all_rules = ( *(rules or ()), *source_root.rules(), QueryRule(WrappedTarget, (Address, OptionsBootstrapper)), ) build_config_builder = BuildConfiguration.Builder() build_config_builder.register_aliases( BuildFileAliases( objects=objects, context_aware_object_factories=context_aware_object_factories ) ) build_config_builder.register_rules(all_rules) build_config_builder.register_target_types(target_types or ()) self.build_config = build_config_builder.create() options_bootstrapper = OptionsBootstrapper.create( env={}, args=["--pants-config-files=[]"], allow_pantsrc=False ) global_options = options_bootstrapper.bootstrap_options.for_global_scope() local_store_dir = global_options.local_store_dir local_execution_root_dir = global_options.local_execution_root_dir named_caches_dir = global_options.named_caches_dir graph_session = EngineInitializer.setup_graph_extended( pants_ignore_patterns=[], use_gitignore=False, local_store_dir=local_store_dir, local_execution_root_dir=local_execution_root_dir, named_caches_dir=named_caches_dir, native=Native(), options_bootstrapper=options_bootstrapper, build_root=self.build_root, build_configuration=self.build_config, execution_options=ExecutionOptions.from_bootstrap_options(global_options), ).new_session(build_id="buildid_for_test", should_report_workunits=True) self.scheduler = graph_session.scheduler_session
def _test_bootstrap_options(self, config, env, args, **expected_entries): with temporary_file(binary_mode=False) as fp: fp.write('[DEFAULT]\n') if config: for k, v in config.items(): fp.write('{0}: {1}\n'.format(k, v)) fp.close() args = args + self._config_path(fp.name) bootstrapper = OptionsBootstrapper.create(env=env, args=args) vals = bootstrapper.get_bootstrap_options().for_global_scope() vals_dict = {k: getattr(vals, k) for k in expected_entries} self.assertEqual(expected_entries, vals_dict)
def test_full_options_caching(self): with temporary_file_path() as config: args = self._config_path(config) bootstrapper = OptionsBootstrapper.create(env={}, args=args) opts1 = bootstrapper.get_full_options(known_scope_infos=[ScopeInfo('', ScopeInfo.GLOBAL), ScopeInfo('foo', ScopeInfo.TASK)]) opts2 = bootstrapper.get_full_options(known_scope_infos=[ScopeInfo('foo', ScopeInfo.TASK), ScopeInfo('', ScopeInfo.GLOBAL)]) self.assertIs(opts1, opts2) opts3 = bootstrapper.get_full_options(known_scope_infos=[ScopeInfo('', ScopeInfo.GLOBAL), ScopeInfo('foo', ScopeInfo.TASK), ScopeInfo('', ScopeInfo.GLOBAL)]) self.assertIs(opts1, opts3) opts4 = bootstrapper.get_full_options(known_scope_infos=[ScopeInfo('', ScopeInfo.GLOBAL)]) self.assertIsNot(opts1, opts4) opts5 = bootstrapper.get_full_options(known_scope_infos=[ScopeInfo('', ScopeInfo.GLOBAL)]) self.assertIs(opts4, opts5) self.assertIsNot(opts1, opts5)
def _init_engine(cls): if cls._scheduler is not None: return cls._local_store_dir = os.path.realpath(safe_mkdtemp()) safe_mkdir(cls._local_store_dir) # NB: This uses the long form of initialization because it needs to directly specify # `cls.alias_groups` rather than having them be provided by bootstrap options. graph_session = EngineInitializer.setup_legacy_graph_extended( pants_ignore_patterns=None, workdir=cls._pants_workdir(), local_store_dir=cls._local_store_dir, build_file_imports_behavior='allow', native=init_native(), options_bootstrapper=OptionsBootstrapper.create(args=['--pants-config-files=[]']), build_configuration=cls.build_config(), build_ignore_patterns=None, ).new_session(zipkin_trace_v2=False) cls._scheduler = graph_session.scheduler_session cls._build_graph, cls._address_mapper = graph_session.create_build_graph( TargetRoots([]), cls._build_root() )
def run(self): # Register our exiter at the beginning of the run() method so that any code in this process from # this point onwards will use that exiter in the case of a fatal error. ExceptionSink.reset_exiter(self._exiter) options_bootstrapper = OptionsBootstrapper.create(env=self._env, args=self._args) bootstrap_options = options_bootstrapper.bootstrap_options global_bootstrap_options = bootstrap_options.for_global_scope() # We enable Rust logging here, # and everything before it will be routed through regular Python logging. self._enable_rust_logging(global_bootstrap_options) ExceptionSink.reset_should_print_backtrace_to_terminal(global_bootstrap_options.print_exception_stacktrace) ExceptionSink.reset_log_location(global_bootstrap_options.pants_workdir) for message_regexp in global_bootstrap_options.ignore_pants_warnings: warnings.filterwarnings(action='ignore', message=message_regexp) if global_bootstrap_options.enable_pantsd: try: return RemotePantsRunner(self._exiter, self._args, self._env, options_bootstrapper).run() except RemotePantsRunner.Fallback as e: logger.warn('caught client exception: {!r}, falling back to non-daemon mode'.format(e)) # N.B. Inlining this import speeds up the python thin client run by about 100ms. from pants.bin.local_pants_runner import LocalPantsRunner runner = LocalPantsRunner.create( self._exiter, self._args, self._env, options_bootstrapper=options_bootstrapper ) runner.set_start_time(self._start_time) return runner.run()
def plugin_resolution(self, chroot=None, plugins=None, packager_cls=None): @contextmanager def provide_chroot(existing): if existing: yield existing, False else: with temporary_dir() as new_chroot: yield new_chroot, True with provide_chroot(chroot) as (root_dir, create_artifacts): env = {'PANTS_BOOTSTRAPDIR': root_dir} repo_dir = None if plugins: repo_dir = os.path.join(root_dir, 'repo') env.update(PANTS_PYTHON_REPOS_REPOS='[{!r}]'.format(repo_dir), PANTS_PYTHON_REPOS_INDEXES='[]', PANTS_PYTHON_SETUP_RESOLVER_CACHE_TTL='1') plugin_list = [] for plugin in plugins: version = None if isinstance(plugin, tuple): plugin, version = plugin plugin_list.append('{}=={}'.format(plugin, version) if version else plugin) if create_artifacts: self.create_plugin(repo_dir, plugin, version, packager_cls=packager_cls) env['PANTS_PLUGINS'] = '[{}]'.format(','.join(map(repr, plugin_list))) configpath = os.path.join(root_dir, 'pants.ini') if create_artifacts: touch(configpath) args = ["--pants-config-files=['{}']".format(configpath)] options_bootstrapper = OptionsBootstrapper.create(env=env, args=args) plugin_resolver = PluginResolver(options_bootstrapper) cache_dir = plugin_resolver.plugin_cache_dir yield plugin_resolver.resolve(WorkingSet(entries=[])), root_dir, repo_dir, cache_dir
def create_options_bootstrapper(*config_paths): return OptionsBootstrapper.create(args=['--pantsrc-files={}'.format(cp) for cp in config_paths])
def parse_options(*args): full_args = list(args) + self._config_path(None) return OptionsBootstrapper.create(args=full_args).get_bootstrap_options().for_global_scope()
def test_invalid_version(self): options_bootstrapper = OptionsBootstrapper.create(args=['--pants-version=99.99.9999']) build_config = BuildConfigInitializer.get(options_bootstrapper) with self.assertRaises(BuildConfigurationError): OptionsInitializer.create(options_bootstrapper, build_config)
def parse_options(args, env, options_bootstrapper=None): options_bootstrapper = options_bootstrapper or OptionsBootstrapper.create(args=args, env=env) build_config = BuildConfigInitializer.get(options_bootstrapper) options = OptionsInitializer.create(options_bootstrapper, build_config) return options, build_config, options_bootstrapper
def launch(): """An external entrypoint that spawns a new pantsd instance.""" PantsDaemon.Factory.create(OptionsBootstrapper.create()).run_sync()