Esempio n. 1
0
def is_ownable_target(tgt: Target, union_membership: UnionMembership) -> bool:
    return (
        # Note that we check for a PythonProvides field so that a python_distribution
        # target can be owned (by itself). This is so that if there are any 3rdparty
        # requirements directly on the python_distribution target, we apply them to the dist.
        # This isn't particularly useful (3rdparty requirements should be on the python_library
        # that consumes them)... but users may expect it to work anyway.
        tgt.has_field(PythonProvidesField) or tgt.has_field(PythonSources)
        or tgt.has_field(ResourcesSources)
        or tgt.get(Sources).can_generate(PythonSources, union_membership))
Esempio n. 2
0
def is_ownable_target(tgt: Target, union_membership: UnionMembership) -> bool:
    return (
        # Note that we check for a PythonProvides field so that a python_distribution
        # target can be owned (by itself). This is so that if there are any 3rdparty
        # requirements directly on the python_distribution target, we apply them to the dist.
        # This isn't particularly useful (3rdparty requirements should be on the python_sources
        # that consumes them)... but users may expect it to work anyway.
        tgt.has_field(PythonProvidesField)
        or tgt.has_field(PythonSourceField)
        or tgt.has_field(ResourceSourceField)
        or tgt.get(SourcesField).can_generate(PythonSourceField, union_membership)
        or tgt.get(SourcesField).can_generate(ResourceSourceField, union_membership)
        # We also check for generating sources so that dependencies on `python_sources(sources=[])`
        # is included. Those won't generate any `python_source` targets, but still can be
        # dependended upon.
        or tgt.has_field(PythonGeneratingSourcesBase)
    )
Esempio n. 3
0
 def is_compatible(target: Target) -> bool:
     return (
         # Is directly applicable.
         any(fs.is_applicable(target) for fs in impl.field_sets) or
         # Is applicable via generated sources.
         any(target.has_field(g) for g in generator_sources) or
         # Is applicable via a generator.
         (isinstance(target, TargetFilesGenerator)
          and any(field in target.generated_target_cls.core_fields
                  for field in generator_sources)))
Esempio n. 4
0
def maybe_get_codegen_request_type(
        tgt: Target,
        union_membership: UnionMembership) -> GoCodegenBuildRequest | None:
    if not tgt.has_field(SourcesField):
        return None
    generate_request_types = cast(
        FrozenOrderedSet[Type[GoCodegenBuildRequest]],
        union_membership.get(GoCodegenBuildRequest))
    sources_field = tgt[SourcesField]
    relevant_requests = [
        req for req in generate_request_types
        if isinstance(sources_field, req.generate_from)
    ]
    if len(relevant_requests) > 1:
        generate_from_sources = relevant_requests[0].generate_from.__name__
        raise AmbiguousCodegenImplementationsException(
            f"Multiple registered code generators from {GoCodegenBuildRequest.__name__} can "
            f"generate from {generate_from_sources}. It is ambiguous which implementation to "
            f"use.\n\n"
            f"Possible implementations:\n\n"
            f"{bullet_list(sorted(generator.__name__ for generator in relevant_requests))}"
        )
    return relevant_requests[0](tgt) if relevant_requests else None
Esempio n. 5
0
def is_ownable_target(tgt: Target) -> bool:
    return tgt.has_field(PythonSources) or tgt.has_field(ResourcesSources)
Esempio n. 6
0
def _is_exported(target: Target) -> bool:
    return target.has_field(
        PythonProvidesField) and target[PythonProvidesField].value is not None
Esempio n. 7
0
def is_ownable_target(tgt: Target, union_membership: UnionMembership) -> bool:
    return (tgt.has_field(PythonSources) or tgt.has_field(ResourcesSources)
            or tgt.get(Sources).can_generate(PythonSources, union_membership))
Esempio n. 8
0
 def maybe_get_resolve(t: Target) -> str | None:
     if not t.has_field(PythonResolveField):
         return None
     return t[PythonResolveField].normalized_value(python_setup)
Esempio n. 9
0
def is_third_party_package_target(tgt: Target) -> bool:
    return tgt.has_field(GoExternalPackageDependencies)
Esempio n. 10
0
def is_first_party_package_target(tgt: Target) -> bool:
    return tgt.has_field(GoPackageSources)