如何从构建的scons创建运行epydoc或/和pylint的构建器?
发布于 2012-08-03 20:58:45
这是另一种方法,可能更适合大型项目。
首先,在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')))pylint注释:您可以对ctag和pylint做同样的事情,仅举几例。
发布于 2012-08-03 16:18:52
您可以使用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)发布于 2012-08-03 18:25:06
## 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。欢迎进行更通用的编辑。
https://stackoverflow.com/questions/11791776
复制相似问题