问题
How would I create builders that runs epydoc or/and pylint from a scons built?
回答1:
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)
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/11791776/run-epydoc-and-or-pylint-builders-from-scons-file