Esempio n. 1
0
def test_find_thrift_python_requirement(rule_runner: RuleRunner) -> None:
    rule_runner.write_files({"codegen/dir/f.thrift": "", "codegen/dir/BUILD": "thrift_sources()"})
    rule_runner.set_options(
        ["--python-resolves={'python-default': '', 'another': ''}", "--python-enable-resolves"]
    )
    thrift_tgt = rule_runner.get_target(Address("codegen/dir", relative_file_path="f.thrift"))
    request = InjectApacheThriftPythonDependencies(thrift_tgt[Dependencies])

    # Start with no relevant requirements.
    with engine_error(MissingPythonCodegenRuntimeLibrary):
        rule_runner.request(InjectedDependencies, [request])

    # If exactly one, match it.
    rule_runner.write_files({"reqs1/BUILD": "python_requirement(requirements=['thrift'])"})
    assert rule_runner.request(InjectedDependencies, [request]) == InjectedDependencies(
        [Address("reqs1")]
    )

    # Multiple is fine if from other resolve.
    rule_runner.write_files(
        {"another_resolve/BUILD": "python_requirement(requirements=['thrift'], resolve='another')"}
    )
    assert rule_runner.request(InjectedDependencies, [request]) == InjectedDependencies(
        [Address("reqs1")]
    )

    # If multiple from the same resolve, error.
    rule_runner.write_files({"reqs2/BUILD": "python_requirement(requirements=['thrift'])"})
    with engine_error(
        AmbiguousPythonCodegenRuntimeLibrary, contains="['reqs1:reqs1', 'reqs2:reqs2']"
    ):
        rule_runner.request(InjectedDependencies, [request])
Esempio n. 2
0
async def inject_lambda_handler_dependency(
        request: InjectPythonLambdaHandlerDependency,
        python_infer_subsystem: PythonInferSubsystem) -> InjectedDependencies:
    if not python_infer_subsystem.entry_points:
        return InjectedDependencies()
    original_tgt = await Get(WrappedTarget, Address,
                             request.dependencies_field.address)
    explicitly_provided_deps, handler = await MultiGet(
        Get(ExplicitlyProvidedDependencies,
            DependenciesRequest(original_tgt.target[Dependencies])),
        Get(
            ResolvedPythonAwsHandler,
            ResolvePythonAwsHandlerRequest(
                original_tgt.target[PythonAwsLambdaHandlerField]),
        ),
    )
    module, _, _func = handler.val.partition(":")
    owners = await Get(PythonModuleOwners, PythonModule(module))
    address = original_tgt.target.address
    explicitly_provided_deps.maybe_warn_of_ambiguous_dependency_inference(
        owners.ambiguous,
        address,
        import_reference="module",
        context=
        (f"The python_awslambda target {address} has the field "
         f"`handler={repr(original_tgt.target[PythonAwsLambdaHandlerField].value)}`, which maps "
         f"to the Python module `{module}`"),
    )
    maybe_disambiguated = explicitly_provided_deps.disambiguated_via_ignores(
        owners.ambiguous)
    unambiguous_owners = owners.unambiguous or (
        (maybe_disambiguated, ) if maybe_disambiguated else ())
    return InjectedDependencies(unambiguous_owners)
Esempio n. 3
0
async def inject_pex_binary_entry_point_dependency(
        request: InjectPexBinaryEntryPointDependency,
        python_infer_subsystem: PythonInferSubsystem) -> InjectedDependencies:
    if not python_infer_subsystem.entry_points:
        return InjectedDependencies()
    original_tgt = await Get(WrappedTarget, Address,
                             request.dependencies_field.address)
    explicitly_provided_deps, entry_point = await MultiGet(
        Get(ExplicitlyProvidedDependencies,
            DependenciesRequest(original_tgt.target[Dependencies])),
        Get(
            ResolvedPexEntryPoint,
            ResolvePexEntryPointRequest(
                original_tgt.target[PexEntryPointField]),
        ),
    )
    if entry_point.val is None:
        return InjectedDependencies()
    owners = await Get(PythonModuleOwners,
                       PythonModule(entry_point.val.module))
    address = original_tgt.target.address
    explicitly_provided_deps.maybe_warn_of_ambiguous_dependency_inference(
        owners.ambiguous,
        address,
        import_reference="module",
        context=
        (f"The pex_binary target {address} has the field "
         f"`entry_point={repr(original_tgt.target[PexEntryPointField].value.spec)}`, which "
         f"maps to the Python module `{entry_point.val.module}`"),
    )
    maybe_disambiguated = explicitly_provided_deps.disambiguated_via_ignores(
        owners.ambiguous)
    unambiguous_owners = owners.unambiguous or (
        (maybe_disambiguated, ) if maybe_disambiguated else ())
    return InjectedDependencies(unambiguous_owners)
