bitter-ability-32190
12/27/2021, 3:56 PMbitter-ability-32190
12/27/2021, 3:56 PMBUILDbitter-ability-32190
12/27/2021, 4:00 PMpants-plugins/bazel-compat-macros.py# Macros for Bazel defintions
def alias(*args, **kwargs): ...
def genrule(*args, **kwargs): ...
def exports_files(*args, **kwargs): ...
def load(*args, **kwargs): ...
def requirement(arg): ...
# ... you get the idea ;)
def glob(*args, **kwargs): return []
# Ones we do care about
def py_library(**kwargs):
    srcs = kwargs.get("srcs", [])
    if srcs:
        return python_sources(name=kwargs["name"], sources=srcs)
def py_test(**kwargs):
    srcs = kwargs.get("srcs", [])
    if srcs:
        return python_sources(name=kwargs["name"], sources=srcs)# In pants-compat.bzl
def python_requirements(**kwargs):
  passBUILDload("//:pants-compat.bzl", "python_requirements")
package(default_visibility = ["//visibility:public"])
# Bazel stuff
python_requirements(
    module_mapping = {
        "absl-py": ["absl"],
        # ...
    },
)bitter-ability-32190
12/27/2021, 4:01 PMbitter-ability-32190
12/27/2021, 4:02 PMcurved-television-6568
12/27/2021, 4:06 PMbitter-ability-32190
12/27/2021, 4:08 PMlintbitter-ability-32190
12/27/2021, 4:16 PMpantsbitter-ability-32190
12/27/2021, 4:18 PMcurved-television-6568
12/27/2021, 4:22 PMmaybe have a āignore-unrecognized-definitionsā optionis it too many definitions to āstubā out with macros? or are there other constructs that doesnāt map to a macro syntactically ?
bitter-ability-32190
12/27/2021, 4:25 PMglobbitter-ability-32190
12/27/2021, 4:42 PMlintbitter-ability-32190
12/27/2021, 4:44 PMpy_binarypy_testsrcs=[...]py_librarysrcspy_library:foo/barbitter-ability-32190
12/27/2021, 4:54 PMpy_binarysrcspy_binarybitter-ability-32190
12/27/2021, 5:02 PMdef py_binary(
    srcs = [],
    **kwargs
):
    for src in srcs:
        if src.endswith(".py"):
            # This is valid Bazel, but for Pants-compat to work, each src should be owned
            # once-and-only-once. And the easiest way to do that is throught `py_library`.
            fail(
                "`py_binary` cannot claim a Python src. Use `py_library` instead and depend on it.\n\n"
                + "E.g. declare:\n\n"
                + "py_library(\n"
                + '  name = "{}",\n'.format(src[:-3])
                + '  srcs = ["{}"],\n'.format(src)
                + ")\n\n"
                + 'Then set the `py_binary` `srcs` attribute to ":{}"'.format(src[:-3])
            )
    _py_binary(
        srcs=srcs,
        **kwargs,
    )