示例#1
0
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)
示例#2
0
文件: python_fmt.py 项目: wiwa/pants
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,
    )
示例#3
0
文件: rules.py 项目: Thangiee/pants
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)
示例#4
0
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)
示例#5
0
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"
    )
示例#6
0
文件: rules.py 项目: briespoke/pants
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,
    )
示例#7
0
文件: rules.py 项目: LarryFinn/pants
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,
    )
示例#8
0
 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
示例#9
0
 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()
示例#10
0
 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
示例#11
0
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)