packages feed

cabal-buck2-0.6.0.0: buck2/prelude/decls/python_common.bzl

# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is dual-licensed under either the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree or the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree. You may select, at your option, one of the
# above-listed licenses.

# TODO(cjhopman): This was generated by scripts/hacks/rules_shim_with_docs.py,
# but should be manually edited going forward. There may be some errors in
# the generated docs, and so those should be verified to be accurate and
# well-formatted (and then delete this TODO)

PythonBuckConfigPackageStyle = ["standalone", "inplace", "outplace"]

def _srcs_arg():
    return {
        "srcs": attrs.named_set(
            attrs.source(),
            sorted = True,
            default = [],
            doc = """
    The set of Python (`.py`) files to include in this library.
""",
        ),
    }

def _resources_arg():
    return {
        "resources": attrs.named_set(
            attrs.source(),
            sorted = True,
            default = [],
            doc = """
    Static files to be packaged along with the Python sources.
     These resources can be accessed at runtime using
     the [importlib.resources](https://docs.python.org/3/library/importlib.resources.html) module
     from the Python standard library.
""",
        ),
    }

def _base_module_arg():
    return {
        "base_module": attrs.option(
            attrs.string(),
            default = None,
            doc = """
    The package in which the specified source files and resources should reside in their final
     location in the top-level binary. If unset, Buck uses the project-relative directory
     that contains the BUCK file.
""",
        ),
    }

def _linker_flags_arg():
    return {
        "linker_flags": attrs.list(
            attrs.arg(anon_target_compatible = True),
            default = [],
            doc = """
    Additional linker flags that should be applied to any linking which is specific to this rule.
     Note that whether these flags are used is dependent on the native link strategy selected in
     `.buckconfig` and currently applies only to the merged `.buckconfig`;
     the `separate` link strategy pulls in shared libraries that are linked in the
     context of the rules that own them, such as `cxx_library()`.
""",
        ),
    }

def _package_style_arg():
    return {
        "package_style": attrs.option(
            attrs.enum(PythonBuckConfigPackageStyle),
            default = None,
            doc = """
    Used to override the global packaging style that is set in `[`.buckconfig`
    ]`.
""",
        ),
    }

def _preload_deps_arg():
    return {
        "preload_deps": attrs.list(
            attrs.dep(),
            default = [],
            doc = """
    A list of C/C++ library dependencies that need to be loaded before any
     other libraries when the PEX starts up. This requires dynamic loader support,
     such as `LD_PRELOAD`, found on most systems. This list is order-
     sensitive and the preload libraries listed here are passed down to the dynamic
     linker in the same order.
""",
        ),
    }

def _exclude_deps_from_merged_linking_arg():
    return {
        "exclude_deps_from_merged_linking": attrs.bool(
            default = False,
            doc = """
    When linking the top-level binary with a `merged` ``.buckconfig``,
     do not merge or re-link any native transitive deps of this library. This is useful if
     this library wraps prebuilt native extensions which cannot be re-linked as part of
     library merging.
""",
        ),
    }

def _deduplicate_merged_link_roots():
    return {
        "deduplicate_merged_link_roots": attrs.bool(
            default = True,
            doc = """
    When linking multiple top-level binaries with the `merged` ``.buckconfig``,
     coalesce root link rules which are identical across independent merged links.
""",
        ),
    }

def _version_selections_arg():
    return {
        "version_selections": attrs.dict(
            key = attrs.string(),
            value = attrs.string(),
            default = {},
            doc = """A mapping from library name to desired version. Versioned dependencies from the entire dependency tree with the given name will be used at the specified version, if available.
            Versioned libraries that are unspecified will be used at their respective default version.""",
        ),
    }

def _executable_deps_arg():
    return {
        "executable_deps": attrs.list(attrs.dep(), default = []),
    }

def _deps_arg():
    return {
        "deps": attrs.list(
            attrs.dep(),
            default = [],
            doc = """
            A list of `python_library()` rules that specify Python
                modules to include in the binary — including all transitive
                dependencies of these rules.
        """,
        ),
    }

def _internal_tools_arg():
    return attrs.default_only(
        attrs.toolchain_dep(
            default = "prelude//python/tools:python_internal_tools",
            doc = """
        Internal implementation details of the Python rules.
    """,
        )
    )

python_common = struct(
    srcs_arg = _srcs_arg,
    resources_arg = _resources_arg,
    base_module_arg = _base_module_arg,
    linker_flags_arg = _linker_flags_arg,
    package_style_arg = _package_style_arg,
    preload_deps_arg = _preload_deps_arg,
    exclude_deps_from_merged_linking_arg = _exclude_deps_from_merged_linking_arg,
    deduplicate_merged_link_roots = _deduplicate_merged_link_roots,
    version_selections_arg = _version_selections_arg,
    executable_deps_arg = _executable_deps_arg,
    deps_arg = _deps_arg,
    internal_tools_arg = _internal_tools_arg,
)