I’m putting together some plans for automating the testing the Python examples in the vtk-examples repository. All comments are welcome, especially from @amaclean since you have already done a lot of great work with these examples.
The goal is to make the python examples introspectable, so that we don’t have to add each example to the CMakeLists.txt scripts by hand. Much of this is already done, because each example has a
main() method, uses
argparse where arguments are required, and clearly defines which input data file must be passed as an argument, e.g.:
Hence, running an example with the
--help option will indicate the needed input file. However, I want to change the examples so that the input file can be introspected from another Python program before the example is run, by importing the example as a module.
import MyExample try: # the example's 'inputfiles' attribute, if present, will be a list of filenames. inputfiles = [os.path.join(TestingData, filename) for filename in MyExample.inputfiles] except AttributeError: inputfiles =  # the example's main() will take an argv-style list of arguments MyExample.main(['MyExample'] + inputfiles)
Hence it would be possible to make a single Python front-end for all the Python examples. Such a front end could also generate any cmake bits that are needed to integrate the examples with ctest.
The two changes that I hope to make first are as follows:
- add an
inputfilesattribute to each example that needs an input data file
main(argv)in all examples (plus related argparse changes)
I already have a working script to automatically apply change (2) to each example, and am adding (1) to the same script. Hopefully I will be able to commit something for review this weekend.