Exemplo n.º 1
0
def rules():
    return (
        *collect_rules(),
        *lockfile.rules(),
        *pex.rules(),
        UnionRule(GenerateToolLockfileSentinel,
                  DockerfileParserLockfileSentinel),
    )
Exemplo n.º 2
0
 def rules(cls):
     return (
         *super().rules(),
         generate_smalltalk_from_avro,
         RootRule(GenerateSmalltalkFromAvroRequest),
         RootRule(HydrateSourcesRequest),
         UnionRule(GenerateSourcesRequest, GenerateSmalltalkFromAvroRequest),
     )
Exemplo n.º 3
0
def rules():
    return [
        infer_java_dependencies_via_imports,
        *import_parser.rules(),
        *package_mapper.rules(),
        SubsystemRule(JavaInferSubsystem),
        UnionRule(InferDependenciesRequest, InferJavaImportDependencies),
    ]
Exemplo n.º 4
0
def test_register_union_rules(bc_builder: BuildConfiguration.Builder) -> None:
    @union
    class Base:
        pass

    class A:
        pass

    class B:
        pass

    union_a = UnionRule(Base, A)
    union_b = UnionRule(Base, B)
    bc_builder.register_rules([union_a])
    bc_builder.register_rules([union_b])
    assert bc_builder.create().union_rules == FrozenOrderedSet(
        [union_a, union_b])
Exemplo n.º 5
0
def rules():
    return [
        *collect_rules(),
        UnionRule(DistBuildEnvironmentRequest,
                  MyPycDistBuildEnvironmentRequest),
        PythonDistribution.register_plugin_field(UsesMyPycField),
        *pex_from_targets.rules(),
    ]
Exemplo n.º 6
0
def rules():
    return [
        *collect_rules(),
        UnionRule(LintRequest, Flake8Request),
        *determine_source_files.rules(),
        *pex.rules(),
        *strip_source_roots.rules(),
    ]
Exemplo n.º 7
0
 def rules(cls):
     return (
         *super().rules(),
         generate_fortran_from_avro,
         RootRule(GenerateFortranFromAvroRequest),
         RootRule(HydrateSourcesRequest),
         UnionRule(GenerateSourcesRequest, GenerateFortranFromAvroRequest),
     )
Exemplo n.º 8
0
def rules():
    return [
        *collect_rules(),
        UnionRule(TypecheckRequest, MyPyRequest),
        *extract_pex.rules(),
        *pants_bin.rules(),
        *pex_from_targets.rules(),
    ]
Exemplo n.º 9
0
def rules():
    return [
        *collect_rules(),
        *artifact_mapper.rules(),
        *scala_parser.rules(),
        *symbol_mapper.rules(),
        UnionRule(InferDependenciesRequest, InferScalaSourceDependencies),
    ]
Exemplo n.º 10
0
def rules():
    return [
        *collect_rules(),
        UnionRule(LintRequest, Flake8Request),
        *pex.rules(),
        *source_files.rules(),
        *stripped_source_files.rules(),
    ]
Exemplo n.º 11
0
def rules():
    return [
        *collect_rules(),
        *external_tool.rules(),
        *tool_rules(),
        UnionRule(LintRequest, ValidateRequest),
        SubsystemRule(TerraformValidateSubsystem),
    ]
Exemplo n.º 12
0
def test_setup_plugins_and_runtime_package_dependency(
        rule_runner: RuleRunner) -> None:
    # We test both the generic `PytestPluginSetup` mechanism and our `runtime_package_dependencies`
    # feature in the same test to confirm multiple plugins can be used on the same target.
    rule_runner = RuleRunner(
        rules=[
            *rule_runner.rules,
            used_plugin,
            unused_plugin,
            UnionRule(PytestPluginSetupRequest, UsedPlugin),
            UnionRule(PytestPluginSetupRequest, UnusedPlugin),
        ],
        target_types=rule_runner.target_types,
    )
    rule_runner.write_files({
        f"{PACKAGE}/say_hello.py":
        "print('Hello, test!')",
        f"{PACKAGE}/test_binary_call.py":
        dedent(f"""\
                import os.path
                import subprocess

                def test_embedded_binary():
                    assert os.path.exists("bin.pex")
                    assert b"Hello, test!" in subprocess.check_output(args=['./bin.pex'])

                    # Ensure that we didn't accidentally pull in the binary's sources. This is a
                    # special type of dependency that should not be included with the rest of the
                    # normal dependencies.
                    assert not os.path.exists("{PACKAGE}/say_hello.py")

                def test_additional_plugins():
                    assert os.path.exists("used.txt")
                    assert not os.path.exists("unused.txt")
                """),
        f"{PACKAGE}/BUILD":
        dedent("""\
                python_sources(name='bin_lib', sources=['say_hello.py'])
                pex_binary(name='bin', entry_point='say_hello.py', output_path="bin.pex")
                python_tests(runtime_package_dependencies=[':bin'])
                """),
    })
    tgt = rule_runner.get_target(
        Address(PACKAGE, relative_file_path="test_binary_call.py"))
    result = run_pytest(rule_runner, tgt)
    assert result.exit_code == 0
