def format_with_styles(formatter, # type: CodeFormatter
styles, # type: List[Style]
filenames, # type: List[str]
reporterrors=True, # type: bool
cache=None, # type: Optional[Cache]
ccmode=CC_PROCESSES # type: str
):
# type: (...) -> Iterator[Tuple[ExeCall, ExeResult]]
"""Reformat all files with all styles and yield pairs
(job, jobresult) of all reformat operations.
"""
jobs = []
sourcecodes = []
for style, filename in itertools.product(styles, filenames):
cmdargs = formatter.cmdargs_for_style(style, filename)
sourcedata = get_cached_file(filename)
jobs.append(make_execall(formatter.exe, cmdargs, sourcedata, depfiles=[filename]))
sourcecodes.append(sourcedata)
jobresults = run_executables(jobs, cache, ccmode=ccmode)
for srcdata, job, jobres in izip(sourcecodes, jobs, jobresults):
if reporterrors:
formatter.reporterrors(job, jobres)
# A formatter reporting a valid result for non-empty input while returning empty
# output indicates that the effective result is the unchanged input.
if not jobres.stdout and srcdata and formatter.valid_job_result(job, jobres):
jobres = jobres._replace(stdout=srcdata)
yield job, jobres
评论列表
文章目录