Skip to content

hugoduncan/bazel_rules_pex

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python pex rules for Bazel

Rules


Overview

Setup

Add something like this to your WORKSPACE file:

git_repository(
    name = "io_bazel_rules_pex",
    remote = "https://github.com/benley/bazel_rules_pex.git",
    tag = "0.1.6",
)
load("@io_bazel_rules_pex//pex:pex_rules.bzl", "pex_repositories")
pex_repositories()

In a BUILD file where you want to use these rules, or in your tools/build_rules/prelude_bazel file if you want them present repo-wide, add:

load(
    "@io_bazel_rules_pex//pex:pex_rules.bzl",
    "pex_binary",
    "pex_library",
    "pex_test",
    "pex_pytest",
)

Lastly, make sure that tools/build_rules/BUILD exists, even if it is empty, so that Bazel can find your prelude_bazel file.

pex_pytest

pex_pytest(name, srcs, deps, eggs, args, flaky, local, size, timeout)

A variant of pex_test that uses py.test to run one or more sets of tests.

This produces two things:

  1. A pex_binary (<name>_runner) containing all your code and its dependencies, plus py.test, and the entrypoint set to the py.test runner.
  2. A small shell script to launch the <name>_runner executable with each of the srcs enumerated as commandline arguments. This is the actual test entrypoint for bazel.

Almost all of the attributes that can be used with pex_test work identically here, including those not specifically mentioned in this docstring. Exceptions are main and entrypoint, which cannot be used with this macro.

Attributes

name

Name; Required

A unique name for this rule.

srcs

Unknown; Required

List of files containing tests that should be run.

deps

List of strings; Optional

  </td>
</tr>
<tr id="pex_pytest.eggs">
  <td><code>eggs</code></td>
  <td>
    <p><code>List of strings; Optional</code></p>
    
  </td>
</tr>
<tr id="pex_pytest.args">
  <td><code>args</code></td>
  <td>
    <p><code>List of strings; Optional</code></p>
    
  </td>
</tr>
<tr id="pex_pytest.flaky">
  <td><code>flaky</code></td>
  <td>
    <p><code>Unknown; Optional</code></p>
    
  </td>
</tr>
<tr id="pex_pytest.local">
  <td><code>local</code></td>
  <td>
    <p><code>Unknown; Optional</code></p>
    
  </td>
</tr>
<tr id="pex_pytest.size">
  <td><code>size</code></td>
  <td>
    <p><code>Unknown; Optional</code></p>
    
  </td>
</tr>
<tr id="pex_pytest.timeout">
  <td><code>timeout</code></td>
  <td>
    <p><code>Unknown; Optional</code></p>
    
  </td>
</tr>
## pex_repositories
pex_repositories()

Rules to be invoked from WORKSPACE for remote dependencies.

pex_binary

pex_binary(name, deps, data, srcs, eggs, entrypoint, interpreter, main, pex_use_wheels, pex_verbosity, reqs, zip_safe)

Build a deployable pex executable.

Attributes

name

Name; Required

A unique name for this rule.

deps

List of labels; Optional

Python module dependencies.

pex_library and py_library rules should work here.

data

List of labels; Optional

Files to include as resources in the final pex binary.

Putting other rules here will cause the outputs of those rules to be embedded in this one. Files will be included as-is. Paths in the archive will be relative to the workspace root.

srcs

List of labels; Optional

  </td>
</tr>
<tr id="pex_binary.eggs">
  <td><code>eggs</code></td>
  <td>
    <p><code>List of <a href="http://bazel.io/docs/build-ref.html#labels">labels</a>; Optional</code></p>
    <p><code>.egg</code> and <code>.whl</code> files to include as python packages.</p>
  </td>
</tr>
<tr id="pex_binary.entrypoint">
  <td><code>entrypoint</code></td>
  <td>
    <p><code>String; Optional</code></p>
    <p>Name of a python module to use as the entrypoint.</p>

e.g. your.project.main

If unspecified, the main attribute will be used. It is an error to specify both main and entrypoint.

interpreter

String; Optional

Path to the python interpreter the pex should to use in its shebang line.

main

Label; Optional

File to use as the entrypoint.