Esempio n. 4
0
async def find_apache_thrift_python_requirement(
    request: InjectApacheThriftPythonDependencies,
    thrift_python: ThriftPythonSubsystem,
    python_setup: PythonSetup,
    # TODO(#12946): Make this a lazy Get once possible.
    module_mapping: ThirdPartyPythonModuleMapping,
) -> InjectedDependencies:
    if not thrift_python.infer_runtime_dependency:
        return InjectedDependencies()

    wrapped_tgt = await Get(
        WrappedTarget,
        WrappedTargetRequest(
            request.dependencies_field.address, description_of_origin="<infallible>"
        ),
    )
    resolve = wrapped_tgt.target.get(PythonResolveField).normalized_value(python_setup)

    addr = find_python_runtime_library_or_raise_error(
        module_mapping,
        request.dependencies_field.address,
        "thrift",
        resolve=resolve,
        resolves_enabled=python_setup.enable_resolves,
        recommended_requirement_name="thrift",
        recommended_requirement_url="https://pypi.org/project/thrift/",
        disable_inference_option=f"[{thrift_python.options_scope}].infer_runtime_dependency",
    )
    return InjectedDependencies([addr])
Esempio n. 5
0
async def inject_python_distribution_dependencies(
        request: InjectPythonDistributionDependencies,
        python_infer_subsystem: PythonInferSubsystem) -> InjectedDependencies:
    """Inject dependencies that we can infer from entry points in the distribution."""
    if not python_infer_subsystem.entry_points:
        return InjectedDependencies()

    original_tgt = await Get(WrappedTarget, Address,
                             request.dependencies_field.address)
    explicitly_provided_deps, distribution_entry_points, provides_entry_points = await MultiGet(
        Get(ExplicitlyProvidedDependencies,
            DependenciesRequest(original_tgt.target[Dependencies])),
        Get(
            ResolvedPythonDistributionEntryPoints,
            ResolvePythonDistributionEntryPointsRequest(
                entry_points_field=original_tgt.
                target[PythonDistributionEntryPointsField]),
        ),
        Get(
            ResolvedPythonDistributionEntryPoints,
            ResolvePythonDistributionEntryPointsRequest(
                provides_field=original_tgt.target[PythonProvidesField]),
        ),
    )

    address = original_tgt.target.address
    all_module_entry_points = [
        (category, name, entry_point) for category, entry_points in chain(
            distribution_entry_points.explicit_modules.items(),
            provides_entry_points.explicit_modules.items(),
        ) for name, entry_point in entry_points.items()
    ]
    all_module_owners = iter(await MultiGet(
        Get(PythonModuleOwners,
            PythonModuleOwnersRequest(entry_point.module, resolve=None))
        for _, _, entry_point in all_module_entry_points))
    module_owners: OrderedSet[Address] = OrderedSet()
    for (category, name, entry_point), owners in zip(all_module_entry_points,
                                                     all_module_owners):
        field_str = repr({category: {name: entry_point.spec}})
        explicitly_provided_deps.maybe_warn_of_ambiguous_dependency_inference(
            owners.ambiguous,
            address,
            import_reference="module",
            context=(
                f"The python_distribution target {address} has the field "
                f"`entry_points={field_str}`, which maps to the Python module"
                f"`{entry_point.module}`"),
        )
        maybe_disambiguated = explicitly_provided_deps.disambiguated(
            owners.ambiguous)
        unambiguous_owners = owners.unambiguous or (
            (maybe_disambiguated, ) if maybe_disambiguated else ())
        module_owners.update(unambiguous_owners)

    return InjectedDependencies(
        Addresses(module_owners) +
        distribution_entry_points.pex_binary_addresses +
        provides_entry_points.pex_binary_addresses)
Esempio n. 6
0
async def inject_go_package_dependencies(
    request: InjectGoPackageDependenciesRequest, ) -> InjectedDependencies:
    owning_go_module_result = await Get(
        ResolvedOwningGoModule,
        FindNearestGoModuleRequest(
            request.dependencies_field.address.spec_path),
    )
    if owning_go_module_result.module_address:
        return InjectedDependencies([owning_go_module_result.module_address])
    else:
        return InjectedDependencies()
