从scons文件运行epydoc和/或pylint生成器



如何创建从已构建的scons运行epydoc或/和pylint的构建程序?

您可以使用Command()生成器,而不是创建自己的生成器。

例如,您可以如下执行epydoc:

# 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)

以下是我最终使用的内容,基于Brady的回答。

## 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'."

请注意,我在fedora上运行,不需要担心代码在其他地方运行,因此我可以假设路径和如何安装epydoc。欢迎进行更全面的编辑。

这里有另一种方法,可能更适合大型项目。

首先,在site_scons/site_tools中定义epydoc.py(或者你有这些):

# -*- 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

在主SConstruct文件中,添加:

import epdoc
env.Tool("epydoc")

然后,在SConstruct文件或SConscript文件中,您可以构建这样的文档:

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

注意:您可以对ctags和pylint做同样的事情,仅举几个例子。