commit | adab133596f29fdc082f5d2d763e3bc475b008d5 | [log] [tgz] |
---|---|---|
author | Doug Greiman <dgreiman@google.com> | Wed Oct 12 17:54:10 2016 -0700 |
committer | Doug Greiman <dgreiman@google.com> | Wed Oct 12 17:59:47 2016 -0700 |
tree | 1d759c1ff52e011e4b674e373272bb70d87d0e81 | |
parent | 163c53c3bfc25e767d7991dca75b3cd6f6165294 [diff] |
Insert imports near the front of sys.path instead of the end. All 'imports' attributes of py_libraries, plus implicit imports added by Bazel, are added to sys.path by the subpar runtime support module. Previously they were added to the end of sys.path. Now they are added immediately after sys.path[0], to match the behavior of Bazel's generated stub script. https://github.com/google/subpar/issues/11
Subpar is a utility for creating self-contained python executables. It is designed to work well with Bazel.
git_repository( name = "subpar", remote = "https://github.com/google/subpar", commit = "HEAD", )
par_binary()
rules:load("@subpar//:subpar.bzl", "par_binary")
par_binary()
is a drop-in replacement for py_binary()
that also builds a self-contained, single-file executable for the application, with a .par
file extension.
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.
par_binary( name = 'foo', srcs = ['foo.py', 'bar.py'], deps = ['//baz:some_py_lib'], data = ['quux.dat'], )
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
This is not an official Google product, it is just code that happens to be owned by Google.