bpt (original) (raw)

What is BPT

BPT is a Python library (bpt) and a command line application (box) to create and manage isolated enviroments, or boxes.

BPT is similar in some ways to virtualenv, but it is not restricted to Python packages, allowing to install virtually any Unix software. It also takes some ideas from jhbuild, but without the dependency resolution and automatic downloading machinery, and the bpt-rulesformat is inspired by Gentoo’s ebuilds.

A fork of PIP is included to make installation of python packages easier, and as an example of use of the BPT API.

How to use it

A box is a directory whose structure resembles /usr/ (as defined in the Filesystem Hierarchy Standard), that can contain one or more software packages. Each package is contained in a subdirectory of the pkgs directory in the box. A box contains a script, env, which sets up the environment, putting all the libraries, executables, etc. in the path.

The command to create a box is:

$ bpt/box create my_first_box

(We assume that the source distribution of BPT is in the directory bpt)

This creates the basic structure:

$ find my_first_box my_first_box my_first_box/bin my_first_box/bpt_meta my_first_box/bpt_meta/box_info my_first_box/env my_first_box/include my_first_box/lib my_first_box/man my_first_box/pkgs my_first_box/share

To execute a command within the box environment, use the env script:

$ my_first_box/env 'echo $PATH' /tmp/box_87a482cc-34fc-11de-865a-001ec21bf2c7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/bin

Even if it may not seem obvious at first, the first path points to the box’s bin. We’ll talk about this later in the How it workssection. Prefixing env to every command can be boring, sobox has a shell command that spawns a shell with the environment set up. The env script exports also an environment variable, BPT_BOX_PATH, that box uses to know the location of the current box:

$ bpt/box -b my_first_box/ shell (my_first_box) ot@brian ~ $ echo $BPT_BOX_PATH /Users/ot/my_first_box

To install packages into a box, box offers two different commands:build and autobuild. Alternatively, external programs can use the BPT API to install packages. An example is given by pip-box, included in the distribution.

build

The build command works with sourcedirs: a sourcedir is a directory that contains a bpt-rules file, which contains the instructions to build the software. A good practice is to install BPT itself into the box (the source distribution of BPT is a_sourcedir_):

(my_first_box) ot@brian ~ $ bpt/box build bpt INFO:BPT:Using current box "my_first_box" INFO:BPT:Building application bpt, in sourcedir work/experimental/bpt ... (my_first_box) ot@brian ~ $ which box /tmp/box_87a482cc-34fc-11de-865a-001ec21bf2c7/bin/box

Now we can run the shell using the box’s box:

$ my_first_box/env box shell INFO:BPT:Using current box "my_first_box"

(my_first_box) ot@brian ~ $

Another example of sourcedir is given by python30 in theexamples directory, which installs python 3.0.1:

(my_first_box) ot@brian ~ $ box build examples/python30/ ...

(my_first_box) ot@brian ~ $ python3.0 --version Python 3.0.1

autobuild

The autobuild command, when invoked with a vanilla source tarball or a source directory, tries to build and install it by guessing the build commands. It works when the software builds using the usualconfigure/make or setup.py:

(my_first_box) ot@brian ~ $ box autobuild Downloads/ipython-0.9.1.tar.gz INFO:BPT:Using current box "my_first_box" INFO:BPT:Guessed application name "ipython", version "0.9.1". Unpacking the file... INFO:BPT:Building and installing as package ipython-0.9.1 ...

(my_first_box) ot@brian ~ $ which ipython /tmp/box_87a482cc-34fc-11de-865a-001ec21bf2c7/bin/ipython

(my_first_box) ot@brian ~ $ box autobuild Downloads/sqlite-amalgamation-3.6.3.tar.gz INFO:BPT:Using current box "my_first_box" INFO:BPT:Guessed application name "sqlite-amalgamation", version "3.6.3". Unpacking the file... INFO:BPT:Building and installing as package sqlite-amalgamation-3.6.3 ...

(my_first_box) ot@brian ~ $ which sqlite3 /tmp/box_87a482cc-34fc-11de-865a-001ec21bf2c7/bin/sqlite3

