Fix tests for --incompatible_use_python_toolchains (#104)

This adds a hook file for run_tests.sh to write toolchain info to before each bazel invocation. This replaces the legacy way of passing an interpreter in via --python_path.

It also replaces a config_setting that was used to control whether PY2 or PY3 was used, with a simple constant symbol consumed at loading time. This is needed in order to make the target aware at analysis time of which version it is building for.

Fixes #98, fixes #102.
4 files changed
tree: 0048c4681512a404b6643c4e7f7f0e40ec750742
  1. .ci/
  2. compiler/
  3. docs/
  4. runtime/
  5. scripts/
  6. test_dir_shadowing/
  7. tests/
  8. third_party/
  9. .flake8
  10. .gitignore
  11. .travis.yml
  12. __init__.py
  13. BUILD
  14. CONTRIBUTING.md
  15. debug.bzl
  16. LICENSE
  17. nox.py
  18. README.md
  19. run_tests.sh
  20. subpar.bzl
  21. toolchain_test_hook.bzl
  22. update_docs.sh
  23. WORKSPACE
README.md

Subpar

Build Status

Subpar is a utility for creating self-contained python executables. It is designed to work well with Bazel.

Setup

  • Add the following to your WORKSPACE file:
git_repository(
    name = "subpar",
    remote = "https://github.com/google/subpar",
    tag = "1.0.0",
)
  • Add the following to the top of any BUILD files that declare par_binary() rules:
load("@subpar//:subpar.bzl", "par_binary")

Usage

par_binary() is a drop-in replacement for py_binary() in your BUILD files that also builds a self-contained, single-file executable for the application, with a .par file extension.

To build the .par file associated with a par_binary(name=myname) rule, do

bazel build //my/package:myname.par

The .par file is created alongside the python stub and .runfiles directories that py_binary() creates, but is independent of them. It can be copied to other directories or machines, and executed directly without needing the .runfiles directory. The body of the .par file contains all the srcs, deps, and data files listed.

Limitations:

  • C extension modules in ‘deps’ is not yet supported
  • Automatic re-extraction of ‘.runfiles’ is not yet supported
  • Does not include a copy of the Python interpreter (‘hermetic .par’)

Example

Given a BUILD file with the following:

load("@subpar//:subpar.bzl", "par_binary")

par_binary(
    name = 'foo',
    srcs = ['foo.py', 'bar.py'],
    deps = ['//baz:some_py_lib'],
    data = ['quux.dat'],
)

Run the following build command:

bazel build //package:foo.par

This results in the following files being created by bazel build:

bazel-bin/
    package/
        foo
        foo.par
        foo.runfiles/
            ...

The .par file can be copied, moved, or renamed, and still run like a compiled executable file:

$ scp bazel-bin/package/foo.par my-other-machine:foo.par
$ ssh my-other-machine ./foo.par

System Requirements

  • Python Versions: CPython versions 2.7.6+
  • Operating Systems: Debian-derived Linux, including Ubuntu and Goobuntu.

DISCLAIMER

This is not an official Google product, it is just code that happens to be owned by Google.