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:
Installs a new builder: PyScript.
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:
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”.
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)])
Known Issues
Relative imports do not work. This seems to be a bug in the modulefinder package that I do not know how to fix.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.