To guess name and version of the package, the tarball/directory name is used, so it has to be of the form -.

pip-box

pip-box is a fork of PIP 0.3.1 where onlyInstallRequirement.install{,_editable} have been replaced to install every package inside the current box:

$ new_box/env pip-box install -qI sphinx INFO:BPT:Enabling package Jinja2-2.1.1 INFO:BPT:Linking package Jinja2-2.1.1 INFO:BPT:Created env script INFO:BPT:Enabling package Pygments-1.0 INFO:BPT:Linking package Pygments-1.0 INFO:BPT:Created env script INFO:BPT:Enabling package sphinx-0.6.1 INFO:BPT:Linking package sphinx-0.6.1 INFO:BPT:Created env script INFO:BPT:Enabling package docutils-0.5 INFO:BPT:Linking package docutils-0.5 INFO:BPT:Created env script

$ new_box/env box status INFO:BPT:Using current box "new_box"

PACKAGE | NAME | VERSION | STATUS |

Jinja2-2.1.1 | Jinja2 | 2.1.1 | enabled | sphinx-0.6.1 | sphinx | 0.6.1 | enabled | docutils-0.5 | docutils | 0.5 | enabled | Pygments-1.0 | Pygments | 1.0 | enabled |

Since only the install functions where changed, it is completely command-line-compatible with PIP. (Interaction with virtualenv was not tested and probably it won’t work)

pip-box is just a working proof-of-concept of an external application that uses the BPT API. If future versions of PIP allow to override the install commands, probably the fork will be removed and the PIP API will be used instead.

Notice that to use pip-box, setuptools is needed. It can be installed in the underlying system, or inside the box usingautobuild:

$ wget -q http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c9.tar.gz $ box -b my_box/ autobuild setuptools-0.6c9.tar.gz INFO:BPT:Unpacking the file... INFO:BPT:Guessed application name "setuptools", version "0.6c9" INFO:BPT:Building and installing as package setuptools-0.6c9 ...

Other commands

The status command shows the installed packages:

(my_first_box) ot@brian ~ $ box status INFO:BPT:Using current box "my_first_box"

PACKAGE | NAME | VERSION | STATUS |

bpt-0.1 | bpt | 0.1 | enabled | ipython-0.8.4 | ipython | 0.8.4 | disabled | ipython-0.9.1 | ipython | 0.9.1 | enabled | python30-3.0.1 | python30 | 3.0.1 | enabled | sqlite-amalgamation-3.6.3 | sqlite-amalgamation | 3.6.3 | enabled |

Packages can be enabled/disabled with the enable/disable commands:

(my_first_box) ot@brian ~ $ box disable python30-3.0.1

(my_first_box) ot@brian ~ $ python3.0 bash: python3.0: command not found

(my_first_box) ot@brian ~ $ box enable python30-3.0.1

(my_first_box) ot@brian ~ $ python3.0 --version Python 3.0.1

Executing disable with the --remove switch deletes permanently the package files.

Use cases

How it works

BPT is designed to work around two problems common to Unix applications and libraries:

Both problems are solved by BPT by using symlinks. When an application is compiled, the prefix passed to the compilation script has the form:

/tmp/box_/pkgs/

where is a unique identifier of the box, and <pkg_name>identifies the (name, version) pair of the software. The envscript ensures that /tmp/box_ is a symlink to the box. Then, when a package is installed/enabled, all the contents of the package are symlinked to the box root (where the PATH variables point to).

If packages are manually removed by deleting their directories, symlinks may be broken. The sync command can be used to restore the consistency of the box by recreating all the symlinks and theenv script.

Writing the bpt-rules file

TODO For now, see the examples/python30 example, it is quite self-explanatory. Keep in mind that, for most software, autobuildjust works.

Also, the bpt-rules format may soon change (or, more probably, a new syntax will be added alongside)

TODO

Some features planned for next releases. Ideas and patches are very welcome.

Supported operating systems

BPT should work with any POSIX operating system. It has been tested on Mac OS X Leopard and several Ubuntu releases.

License

BPT is distributed under the terms of the GPL License. The full license is in the file COPYING, distributed as part of this software.

Credits