Search code examples
pythonsconsepydoc

Run epydoc and/or pylint builders from scons file


How would I create builders that runs epydoc or/and pylint from a scons built?


Solution

  • Here is another method, probably more portable to large projects.

    First, define epydoc.py in site_scons/site_tools (or where ever you have those) to be:

    # -*- coding: utf-8 -*-
    import SCons.Builder
    import SCons.Action
    
    def complain_epydoc(target, source, env):
        print 'INFORMATION: epydoc binary was not found (see above). Documentation has not been built.'
    
    def generate(env):
        env['EPYDOC'] = find_epydoc(env)
        if env['EPYDOC'] != None:
            opts = '--quiet --html --inheritance listed --graph all --css white --parse-only '
            env['EPYDOCCOM'] = '$EPYDOC ' + opts + '-o $TARGET  $SOURCES'
            env['BUILDERS']['epydoc'] = SCons.Builder.Builder(action=env['EPYDOCCOM'])
        else:
            env['BUILDERS']['epydoc'] = SCons.Builder.Builder(action=env.Action(complain_epydoc))
    
    def find_epydoc(env):
        b=env.WhereIs('epydoc')
        if b == None:
            print 'Searching for epydoc: not found. Documentation will not be built'
        else:
            print 'Searching for epydoc: ', b
        return b
    
    def exists(env):
        if find_epydoc(env) == None:
            return 0
        return 1
    

    In the main SConstruct file, add:

    import epdoc
    env.Tool("epydoc")
    

    Then, in your SConstruct file or SConscript files, you can build documentation like so:

    Alias('epydoc', env.epydoc(source=python_code_files, target=Dir('docs')))
    

    Note: you could do the same thing for ctags and pylint, just to name a few.