Esempio n. 7
0
async def inject_pex_binary_entry_point_dependency(
    request: InjectPexBinaryEntryPointDependency,
    python_infer_subsystem: PythonInferSubsystem,
    python_setup: PythonSetup,
) -> InjectedDependencies:
    if not python_infer_subsystem.entry_points:
        return InjectedDependencies()
    original_tgt = await Get(
        WrappedTarget,
        WrappedTargetRequest(
            request.dependencies_field.address, description_of_origin="<infallible>"
        ),
    )
    entry_point_field = original_tgt.target.get(PexEntryPointField)
    if entry_point_field.value is None:
        return InjectedDependencies()

    explicitly_provided_deps, entry_point = await MultiGet(
        Get(ExplicitlyProvidedDependencies, DependenciesRequest(original_tgt.target[Dependencies])),
        Get(ResolvedPexEntryPoint, ResolvePexEntryPointRequest(entry_point_field)),
    )
    if entry_point.val is None:
        return InjectedDependencies()

    owners = await Get(
        PythonModuleOwners,
        PythonModuleOwnersRequest(
            entry_point.val.module,
            resolve=original_tgt.target[PythonResolveField].normalized_value(python_setup),
        ),
    )
    address = original_tgt.target.address
    explicitly_provided_deps.maybe_warn_of_ambiguous_dependency_inference(
        owners.ambiguous,
        address,
        # If the entry point was specified as a file, like `app.py`, we know the module must
        # live in the pex_binary's directory or subdirectory, so the owners must be ancestors.
        owners_must_be_ancestors=entry_point.file_name_used,
        import_reference="module",
        context=softwrap(
            f"""
            The pex_binary target {address} has the field
            `entry_point={repr(entry_point_field.value.spec)}`, which
            maps to the Python module `{entry_point.val.module}`
            """
        ),
    )
    maybe_disambiguated = explicitly_provided_deps.disambiguated(
        owners.ambiguous, owners_must_be_ancestors=entry_point.file_name_used
    )
    unambiguous_owners = owners.unambiguous or (
        (maybe_disambiguated,) if maybe_disambiguated else ()
    )
    return InjectedDependencies(unambiguous_owners)
Esempio n. 8
0
async def inject_lambda_handler_dependency(
    request: InjectPythonLambdaHandlerDependency, python_infer_subsystem: PythonInferSubsystem
) -> InjectedDependencies:
    if not python_infer_subsystem.entry_points:
        return InjectedDependencies()
    original_tgt = await Get(WrappedTarget, Address, request.dependencies_field.address)
    handler = await Get(
        ResolvedPythonAwsHandler,
        ResolvePythonAwsHandlerRequest(original_tgt.target[PythonAwsLambdaHandlerField]),
    )
    module, _, _func = handler.val.partition(":")
    owners = await Get(PythonModuleOwners, PythonModule(module))
    return InjectedDependencies(owners)
Esempio n. 9
0
async def inject_lambda_handler_dependency(
    request: InjectPythonLambdaHandlerDependency,
    python_infer_subsystem: PythonInferSubsystem,
    python_setup: PythonSetup,
) -> InjectedDependencies:
    if not python_infer_subsystem.entry_points:
        return InjectedDependencies()
    original_tgt = await Get(
        WrappedTarget,
        WrappedTargetRequest(
            request.dependencies_field.address, description_of_origin="<infallible>"
        ),
    )
    explicitly_provided_deps, handler = await MultiGet(
        Get(ExplicitlyProvidedDependencies, DependenciesRequest(original_tgt.target[Dependencies])),
        Get(
            ResolvedPythonAwsHandler,
            ResolvePythonAwsHandlerRequest(original_tgt.target[PythonAwsLambdaHandlerField]),
        ),
    )
    module, _, _func = handler.val.partition(":")
    owners = await Get(
        PythonModuleOwners,
        PythonModuleOwnersRequest(
            module, resolve=original_tgt.target[PythonResolveField].normalized_value(python_setup)
        ),
    )
    address = original_tgt.target.address
    explicitly_provided_deps.maybe_warn_of_ambiguous_dependency_inference(
        owners.ambiguous,
        address,
        # If the handler was specified as a file, like `app.py`, we know the module must
        # live in the python_awslambda's directory or subdirectory, so the owners must be ancestors.
        owners_must_be_ancestors=handler.file_name_used,
        import_reference="module",
        context=softwrap(
            f"""
            The python_awslambda target {address} has the field
            `handler={repr(original_tgt.target[PythonAwsLambdaHandlerField].value)}`,
            which maps to the Python module `{module}`"
            """
        ),
    )
    maybe_disambiguated = explicitly_provided_deps.disambiguated(
        owners.ambiguous, owners_must_be_ancestors=handler.file_name_used
    )
    unambiguous_owners = owners.unambiguous or (
        (maybe_disambiguated,) if maybe_disambiguated else ()
    )
    return InjectedDependencies(unambiguous_owners)
