Skip to main content

An extension to Scons which enables dependency tracking on python script imports.

Project description

PyScons is a tool which works with Scons. It is installed into a new environment with either of the two commands:

from pyscons import PYTOOL
env = Environment(tools = ['default', PYTOOL()])

or:

from pyscons import PYTOOL
env = Environment()
PYTOOL()(env)

This does two things:

  1. Installs a new builder: PyScript.
  2. Installs a new scanner for python scripts.

PyScript

This Builder has a few additional abilities.

First, it will automatically find the “.py” files referred to when running a module as a script with the ‘-m’ option. For example the following code will run a module as script and add the appriate files to the dependencies:

env.PyScript("out", ["-m timeit", "myscript.py"], "python $SOURCES > $TARGET")

Second, it defaults the command string to “python $SOURCES” and using the “capture” keyword argument, can automatically append the appropriate strings to capture the output or error (or both) to the targets:

env.PyScript("out", ["-m timeit", "myscript.py"], capture="output")

or to capture both the output and error:

env.PyScript(["out","err"], ["-m timeit", "myscript.py"], capture="both")

Just like Command, multiple steps can be used to create a file:

env.PyScript("out", ["step1.py", "step2.py"],
     ["python ${SOURCES[0]} > temp", "python ${SOURCES[1]} > $TARGET", Delete("temp")])

PyScanner

This scanner uses the modulefinder module to find all import dependencies in all sources with a ‘py’ extension. It can take two options in its constructor:

  1. filter_path: a callable object (or None) which takes a path as input and returns true if this file should be included as a dependency by scons, or false if it should be ignored. By default, this variable becomes a function which ensures that no system python modules or modules from site-packages are tracked. To track all files, use “lambda p: True”.
  2. recursive: with a true (default) or false, it enables or disables recursive dependency tracking.

For example to track all files (including system imports) in a nonrecursive scanner, use the following install code in your SConstruct:

from pyscons import PYTOOL
env = Environment(tools = ['default', PYTOOL(recursive = False, filter_path = lambda p: True)])

Author

  1. Joshua Swamidass (homepage)

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
PyScons-1.0.8.tar.gz (3.4 kB) Copy SHA256 hash SHA256 Source None Sep 22, 2010

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page