2012-08-03 80 views

回答

0

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

首先,定义在site_scons/site_toolsepydoc.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做同样的事情,仅举几例。

1

您可以使用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) 
0

这里是我最终使用的基础上,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的。更普遍的编辑​​是受欢迎的。

+0

为什么你有target ='dummy'?如果你没有使用真正的目标,那么SCons会每次运行epydoc,即使它不需要,也可能会有问题。您应该能够将目标指定为由epydoc生成的实际文件,然后SCons只会在需要时执行它。 – Brady 2012-08-03 10:41:36

+0

@Brady:的确如此。这是次优。我最终使用了完全不同的东西。 – Sardathrion 2012-08-03 12:54:37