Skip to main content

prebuilt_python_library

A prebuilt_python_library() rule is used to include prebuilt python packages into the output of a top-level python_binary() or python_test() rule.

Details

These prebuilt libraries can either be whl files or eggs

whls for most packages are available for download from PyPI. The whl used may be downloaded with remote_file(). However, Buck does not attempt to infer dependency information from pip, so that information will have to be imparted by the user.

To create an egg for a package, run python setup.py bdist_egg in the package source distribution.

Function Signature

def prebuilt_python_library(
*,
name: str,
default_target_platform: None | str = None,
target_compatible_with: list[str] = [],
compatible_with: list[str] = [],
exec_compatible_with: list[str] = [],
visibility: list[str] = [],
within_view: list[str] = ["PUBLIC"],
metadata: OpaqueMetadata = {},
tests: list[str] = [],
modifiers: OpaqueMetadata = [],
_apple_platforms: dict[str, str] = {},
_create_manifest_for_source_dir: str = "prelude//python/tools:create_manifest_for_source_dir",
_create_third_party_build_root: str = "prelude//third-party/tools:create_build",
_extract: str = "prelude//python/tools:extract",
_python_internal_tools: str = "prelude//python/tools:python_internal_tools",
_python_toolchain: str = "gh_facebook_buck2_shims_meta//:python",
binary_src: str,
contacts: list[str] = [],
cxx_header_dirs: None | list[str] = None,
default_host_platform: None | str = None,
deps: list[str] = [],
exclude_deps_from_merged_linking: bool = False,
infer_cxx_header_dirs: bool = False,
labels: list[str] = [],
licenses: list[str] = [],
strip_soabi_tags: bool = False,
) -> None

Parameters

  • name: (required)

    name of the target

  • default_target_platform: (defaults to: None)

    specifies the default target platform, used when no platforms are specified on the command line

  • target_compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • exec_compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with an execution platform

  • visibility: (defaults to: [])

    a list of visibility patterns restricting what targets can depend on this one

  • within_view: (defaults to: ["PUBLIC"])

    a list of visibility patterns restricting what this target can depend on

  • metadata: (defaults to: {})

    a key-value map of metadata associated with this target

  • tests: (defaults to: [])

    a list of targets that provide tests for this one

  • modifiers: (defaults to: [])

    an array of modifiers associated with this target

  • binary_src: (required)

    The path to the .whl or .egg to use.

    Note: .egg files have a very particular naming convention that must be followed - otherwise it will not be found at runtime!

  • deps: (defaults to: [])

    A list of python_library() rules that specify Python modules to include in the binary — including all transitive dependencies of these rules.

  • exclude_deps_from_merged_linking: (defaults to: False)

    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.

  • labels: (defaults to: [])

    Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using buck query() .

  • strip_soabi_tags: (defaults to: False)

    Strip the SOABI tags from extensions in the prebuilt library.

    Note that this should be considered unsafe, as it removes builtin protections that fail fast when a potententially incompatible native extension is imported.

Examples



# A simple prebuilt_python_library with no external dependencies.
remote_file(
name = "requests-download",
url = "https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl",
sha1 = "e1fc28120002395fe1f2da9aacea4e15a449d9ee",
out = "requests-2.22.0-py2.py3-none-any.whl",
)

prebuilt_python_library(
name = "requests",
binary_src = ":requests-download",
)

# A slightly more complex example
prebuilt_python_library(
name = "greenlet",
binary_src = "greenlet-0.4.7-py2.7-macosx-10.10-x86_64.egg",
)

prebuilt_python_library(
name = "gevent",
binary_src = "gevent-1.0.2-py2.7-macosx-10.10-x86_64.egg",
deps = [
":greenlet",
],
)