If unspecified, the first file from the srcs attribute will be used.

pex_use_wheels

Boolean; Optional

  </td>
</tr>
<tr id="pex_binary.pex_verbosity">
  <td><code>pex_verbosity</code></td>
  <td>
    <p><code>Integer; Optional</code></p>
    
  </td>
</tr>
<tr id="pex_binary.reqs">
  <td><code>reqs</code></td>
  <td>
    <p><code>List of strings; Optional</code></p>
    <p>External requirements to retrieve from pypi, in <code>requirements.txt</code> format.</p>

This feature will reduce build determinism! It tells pex to resolve all the transitive python dependencies and fetch them from pypi.

It is recommended that you use eggs instead where possible.

zip_safe

Boolean; Optional

  </td>
</tr>
## pex_library
pex_library(name, deps, data, srcs, eggs, reqs)

Attributes

name

Name; Required

A unique name for this rule.

deps

List of labels; Optional

Python module dependencies.

pex_library and py_library rules should work here.

data

List of labels; Optional

Files to include as resources in the final pex binary.

Putting other rules here will cause the outputs of those rules to be embedded in this one. Files will be included as-is. Paths in the archive will be relative to the workspace root.

srcs

List of labels; Optional

  </td>
</tr>
<tr id="pex_library.eggs">
  <td><code>eggs</code></td>
  <td>
    <p><code>List of <a href="http://bazel.io/docs/build-ref.html#labels">labels</a>; Optional</code></p>
    <p><code>.egg</code> and <code>.whl</code> files to include as python packages.</p>
  </td>
</tr>
<tr id="pex_library.reqs">
  <td><code>reqs</code></td>
  <td>
    <p><code>List of strings; Optional</code></p>
    <p>External requirements to retrieve from pypi, in <code>requirements.txt</code> format.</p>

This feature will reduce build determinism! It tells pex to resolve all the transitive python dependencies and fetch them from pypi.

It is recommended that you use eggs instead where possible.

## pex_test
pex_test(name, deps, data, srcs, eggs, entrypoint, interpreter, main, pex_use_wheels, pex_verbosity, reqs, zip_safe)

Attributes

name

Name; Required

A unique name for this rule.

deps

List of labels; Optional

Python module dependencies.

pex_library and py_library rules should work here.

data

List of labels; Optional

Files to include as resources in the final pex binary.

Putting other rules here will cause the outputs of those rules to be embedded in this one. Files will be included as-is. Paths in the archive will be relative to the workspace root.

srcs

List of labels; Optional

  </td>
</tr>
<tr id="pex_test.eggs">
  <td><code>eggs</code></td>
  <td>
    <p><code>List of <a href="http://bazel.io/docs/build-ref.html#labels">labels</a>; Optional</code></p>
    <p><code>.egg</code> and <code>.whl</code> files to include as python packages.</p>
  </td>
</tr>
<tr id="pex_test.entrypoint">
  <td><code>entrypoint</code></td>
  <td>
    <p><code>String; Optional</code></p>
    <p>Name of a python module to use as the entrypoint.</p>

e.g. your.project.main

If unspecified, the main attribute will be used. It is an error to specify both main and entrypoint.

interpreter

String; Optional

Path to the python interpreter the pex should to use in its shebang line.

main

Label; Optional

File to use as the entrypoint.

If unspecified, the first file from the srcs attribute will be used.

pex_use_wheels

Boolean; Optional

  </td>
</tr>
<tr id="pex_test.pex_verbosity">
  <td><code>pex_verbosity</code></td>
  <td>
    <p><code>Integer; Optional</code></p>
    
  </td>
</tr>
<tr id="pex_test.reqs">
  <td><code>reqs</code></td>
  <td>
    <p><code>List of strings; Optional</code></p>
    <p>External requirements to retrieve from pypi, in <code>requirements.txt</code> format.</p>

This feature will reduce build determinism! It tells pex to resolve all the transitive python dependencies and fetch them from pypi.

It is recommended that you use eggs instead where possible.

zip_safe

Boolean; Optional

  </td>
</tr>

About

Python PEX rules for Bazel

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.4%
  • Shell 0.6%