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


from pyscons import PYTOOL
env = Environment()

This does two things:

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


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", ""], "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", ""], capture="output")

or to capture both the output and error:

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

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

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


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)])


  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.12.tar.gz (3.5 kB) Copy SHA256 hash SHA256 Source None

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 SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page