VTK 8.90 and modules.json

There is a very nice JSON file generated called modules.json, in the top-level build directory of VTK. It gives a lot of information about modules selected and their dependencies etc., here is a little Python script I put together in about 5 minutes to display this information:

#!/usr/bin/env python

import json


def get_program_parameters():
    import argparse
    description = 'Parse the VTK JSON file.'
    epilogue = '''

'''
    parser = argparse.ArgumentParser(description=description, epilog=epilogue,
                                     formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument('file_name', help='The path to the VTK JSON file, modules.json.')
    args = parser.parse_args()
    return args.file_name


def disp_dependencies(data):
    # This is just a dictionary e.g
    for k, v in data['modules'].items():
        print(k)
        if v['depends']:
            print('      Dependencies         :', ' '.join(v['depends']))
        if v['optional_depends']:
            print('      Optional dependencies:', ' '.join(v['optional_depends']))
        if v['private_depends']:
            print('      Private dependencies :', ' '.join(v['private_depends']))


def main():
    fn = get_program_parameters()
    with open(fn) as data_file:
        json_data = json.load(data_file)
    disp_dependencies(json_data)


if __name__ == '__main__':
    main()

@ben.boeckel thanks for providing modules.json, it is really useful.
@lorensen You may find this script useful.

1 Like

This may be very useful, thank you. Can you add here an example output?

I noticed that some fields are empty in the file that shouldn’t be. Needs some debugging…

Is the JSON parsing OK?
On thing that I’m thinking about (modules.json looks really useful for this) is using this to determine what modules to link to in a vtk application. Maybe an alternative version of WhatModulesVTK.py.

The JSON file doesn’t contain header information. WhatModulesVTK.py builds this up itself by scanning a source tree. Adding the list of headers in modules to the file could certainly be done though.