Esempio n. 10
0
async def inject_pex_binary_entry_point_dependency(
    request: InjectPexBinaryEntryPointDependency, python_infer_subsystem: PythonInferSubsystem
) -> InjectedDependencies:
    if not python_infer_subsystem.entry_points:
        return InjectedDependencies()
    original_tgt = await Get(WrappedTarget, Address, request.dependencies_field.address)
    entry_point = await Get(
        ResolvedPexEntryPoint,
        ResolvePexEntryPointRequest(original_tgt.target[PexEntryPointField]),
    )
    if entry_point.val is None:
        return InjectedDependencies()
    module, _, _func = entry_point.val.partition(":")
    owners = await Get(PythonModuleOwners, PythonModule(module))
    return InjectedDependencies(owners)
Esempio n. 11
0
async def inject_scala_library_dependency(
    request: InjectScalaLibraryDependencyRequest,
    jvm: JvmSubsystem,
) -> InjectedDependencies:
    wrapped_target = await Get(WrappedTarget, Address, request.dependencies_field.address)
    target = wrapped_target.target

    if not target.has_field(JvmResolveField):
        return InjectedDependencies()
    resolve = target[JvmResolveField].normalized_value(jvm)

    scala_library_target_info = await Get(
        ScalaRuntimeForResolve, ScalaRuntimeForResolveRequest(resolve)
    )
    return InjectedDependencies((scala_library_target_info.address,))
Esempio n. 12
0
async def inject_dependencies(
    request: InjectPythonProtobufDependencies,
    python_protobuf: PythonProtobufSubsystem,
    python_setup: PythonSetup,
    # TODO(#12946): Make this a lazy Get once possible.
    module_mapping: ThirdPartyPythonModuleMapping,
) -> InjectedDependencies:
    if not python_protobuf.infer_runtime_dependency:
        return InjectedDependencies()

    wrapped_tgt = await Get(
        WrappedTarget,
        WrappedTargetRequest(request.dependencies_field.address,
                             description_of_origin="<infallible>"),
    )
    tgt = wrapped_tgt.target
    resolve = tgt.get(PythonResolveField).normalized_value(python_setup)

    result = [
        find_python_runtime_library_or_raise_error(
            module_mapping,
            request.dependencies_field.address,
            "google.protobuf",
            resolve=resolve,
            resolves_enabled=python_setup.enable_resolves,
            recommended_requirement_name="protobuf",
            recommended_requirement_url="https://pypi.org/project/protobuf/",
            disable_inference_option=
            f"[{python_protobuf.options_scope}].infer_runtime_dependency",
        )
    ]

    if tgt.get(ProtobufGrpcToggleField).value:
        result.append(
            find_python_runtime_library_or_raise_error(
                module_mapping,
                request.dependencies_field.address,
                # Note that the library is called `grpcio`, but the module is `grpc`.
                "grpc",
                resolve=resolve,
                resolves_enabled=python_setup.enable_resolves,
                recommended_requirement_name="grpcio",
                recommended_requirement_url="https://pypi.org/project/grpcio/",
                disable_inference_option=
                f"[{python_protobuf.options_scope}].infer_runtime_dependency",
            ))

    return InjectedDependencies(result)
Esempio n. 13
0
 def assert_injected(address: Address, expected: list[Address]) -> None:
     tgt = rule_runner.get_target(address)
     injected = rule_runner.request(
         InjectedDependencies,
         [InjectPythonDistributionDependencies(tgt[PythonDistributionDependenciesField])],
     )
     assert injected == InjectedDependencies(expected)
