Exemplo n.º 1
0
def test_no_compatible_resolve_error() -> None:
    python_setup = create_subsystem(PythonSetup, resolves={"a": "", "b": ""}, enable_resolves=True)
    targets = [
        PythonRequirementTarget(
            {PythonRequirementsField.alias: [], PythonResolveField.alias: "a"},
            Address("", target_name="t1"),
        ),
        PythonSourceTarget(
            {PythonSourceField.alias: "f.py", PythonResolveField.alias: "a"},
            Address("", target_name="t2"),
        ),
        PythonSourceTarget(
            {PythonSourceField.alias: "f.py", PythonResolveField.alias: "b"},
            Address("", target_name="t3"),
        ),
    ]
    assert str(NoCompatibleResolveException(python_setup, "Prefix", targets)).startswith(
        dedent(
            """\
            Prefix:

            a:
              * //:t1
              * //:t2

            b:
              * //:t3
            """
        )
    )
Exemplo n.º 2
0
def rules():
    return [
        PythonSourceTarget.register_plugin_field(SkipYapfField),
        PythonSourcesGeneratorTarget.register_plugin_field(SkipYapfField),
        PythonTestTarget.register_plugin_field(SkipYapfField),
        PythonTestsGeneratorTarget.register_plugin_field(SkipYapfField),
    ]
Exemplo n.º 3
0
def rules():
    return [
        PythonSourcesGeneratorTarget.register_plugin_field(SkipDocformatterField),
        PythonSourceTarget.register_plugin_field(SkipDocformatterField),
        PythonTestsGeneratorTarget.register_plugin_field(SkipDocformatterField),
        PythonTestTarget.register_plugin_field(SkipDocformatterField),
        PythonTestUtilsGeneratorTarget.register_plugin_field(SkipDocformatterField),
    ]
Exemplo n.º 4
0
def rules():
    return [
        PythonSourcesGeneratorTarget.register_plugin_field(SkipAutoflakeField),
        PythonSourceTarget.register_plugin_field(SkipAutoflakeField),
        PythonTestsGeneratorTarget.register_plugin_field(SkipAutoflakeField),
        PythonTestTarget.register_plugin_field(SkipAutoflakeField),
        PythonTestUtilsGeneratorTarget.register_plugin_field(
            SkipAutoflakeField),
    ]
Exemplo n.º 5
0
 def gen_source_tgt(rel_fp: str,
                    tags: list[str] | None = None,
                    *,
                    tgt_name: str) -> PythonSourceTarget:
     return PythonSourceTarget(
         {
             SingleSourceField.alias: rel_fp,
             Tags.alias: tags
         },
         Address("src/py", target_name=tgt_name, relative_file_path=rel_fp),
         residence_dir=os.path.dirname(os.path.join("src/py", rel_fp)),
     )
Exemplo n.º 6
0
def test_no_compatible_resolve_error() -> None:
    python_setup = create_subsystem(PythonSetup,
                                    resolves={
                                        "a": "",
                                        "b": ""
                                    },
                                    enable_resolves=True)
    t1 = PythonRequirementTarget(
        {
            PythonRequirementsField.alias: [],
            PythonResolveField.alias: "a",
            Dependencies.alias: ["//:t3"],
        },
        Address("", target_name="t1"),
    )
    t2 = PythonSourceTarget(
        {
            PythonSourceField.alias: "f.py",
            PythonResolveField.alias: "a",
            Dependencies.alias: ["//:t3"],
        },
        Address("", target_name="t2"),
    )
    t3 = PythonSourceTarget(
        {
            PythonSourceField.alias: "f.py",
            PythonResolveField.alias: "b"
        },
        Address("", target_name="t3"),
    )

    def maybe_get_resolve(t: Target) -> str | None:
        if not t.has_field(PythonResolveField):
            return None
        return t[PythonResolveField].normalized_value(python_setup)

    bad_roots_err = str(
        NoCompatibleResolveException.bad_input_roots(
            [t2, t3],
            maybe_get_resolve=maybe_get_resolve,
            doc_url_slug="",
            workaround=None))
    assert bad_roots_err.startswith(
        softwrap("""
            The input targets did not have a resolve in common.

            a:
              * //:t2

            b:
              * //:t3

            Targets used together must use the same resolve, set by the `resolve` field.
            """))

    bad_single_dep_err = str(
        NoCompatibleResolveException.bad_dependencies(
            maybe_get_resolve=maybe_get_resolve,
            doc_url_slug="",
            root_targets=[t1],
            root_resolve="a",
            dependencies=[t3],
        ))
    assert bad_single_dep_err.startswith(
        softwrap("""
            The target //:t1 uses the `resolve` `a`, but some of its
            dependencies are not compatible with that resolve:

              * //:t3 (b)

            All dependencies must work with the same `resolve`. To fix this, either change
            the `resolve=` field on those dependencies to `a`, or change
            the `resolve=` of the target //:t1.
            """))

    bad_multiple_deps_err = str(
        NoCompatibleResolveException.bad_dependencies(
            maybe_get_resolve=maybe_get_resolve,
            doc_url_slug="",
            root_targets=[t1, t2],
            root_resolve="a",
            dependencies=[t3],
        ))
    assert bad_multiple_deps_err.startswith(
        softwrap("""
            The input targets use the `resolve` `a`, but some of their
            dependencies are not compatible with that resolve.

            Input targets:

              * //:t1
              * //:t2

            Bad dependencies:

              * //:t3 (b)

            All dependencies must work with the same `resolve`. To fix this, either change
            the `resolve=` field on those dependencies to `a`, or change
            the `resolve=` of the input targets.
            """))