Subpar一个实用程序用来创建独立的python可执行文件

网友投稿 653 2022-10-27

Subpar一个实用程序用来创建独立的python可执行文件

Subpar一个实用程序用来创建独立的python可执行文件

Subpar

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", commit = "HEAD",)

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() 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.

Limitations:

C extension modules in 'deps' is not yet supportedAutomatic re-extraction of '.runfiles' is not yet supportedDoes not include a copy of the Python interpreter ('hermetic .par')

Example

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

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.

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:I/O案例实操
下一篇:C# 继承
相关文章

 发表评论

暂时没有评论,来抢沙发吧~