从scons fi运行epydoc和/或pylint builders

2024-06-02 06:04:34 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: sconspylintepydoc
3条回答

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

首先,在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文件中,添加:

^{pr2}$

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

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

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

以下是我最后使用的,基于Bradyanswer。在

## 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。欢迎进行更全面的编辑。在

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

例如,可以执行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)

相关问题 更多 >