Exemplo n.º 13
0
def address_specs_rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            generate_mock_generated_target,
            UnionRule(GenerateTargetsRequest, MockGenerateTargetsRequest),
            QueryRule(Addresses, [AddressSpecs]),
        ],
        target_types=[MockTgt, MockGeneratedTarget, MockTargetGenerator],
    )
Exemplo n.º 14
0
def rules():
    return [
        *collect_rules(),
        *pex.rules(),
        UnionRule(GenerateSourcesRequest, GenerateJavaFromProtobufRequest),
        ProtobufSourceTarget.register_plugin_field(PrefixedJvmJdkField),
        ProtobufSourcesGeneratorTarget.register_plugin_field(
            PrefixedJvmJdkField),
    ]
Exemplo n.º 15
0
def rules():
    return [
        *collect_rules(),
        *lockfile.rules(),
        *export_codegen_goal.rules(),
        *dependency_inference.rules(),
        UnionRule(GenerateSourcesRequest, GenerateScalaFromProtobufRequest),
        UnionRule(GenerateToolLockfileSentinel, ScalapbcToolLockfileSentinel),
        ProtobufSourceTarget.register_plugin_field(PrefixedJvmJdkField),
        ProtobufSourcesGeneratorTarget.register_plugin_field(
            PrefixedJvmJdkField),
        ProtobufSourceTarget.register_plugin_field(PrefixedJvmResolveField),
        ProtobufSourcesGeneratorTarget.register_plugin_field(
            PrefixedJvmResolveField),
        # Rules to avoid rule graph errors.
        *artifact_mapper.rules(),
        *distdir.rules(),
    ]
Exemplo n.º 16
0
def rules():
    return [
        *collect_rules(),
        UnionRule(AWSLambdaFieldSet, PythonAwsLambdaFieldSet),
        *python_sources.rules(),
        *pex.rules(),
        *pex_from_targets.rules(),
        *strip_source_roots.rules(),
    ]
Exemplo n.º 17
0
def rules():
    return [
        run_python_test,
        debug_python_test,
        setup_pytest_for_target,
        UnionRule(TestFieldSet, PythonTestFieldSet),
        SubsystemRule(PyTest),
        SubsystemRule(PythonSetup),
    ]
Exemplo n.º 18
0
def rules():
    return [
        run_python_test,
        debug_python_test,
        setup_pytest_for_target,
        UnionRule(TestConfiguration, PythonTestConfiguration),
        subsystem_rule(PyTest),
        subsystem_rule(PythonSetup),
    ]
Exemplo n.º 19
0
def rules():
    return [
        *collect_rules(),
        *artifact_mapper.rules(),
        *java_parser_rules(),
        *symbol_mapper.rules(),
        *source_files_rules(),
        UnionRule(InferDependenciesRequest, InferJavaSourceDependencies),
    ]
Exemplo n.º 20
0
def rules():
    return (
        *collect_rules(),
        UnionRule(UvicornServerSetupRequest, GraphQLUvicornServerSetupRequest),
        # Root query data rules for graphql.
        QueryRule(AllUnexpandedTargets, ()),
        QueryRule(TargetDatas, (UnexpandedTargets,)),
        QueryRule(UnexpandedTargets, (Specs,)),
    )
Exemplo n.º 21
0
def rules():
    return [
        *collect_rules(),
        UnionRule(LintRequest, PylintRequest),
        *source_files.rules(),
        *pex.rules(),
        *python_sources.rules(),
        *stripped_source_files.rules(),
    ]
Exemplo n.º 22
0
def rules():
    return (
        *collect_rules(),
        UnionRule(GenerateSourcesRequest, GenerateGoFromProtobufRequest),
        UnionRule(GoCodegenBuildRequest, GoCodegenBuildProtobufRequest),
        UnionRule(InferDependenciesRequest,
                  InferGoProtobufDependenciesRequest),
        # Rules needed for this to pass src/python/pants/init/load_backends_integration_test.py:
        *assembly.rules(),
        *build_pkg.rules(),
        *build_pkg_target.rules(),
        *first_party_pkg.rules(),
        *go_mod.rules(),
        *link.rules(),
        *sdk.rules(),
        *target_type_rules.rules(),
        *third_party_pkg.rules(),
        *pex.rules(),
    )