Esempio n. 14
0
 def assert_injected(addr: Address) -> None:
     tgt = rule_runner.get_target(addr)
     injected = rule_runner.request(
         InjectedDependencies,
         [InjectPythonProtobufDependencies(tgt[ProtobufDependenciesField])])
     assert injected == InjectedDependencies(
         [Address("protos", target_name="injected_dep")])
Esempio n. 15
0
 def assert_injected(address: Address, *, expected: Address | None) -> None:
     tgt = rule_runner.get_target(address)
     injected = rule_runner.request(
         InjectedDependencies,
         [InjectPexBinaryEntryPointDependency(tgt[PexBinaryDependenciesField])],
     )
     assert injected == InjectedDependencies([expected] if expected else [])
Esempio n. 16
0
async def inject_dependencies(_: InjectProtobufDependencies,
                              protoc: Protoc) -> InjectedDependencies:
    addresses = await Get(
        Addresses,
        UnparsedAddressInputs((v for v in protoc.runtime_targets),
                              owning_address=None))
    return InjectedDependencies(addresses)
Esempio n. 17
0
async def inject_docker_dependencies(request: InjectDockerDependencies) -> InjectedDependencies:
    """Inspects COPY instructions in the Dockerfile for references to known packagable targets."""
    dockerfile_info = await Get(
        DockerfileInfo, DockerfileInfoRequest(request.dependencies_field.address)
    )

    # Parse all putative target addresses.
    putative_addresses = await Get(
        Addresses,
        UnparsedAddressInputs(
            dockerfile_info.putative_target_addresses,
            owning_address=dockerfile_info.address,
        ),
    )

    # Get the target for those addresses that are known.
    directories = {address.spec_path for address in putative_addresses}
    all_addresses = await Get(Addresses, AddressSpecs(map(MaybeEmptySiblingAddresses, directories)))
    targets = await Get(
        Targets, Addresses((address for address in putative_addresses if address in all_addresses))
    )

    # Only keep those targets that we can "package".
    package = await Get(FieldSetsPerTarget, FieldSetsPerTargetRequest(PackageFieldSet, targets))
    referenced_targets = (
        field_sets[0].address for field_sets in package.collection if len(field_sets) > 0
    )
    return InjectedDependencies(Addresses(referenced_targets))
Esempio n. 18
0
def test_inject_dependencies() -> None:
    rule_runner = RuleRunner(
        rules=[
            *target_type_rules(),
            QueryRule(InjectedDependencies, (InjectProtobufDependencies, )),
        ],
        target_types=[ProtobufLibrary, Files],
    )
    rule_runner.set_options([
        "--backend-packages=pants.backend.codegen.protobuf.python",
        "--protoc-runtime-targets=protos:injected_dep",
    ])
    # Note that injected deps can be any target type for `--protobuf-runtime-targets`.
    rule_runner.add_to_build_file(
        "protos",
        dedent("""\
            protobuf_library()
            files(name="injected_dep", sources=[])
            """),
    )
    tgt = rule_runner.get_target(Address("protos"))
    injected = rule_runner.request(
        InjectedDependencies,
        [InjectProtobufDependencies(tgt[ProtobufDependencies])])
    assert injected == InjectedDependencies(
        [Address("protos", target_name="injected_dep")])
Esempio n. 19
0
def test_inject_docker_dependencies(rule_runner: RuleRunner) -> None:
    rule_runner.add_to_build_file(
        "project/image/test",
        dedent("""\
            docker_image(name="image")
            """),
    )
    rule_runner.create_file(
        "project/image/test/Dockerfile",
        dedent("""\
            FROM baseimage
            ENTRYPOINT ["./entrypoint"]
            COPY project.hello.main/main_binary.pex /entrypoint
            """),
    )
    rule_runner.add_to_build_file(
        "project/hello/main",
        dedent("""\
            pex_binary(name="main_binary")
            """),
    )
    tgt = rule_runner.get_target(
        Address("project/image/test", target_name="image"))
    injected = rule_runner.request(
        InjectedDependencies,
        [InjectDockerDependencies(tgt[DockerDependencies])],
    )
    assert injected == InjectedDependencies(
        [Address("project/hello/main", target_name="main_binary")])
