def _run(exiter): # Place the registration of the unhandled exception hook as early as possible in the code. sys.excepthook = exiter.unhandled_exception_hook # We want to present warnings to the user, set this up early to ensure all warnings are seen. # The "default" action displays a warning for a particular file and line number exactly once. # See https://docs.python.org/2/library/warnings.html#the-warnings-filter for the complete action # list. warnings.simplefilter("default") # The GoalRunner will setup final logging below in `.setup()`, but span the gap until then. logging.basicConfig(level=logging.INFO) # This routes the warnings we enabled above through our loggers instead of straight to stderr raw. logging.captureWarnings(True) root_dir = get_buildroot() if not os.path.exists(root_dir): exiter.exit_and_fail( 'PANTS_BUILD_ROOT does not point to a valid path: {}'.format( root_dir)) options_bootstrapper = OptionsBootstrapper() plugin_resolver = PluginResolver(options_bootstrapper) working_set = plugin_resolver.resolve() goal_runner = GoalRunner(root_dir) goal_runner.setup(options_bootstrapper, working_set) exiter.apply_options(goal_runner.options) result = goal_runner.run() exiter.do_exit(result)
def plugin_resolution(chroot=None, plugins=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: create_plugin(repo_dir, plugin, version) env['PANTS_PLUGINS'] = '[{}]'.format(','.join(map(repr, plugin_list))) configpath = os.path.join(root_dir, 'pants.ini') if create_artifacts: touch(configpath) options_bootstrapper = OptionsBootstrapper(env=env, configpath=configpath, 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