Exemplo n.º 23
0
def rules():
    return [
        *collect_rules(),
        UnionRule(TypecheckRequest, MyPyRequest),
        *source_files.rules(),
        *pants_bin.rules(),
        *pex_rules(),
        *python_sources_rules(),
        *stripped_source_files.rules(),
    ]
Exemplo n.º 24
0
def rules():
    return [
        create_coverage_config,
        generate_coverage_report,
        merge_coverage_data,
        setup_coverage,
        subsystem_rule(PytestCoverage),
        UnionRule(CoverageDataCollection, PytestCoverageDataCollection),
        RootRule(CoverageConfigRequest),
    ]
Exemplo n.º 25
0
def import_rules():
    return [
        infer_python_dependencies_via_imports,
        *pex.rules(),
        *import_parser.rules(),
        *module_mapper.rules(),
        *stripped_source_files.rules(),
        SubsystemRule(PythonInferSubsystem),
        SubsystemRule(PythonSetup),
        UnionRule(InferDependenciesRequest, InferPythonImportDependencies),
    ]
Exemplo n.º 26
0
 def rules(cls):
     return super().rules() + [
         RootRule(A),
         # B is both a RootRule and an intermediate product here.
         RootRule(B),
         RootRule(C),
         RootRule(UnionX),
         error_msg_test_rule,
         consumes_a_and_b,
         transitive_b_c,
         transitive_coroutine_rule,
         RootRule(UnionWrapper),
         UnionRule(UnionBase, UnionA),
         UnionRule(UnionWithNonMemberErrorMsg, UnionWrapper),
         RootRule(UnionA),
         select_union_a,
         UnionRule(union_base=UnionBase, union_member=UnionB),
         RootRule(UnionB),
         select_union_b,
         a_union_test,
     ]
Exemplo n.º 27
0
def rules():
    return [
        flake8_lint,
        SubsystemRule(Flake8),
        UnionRule(LinterFieldSets, Flake8FieldSets),
        *download_pex_bin.rules(),
        *determine_source_files.rules(),
        *pex.rules(),
        *python_native_code.rules(),
        *strip_source_roots.rules(),
        *subprocess_environment.rules(),
    ]
Exemplo n.º 28
0
def rules():
    return [
        bandit_lint,
        subsystem_rule(Bandit),
        UnionRule(LinterConfigurations, BanditConfigurations),
        *download_pex_bin.rules(),
        *determine_source_files.rules(),
        *pex.rules(),
        *python_native_code.rules(),
        *strip_source_roots.rules(),
        *subprocess_environment.rules(),
    ]
Exemplo n.º 29
0
def test_union_rules() -> None:
    rule_runner = RuleRunner(rules=[
        car_num_wheels,
        motorcycle_num_wheels,
        UnionRule(Vehicle, Car),
        UnionRule(Vehicle, Motorcycle),
        generic_num_wheels,
        QueryRule(int, [WrappedVehicle]),
    ], )
    assert rule_runner.request(int, [WrappedVehicle(Car())]) == 4
    assert rule_runner.request(int, [WrappedVehicle(Motorcycle())]) == 2

    # Fails due to no union relationship between Vehicle -> str.
    with pytest.raises(ExecutionError) as exc:
        rule_runner.request(
            int, [WrappedVehicle("not a vehicle")])  # type: ignore[arg-type]
    assert (
        "Invalid Get. Because the second argument to `Get(int, Vehicle, not a vehicle)` is "
        "annotated with `@union`, the third argument should be a member of that union. Did you "
        "intend to register `UnionRule(Vehicle, str)`?") in str(
            exc.value.args[0])
Exemplo n.º 30
0
 def rules(cls):
     return (
         *super().rules(),
         consumes_a_and_b,
         QueryRule(str, (A, B)),
         transitive_b_c,
         QueryRule(str, (A, C)),
         transitive_coroutine_rule,
         QueryRule(D, (C,)),
         UnionRule(UnionBase, UnionA),
         UnionRule(UnionWithNonMemberErrorMsg, UnionWrapper),
         select_union_a,
         UnionRule(union_base=UnionBase, union_member=UnionB),
         select_union_b,
         a_union_test,
         QueryRule(A, (UnionWrapper,)),
         error_msg_test_rule,
         QueryRule(UnionX, (UnionWrapper,)),
         boolean_and_int,
         QueryRule(A, (int, bool)),
     )