Esempio n. 20
0
def test_inject_docker_dependencies(rule_runner: RuleRunner) -> None:
    rule_runner.write_files({
        "project/image/test/BUILD":
        dedent("""\
                docker_image(name="base")
                docker_image(name="image")
                """),
        "project/image/test/Dockerfile":
        dedent("""\
                ARG BASE_IMAGE=:base
                FROM $BASE_IMAGE
                ENTRYPOINT ["./entrypoint"]
                COPY project.hello.main/main_binary.pex /entrypoint
                """),
        "project/hello/main/BUILD":
        dedent("""\
                pex_binary(name="main_binary")
                """),
    })
    tgt = rule_runner.get_target(
        Address("project/image/test", target_name="image"))
    injected = rule_runner.request(
        InjectedDependencies,
        [InjectDockerDependencies(tgt[DockerImageDependenciesField])],
    )
    assert injected == InjectedDependencies([
        Address("project/hello/main", target_name="main_binary"),
        Address("project/image/test", target_name="base"),
    ])
Esempio n. 21
0
async def inject_go_external_package_dependencies(
    request: InjectGoExternalPackageDependenciesRequest,
    std_lib_imports: GoStdLibImports,
    package_mapping: GoImportPathToPackageMapping,
) -> InjectedDependencies:
    this_go_package = await Get(
        ResolvedGoPackage,
        ResolveExternalGoPackageRequest(request.dependencies_field.address))

    # Loop through all of the imports of this package and add dependencies on other packages and
    # external modules.
    inferred_dependencies = []
    for import_path in this_go_package.imports + this_go_package.test_imports:
        if import_path in std_lib_imports:
            continue

        # Infer third-party dependencies on _go_external_package targets.
        candidate_third_party_packages = package_mapping.mapping.get(
            import_path, ())
        if len(candidate_third_party_packages) > 1:
            # TODO: Use ExplicitlyProvidedDependencies.maybe_warn_of_ambiguous_dependency_inference standard
            # way of doing disambiguation.
            logger.warning(
                f"Ambiguous mapping for import path {import_path} on packages at addresses: {candidate_third_party_packages}"
            )
        elif len(candidate_third_party_packages) == 1:
            inferred_dependencies.append(candidate_third_party_packages[0])
        else:
            logger.debug(
                f"Unable to infer dependency for import path '{import_path}' "
                f"in go_external_package at address '{this_go_package.address}'."
            )

    return InjectedDependencies(inferred_dependencies)
Esempio n. 22
0
def test_python_distribution_dependency_injection() -> None:
    rule_runner = RuleRunner(
        rules=[
            *target_type_rules(),
            QueryRule(
                InjectedDependencies,
                (InjectPythonDistributionDependencies, ),
            ),
        ],
        target_types=[PythonDistribution, PexBinary],
        objects={"setup_py": PythonArtifact},
    )
    rule_runner.add_to_build_file(
        "project",
        dedent("""\
            pex_binary(name="my_binary")
            python_distribution(
                name="dist",
                provides=setup_py(
                    name='my-dist'
                ).with_binaries({"my_cmd": ":my_binary"})
            )
            """),
    )
    tgt = rule_runner.get_target(Address("project", target_name="dist"))
    injected = rule_runner.request(
        InjectedDependencies,
        [
            InjectPythonDistributionDependencies(
                tgt[PythonDistributionDependencies])
        ],
    )
    assert injected == InjectedDependencies(
        [Address("project", target_name="my_binary")])
Esempio n. 23
0
 def assert_injected(address: Address, *, expected: Optional[Address]) -> None:
     tgt = rule_runner.get_target(address)
     injected = rule_runner.request(
         InjectedDependencies,
         [InjectPythonLambdaHandlerDependency(tgt[PythonAwsLambdaDependencies])],
     )
     assert injected == InjectedDependencies([expected] if expected else [])
Esempio n. 24
0
async def inject_apache_thrift_java_dependencies(
        request: InjectApacheThriftJavaDependencies,
        jvm: JvmSubsystem) -> InjectedDependencies:
    wrapped_target = await Get(
        WrappedTarget,
        WrappedTargetRequest(request.dependencies_field.address,
                             description_of_origin="<infallible>"),
    )
    target = wrapped_target.target

    if not target.has_field(JvmResolveField):
        return InjectedDependencies()
    resolve = target[JvmResolveField].normalized_value(jvm)

    dependencies_info = await Get(
        ApacheThriftJavaRuntimeForResolve,
        ApacheThriftJavaRuntimeForResolveRequest(resolve))
    return InjectedDependencies(dependencies_info.addresses)
