in src/python/pants/core_tasks/explain_options_task.py [0:0]
def console_output(self, targets):
self._force_option_parsing()
if self.is_json():
output_map = {}
for scope, options in sorted(self.context.options.tracker.option_history_by_scope.items()):
if not self._scope_filter(scope):
continue
for option, history in sorted(options.items()):
if not self._option_filter(option):
continue
if not self._rank_filter(history.latest.rank):
continue
if self.get_options().only_overridden and not history.was_overridden:
continue
# Skip the option if it has already passed the deprecation period.
if history.latest.deprecation_version and PANTS_SEMVER >= Version(
history.latest.deprecation_version):
continue
if self.get_options().skip_inherited:
parent_scope, parent_value = self._get_parent_scope_option(scope, option)
if parent_scope is not None and parent_value == history.latest.value:
continue
if self.is_json():
value, rank_name = self._format_record(history.latest)
scope_key = self._format_scope(scope, option, True)
# We rely on the fact that option values are restricted to a set of types compatible with
# json. In particular, we expect dict, list, str, bool, int and float, and so do no
# processing here.
# TODO(John Sirois): The option parsing system currently lets options of unexpected types
# slide by, which can lead to un-overridable values and which would also blow up below in
# json encoding, fix options to restrict the allowed `type`s:
# https://github.com/pantsbuild/pants/issues/4695
inner_map = dict(value=value, source=rank_name)
output_map[scope_key] = inner_map
elif self.is_text():
yield '{} = {}'.format(self._format_scope(scope, option),
self._format_record(history.latest))
if self.get_options().show_history:
history_list = []
for line in self._show_history(history):
if self.is_text():
yield line
elif self.is_json():
history_list.append(line.strip())
if self.is_json():
inner_map["history"] = history_list
if self.is_json():
yield json.dumps(output_map, indent=2, sort_keys=True, cls=CoercingOptionEncoder)