简体   繁体   中英

Run epydoc and/or pylint builders from scons file

我将如何创建从生成的scons运行epydoc或/和pylint的构建器?

You can use the Command() builder instead of creating your own builder.

For instance, you could execute epydoc as follows:

# SCons will substitute $SOURCE and $TARGET accordingly
# add any extra cmd line args you need to the cmd string
cmd = 'epydoc $SOURCE $TARGET'
env.Command(target = yourTarget, source = yourSourceFile_s, action = cmd)

Here is what I ended up using, based on Brady 's answer .

## Create epydoc!
import os.path
if os.path.isfile('/usr/bin/epydoc'):
    sources = Split("__init__.py ook/ eek/ fubar/")
    cmd = "epydoc -q --name 'Isotek Python Module collection' " + \
          "--html --inheritance listed --graph all -o docs --css white " + \
          "--parse-only --debug $SOURCES"
    env.Command(target = Dir('docs'), source = sources, action = cmd)
else:
    print "WARNING -- Cannot run epydoc so documentation will not be generated."
    print "WARNING -- To install epydoc run 'sudo yum -y install epydoc'."

Note that I am running on fedora and do not need to worry about the code running elsewhere thus I can assume the path and how to install epydoc. A more general edit is welcome.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM