Skip to main content

python_library

name

def name(
*,
name: str,
default_target_platform: None | str = ...,
target_compatible_with: list[str] = ...,
compatible_with: list[str] = ...,
exec_compatible_with: list[str] = ...,
visibility: list[str] = ...,
within_view: list[str] = ...,
metadata: OpaqueMetadata = ...,
tests: list[str] = ...,
modifiers: OpaqueMetadata = ...,
_apple_platforms: dict[str, str] = ...,
_create_manifest_for_source_dir: str = ...,
_create_third_party_build_root: str = ...,
_cxx_toolchain: str = ...,
_python_toolchain: str = ...,
base_module: None | str = ...,
contacts: list[str] = ...,
default_host_platform: None | str = ...,
deps: list[str] = ...,
exclude_deps_from_merged_linking: bool = ...,
ignore_compile_errors: bool = ...,
labels: list[str] = ...,
licenses: list[str] = ...,
platform_deps: list[(str, list[str])] = ...,
platform_resources: list[(str, list[str] | dict[str, str])] = ...,
platform_srcs: list[(str, list[str] | dict[str, str])] = ...,
py_version_for_type_checking: None | str = ...,
resources: list[str] | dict[str, str] = ...,
shard_typing: None | bool = ...,
srcs: list[str] | dict[str, str] = ...,
type_stubs: list[str] | dict[str, str] = ...,
typing: bool = ...,
versioned_resources: None | list[(dict[str, str], list[str] | dict[str, str])] = ...,
versioned_srcs: None | list[(dict[str, str], list[str] | dict[str, str])] = ...,
zip_safe: None | bool = ...,
) -> None

A python_library() rule is used to group together Python source files and resources to be passed together in as a dep of other rules.

Parameters

  • name: name of the target
  • default_target_platform: specifies the default target platform, used when no platforms are specified on the command line
  • target_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration
  • compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration
  • exec_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with an execution platform
  • visibility: a list of visibility patterns restricting what targets can depend on this one
  • within_view: a list of visibility patterns restricting what this target can depend on
  • metadata: a key-value map of metadata associated with this target
  • tests: a list of targets that provide tests for this one
  • modifiers: an array of modifiers associated with this target
  • base_module: 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.
  • deps: Other python_library() rules that list srcs from which this rule imports modules.
  • exclude_deps_from_merged_linking: 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: 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() .
  • platform_resources: Python-platform-specific resource files. These should be specified as a list of pairs where the first element in each pair is an un-anchored regex against which the platform name is matched, and the second element is a list of resource files. The regex should use java.util.regex.Pattern syntax. The platform name is a Python platform flavor defined in the buckconfig#python section of .buckconfig.
  • platform_srcs: Python-platform-specific source files. These should be specified as a list of pairs where the first element in each pair is an un-anchored regex against which the platform name is matched, and the second element is a list of source files. The regex should use java.util.regex.Pattern syntax. The platform name is a Python platform flavor defined in the buckconfig#python section of .buckconfig.
  • py_version_for_type_checking: This option will force the type checker to perform checking under a specific version of Python interpreter.
  • shard_typing: Determines if sharding should be enabled on a given target.
  • srcs: The set of Python (.py) files to include in this library.
  • typing: Determines whether to perform type checking on the given target. Default is False.

Details

Examples:

Include Python source files and resource files.


# BUCK

# A rule that includes a single Python file.
python_library(
name = 'fileutil',
srcs = ['fileutil.py'],
deps = [
'//third_party/python-magic:python-magic',
],
)

# A rule that uses glob() to include all Python source files in the
# directory in which the rule is defined. The rule also specifies a
# resource file that gets packaged with the source file.
python_library(
name = 'testutil',
srcs = glob(['testutil/**/*.py']),
resources = [
'testdata.dat',
],
)