async def format_python_target( python_fmt_targets: PythonFmtTargets, union_membership: UnionMembership) -> LanguageFmtResults: targets_with_origins = python_fmt_targets.targets_with_origins original_sources = await Get[SourceFiles](AllSourceFilesRequest( target_with_origin.target[PythonSources] for target_with_origin in python_fmt_targets.targets_with_origins)) prior_formatter_result = original_sources.snapshot results: List[FmtResult] = [] config_collection_types: Iterable[ Type[FmtConfigurations]] = union_membership.union_rules[ PythonFmtConfigurations] for config_collection_type in config_collection_types: result = await Get[FmtResult]( PythonFmtConfigurations, config_collection_type( (config_collection_type.config_type.create(target_with_origin) for target_with_origin in targets_with_origins), prior_formatter_result=prior_formatter_result, ), ) if result != FmtResult.noop(): results.append(result) prior_formatter_result = await Get[Snapshot](Digest, result.digest) return LanguageFmtResults( tuple(results), combined_digest=prior_formatter_result.directory_digest)
async def format_python_target( python_fmt_targets: PythonFmtTargets, union_membership: UnionMembership) -> LanguageFmtResults: targets_with_origins = python_fmt_targets.targets_with_origins original_sources = await Get[SourceFiles](AllSourceFilesRequest( target_with_origin.target[PythonSources] for target_with_origin in python_fmt_targets.targets_with_origins)) prior_formatter_result = original_sources.snapshot results: List[FmtResult] = [] fmt_request_types: Iterable[ Type[FmtRequest]] = union_membership.union_rules[PythonFmtRequest] for fmt_request_type in fmt_request_types: result = await Get[FmtResult]( PythonFmtRequest, fmt_request_type( (fmt_request_type.field_set_type.create(target_with_origin) for target_with_origin in targets_with_origins), prior_formatter_result=prior_formatter_result, ), ) if result != FmtResult.noop(): results.append(result) if result.did_change: prior_formatter_result = await Get[Snapshot](Digest, result.output) return LanguageFmtResults( tuple(results), input=original_sources.snapshot.digest, output=prior_formatter_result.digest, )
async def isort_fmt(configs: IsortConfigurations, isort: Isort) -> FmtResult: if isort.options.skip: return FmtResult.noop() setup = await Get[Setup](SetupRequest(configs, check_only=False)) result = await Get[ProcessResult](Process, setup.process) return FmtResult.from_process_result(result, original_digest=setup.original_digest)
async def docformatter_fmt(configs: DocformatterConfigurations, docformatter: Docformatter) -> FmtResult: if docformatter.options.skip: return FmtResult.noop() setup = await Get[Setup](SetupRequest(configs, check_only=False)) result = await Get[ProcessResult](Process, setup.process) return FmtResult.from_process_result(result)
async def docformatter_fmt(request: DocformatterRequest, docformatter: Docformatter) -> FmtResult: if docformatter.options.skip: return FmtResult.noop() setup = await Get[Setup](SetupRequest(request, check_only=False)) result = await Get[ProcessResult](Process, setup.process) return FmtResult.from_process_result( result, original_digest=setup.original_digest, formatter_name="Docformatter" )
async def isort_fmt(request: IsortRequest, isort: Isort) -> FmtResult: if isort.options.skip: return FmtResult.noop() setup = await Get[Setup](SetupRequest(request, check_only=False)) result = await Get[ProcessResult](Process, setup.process) return FmtResult.from_process_result( result, original_digest=setup.original_digest, formatter_name="isort", strip_chroot_path=True, )
async def black_fmt(field_sets: BlackFieldSets, black: Black) -> FmtResult: if black.options.skip: return FmtResult.noop() setup = await Get[Setup](SetupRequest(field_sets, check_only=False)) result = await Get[ProcessResult](Process, setup.process) return FmtResult.from_process_result( result, original_digest=setup.original_digest, formatter_name="Black", strip_chroot_path=True, )
def test_skip(self) -> None: target = self.make_target_with_origin([self.bad_source]) lint_result, fmt_result = self.run_isort([target], skip=True) assert lint_result == LintResult.noop() assert fmt_result == FmtResult.noop() assert fmt_result.did_change is False
def test_skip(self) -> None: target = self.make_target_with_origin([self.bad_source]) lint_result, fmt_result = self.run_docformatter([target], skip=True) assert lint_result == LintResult.noop() assert fmt_result == FmtResult.noop()
def test_skip(self) -> None: target = self.make_target([self.bad_source]) lint_results, fmt_result = self.run_black([target], skip=True) assert not lint_results assert fmt_result == FmtResult.noop() assert fmt_result.did_change is False
async def black_fmt(configs: BlackConfigurations, black: Black) -> FmtResult: if black.options.skip: return FmtResult.noop() setup = await Get[Setup](SetupRequest(configs, check_only=False)) result = await Get[ProcessResult](Process, setup.process) return FmtResult.from_process_result(result)