Buck: python_binary()

python_binary()

This is liable to change in the future.

A python_binary() rule is used to build a PEX file -- an exectuble python package that includes python sources and resources from all transitive python_library dependencies.

Arguments

  • name (required) #

    The name of the rule. The output PEX file will also get this name, with an additional .pex suffix.

  • main_module (required) #

    The module which serves as the entry point for this rule. The __main__.py file of this module will be executed by the interpreter when the PEX file is run.

  • base_module (defaults to None) #

    The package for which the main module should reside under in it's final location in the binary. If unset, the project relative directory that houses the BUCK file is used.

  • platform (defaults to None) #

    The name of the Python platform to build against by default (as defined in the `python#name` section of `.buckconfig`).

  • deps (defaults to []) #

    python_library rules to include in the PEX file (including all transitive dependencies).

  • preload_deps (defaults to []) #

    A list of C/C++ library dependencies that need to be loaded before any other libraries when the python binary starts up. This requires dynamic loader support found on most systems (e.g. `LD_PRELOAD`).

  • package_style (defaults to None) #

    Used to override the global packaging style set with python.package_style.

  • linker_flags (defaults to []) #

    Additional linker flags that should be applied to any links which are specific to this rule. Note that whether these flags are used are dependent on the native link strategy selected in `.buckconfig` and currently only applies to the `MERGED` link strategy, as the `SEPARATE` link strategy pulls in shared libraries linked in the context of their owning rule (e.g. `cxx_library`).

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule in its deps.

  • licenses (defaults to []) #

    Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use buck query.

  • 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 attrfilter.

Examples

python_binary(
  name = 'tailer',
  main_module = 'tailer',
  deps = [
    ':tailerutils',
  ],
)

python_library(
  name = 'tailerutils',
  # tailer.py, the main module, should be specified here.
  srcs = glob(['*.py']),
)

Here is an example of using the `platform` parameter to select the "py2" Python platform as defined in `.buckconfig`:

; .buckconfig
[python#py2]
  interpreter = /usr/bin/python2.7
# BUCK
python_binary(
  name = 'bin',
  platform = 'py2',
  main_module = 'main',
  deps = [
    ':bar',
  ],
)