Esempio n. 25
0
async def inject_dependencies(
    request: InjectPythonDistributionDependencies, ) -> InjectedDependencies:
    """Inject any `.with_binaries()` values, as it would be redundant to have to include in the
    `dependencies` field."""
    original_tgt = await Get(WrappedTarget, Address,
                             request.dependencies_field.address)
    with_binaries = original_tgt.target[PythonProvidesField].value.binaries
    if not with_binaries:
        return InjectedDependencies()
    # Note that we don't validate that these are all `pex_binary` targets; we don't care about
    # that here. `setup_py.py` will do that validation.
    addresses = await Get(
        Addresses,
        UnparsedAddressInputs(
            with_binaries.values(),
            owning_address=request.dependencies_field.address),
    )
    return InjectedDependencies(addresses)
Esempio n. 26
0
async def inject_scalapb_runtime_dependency(
    request: InjectScalaPBRuntimeDependencyRequest,
    jvm: JvmSubsystem,
) -> InjectedDependencies:
    wrapped_target = await Get(
        WrappedTarget,
        WrappedTargetRequest(request.dependencies_field.address,
                             description_of_origin="<infallible>"),
    )
    target = wrapped_target.target

    if not target.has_field(JvmResolveField):
        return InjectedDependencies()
    resolve = target[JvmResolveField].normalized_value(jvm)

    scalapb_runtime_target_info = await Get(
        ScalaPBRuntimeForResolve, ScalaPBRuntimeForResolveRequest(resolve))
    return InjectedDependencies(scalapb_runtime_target_info.addresses)
Esempio n. 27
0
async def inject_scala_plugin_dependencies(
    request: InjectScalaPluginDependenciesRequest,
) -> InjectedDependencies:
    """Adds dependencies on plugins for scala source files, so that they get included in the
    target's resolve."""

    wrapped_target = await Get(WrappedTarget, Address, request.dependencies_field.address)
    target = wrapped_target.target

    if not target.has_field(JvmResolveField):
        return InjectedDependencies()

    scala_plugins = await Get(
        ScalaPluginTargetsForTarget, ScalaPluginsForTargetWithoutResolveRequest(target)
    )

    plugin_addresses = [target.address for target in scala_plugins.artifacts]

    return InjectedDependencies(plugin_addresses)
Esempio n. 28
0
async def inject_go_binary_main_dependency(
    request: InjectGoBinaryMainDependencyRequest, ) -> InjectedDependencies:
    wrapped_tgt = await Get(WrappedTarget, Address,
                            request.dependencies_field.address)
    main_pkg = await Get(
        GoBinaryMainPackage,
        GoBinaryMainPackageRequest(
            wrapped_tgt.target[GoBinaryMainPackageField]),
    )
    return InjectedDependencies([main_pkg.address])
Esempio n. 29
0
async def inject_kotlin_junit_dependency(
    request: InjectKotlinJunitTestDependencyRequest,
    jvm: JvmSubsystem,
) -> InjectedDependencies:
    wrapped_target = await Get(
        WrappedTarget,
        WrappedTargetRequest(request.dependencies_field.address,
                             description_of_origin="<infallible>"),
    )
    target = wrapped_target.target

    if not target.has_field(JvmResolveField):
        return InjectedDependencies()
    resolve = target[JvmResolveField].normalized_value(jvm)

    kotlin_junit_libraries = await Get(
        KotlinJunitLibrariesForResolve,
        KotlinJunitLibrariesForResolveRequest(resolve))
    return InjectedDependencies(kotlin_junit_libraries.addresses)
Esempio n. 30
0
async def inject_pex_binary_entry_point_dependency(
        request: InjectPexBinaryEntryPointDependency,
        python_infer_subsystem: PythonInferSubsystem) -> InjectedDependencies:
    if not python_infer_subsystem.entry_points:
        return InjectedDependencies()
    original_tgt = await Get(WrappedTarget, Address,
                             request.dependencies_field.address)
    entry_point = await Get(
        ResolvedPexEntryPoint,
        ResolvePexEntryPointRequest(
            original_tgt.target[PexEntryPointField],
            original_tgt.target[DeprecatedPexBinarySources]),
    )
    if entry_point.val is None:
        return InjectedDependencies()
    module, _, _func = entry_point.val.partition(":")
    owners = await Get(PythonModuleOwners, PythonModule(module))
    # TODO: remove the check for == self once the `sources` field is removed.
    return InjectedDependencies(owner for owner in owners
                                if owner != request.dependencies_field.address)