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))
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) )
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)))
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
def is_ownable_target(tgt: Target) -> bool: return tgt.has_field(PythonSources) or tgt.has_field(ResourcesSources)
def _is_exported(target: Target) -> bool: return target.has_field( PythonProvidesField) and target[PythonProvidesField].value is not None
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))
def maybe_get_resolve(t: Target) -> str | None: if not t.has_field(PythonResolveField): return None return t[PythonResolveField].normalized_value(python_setup)
def is_third_party_package_target(tgt: Target) -> bool: return tgt.has_field(GoExternalPackageDependencies)
def is_first_party_package_target(tgt: Target) -> bool: return tgt.has_field(GoPackageSources)