Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close

CPython, a binary builder for Python installs

This first version of a Python Binary Builder is based on the work of Mati Gruca's Google Summer of Code 2008 project (last SVN branch).

The "InstallPython" method creates .pyc or .pyo files for .py source files and adds them to the list of targets along with the source files. They are later copied to the destination (target) directory.

The "InstallPython" Builder takes a target (destination) directory as its first argument and a list of source files/directories as a second argument. It returns the list of target files to copy to the target directory.

Examples

A simple example of an "SConstruct" file:

env = Environment()
hello = File('hello.py')
env.InstallPython('/usr/local/bin/', hello)
env.Alias('install', '/usr/local/bin/')

"SCons" invoked with the "-Q install" parameter will compile the "hello.py" file into "hello.pyc", and copy both files into "/usr/local/bin/" directory.

Sample output:

$ scons -Q install
Install file: "hello.py" as "/usr/local/bin/hello.py"
Install file: "hello.pyc" as "/usr/local/bin/hello.pyc"

"InstallPython" can also compile Python source files into optimized binary files (".pyo" suffix) instead of ordinary binaries (".pyc" files). To achieve this, change the call to "Environment()" and set the "CPYTHON_PYC" variable to '0' (zero):

env = Environment(CPYTHON_PYC=0)
hello = File('hello.py')
env.InstallPython('/usr/local/bin/', hello)
env.Alias('install', '/usr/local/bin/')

Sample output:

$ scons -Q install
Install file: "hello.py" as "/usr/local/bin/hello.py"
Install file: "hello.pyo" as "/usr/local/bin/hello.pyo"

The "InstallPython" method accepts both, files and directories, as its source arguments:

env = Environment()
pyfiles = Dir('pyfiles/')
env.InstallPython('/usr/local/bin/', pyfiles)
env.Alias('install', '/usr/local/bin')

Running "scons -Q install" will copy all the ".py" files from "pyfiles" directory into "/usr/local/bin/pyfiles" directory along with corresponding ".pyc" files.

Sample output:

$ scons -Q install
Install file: "pyfiles/hello.py" as "/usr/local/bin/pyfiles/hello.py"
Install file: "pyfiles/hello.pyc" as "/usr/local/bin/pyfiles/hello.pyc"
Install file: "pyfiles/hello2.py" as "/usr/local/bin/pyfiles/hello2.py"
Install file: "pyfiles/hello2.pyc" as "/usr/local/bin/pyfiles/hello2.pyc"

Mixing files and directories is also possible:

env = Environment()
hello = File('hello.py')
pyfiles = Dir('pyfiles/')
env.InstallPython('/usr/local/bin/', [hello, pyfiles])
env.Alias('install', '/usr/local/bin')

Sample output:

$ scons -Q install
Install file: "hello.py" as "/usr/local/bin/hello.py"
Install file: "hello.pyc" as "/usr/local/bin/hello.pyc"
Install file: "pyfiles/hello.py" as "/usr/local/bin/pyfiles/hello.py"
Install file: "pyfiles/hello.pyc" as "/usr/local/bin/pyfiles/hello.pyc"
Install file: "pyfiles/hello2.py" as "/usr/local/bin/pyfiles/hello2.py"
Install file: "pyfiles/hello2.pyc" as "/usr/local/bin/pyfiles/hello2.pyc"

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.