6 from twisted
.python
import reflect
7 from twisted
.internet
import reactor
11 assert epydoc
.__version
__[0] == '2', "You need epydoc 2.x!"
12 from epydoc
.cli
import cli
16 def __init__(self
, name
, level
):
21 return '<Fake %s>' % self
.__name
__
24 def __nonzero__(self
):
27 def __call__(self
, *args
, **kw
):
28 pass #print 'Called:', args
30 def __getattr__(self
, attr
):
33 return FakeModule(self
.__name
__+'.'+attr
, self
.__level
-1)
35 def __cmp__(self
, other
):
36 if not hasattr(other
, '___name__'):
38 return cmp(self
.__name
__, other
.__name
__)
42 modpath
= modname
.split('.')
44 for m
in range(len(modpath
)):
45 mp
= '.'.join(modpath
[:m
+1])
46 nm
= FakeModule(mp
, 4)
48 setattr(prevmod
, modpath
[m
], nm
)
54 # HACK: Another "only doc what we tell you". We don't want epydoc to
55 # automatically recurse into subdirectories: "twisted"'s presence was
56 # causing "twisted/test" to be docced, even thought we explicitly
57 # didn't put any twisted/test in our modnames.
59 from epydoc
import imports
60 orig_find_modules
= imports
.find_modules
64 def find_modules(dirname
):
65 if not os
.path
.isdir(dirname
): return []
70 # Search for directories & modules, and check for __init__.py.
71 # Don't include duplicates (like foo.py and foo.pyc), and give
72 # precedance to the .py files.
73 for file in os
.listdir(dirname
):
74 filepath
= os
.path
.join(dirname
, file)
75 if os
.path
.isdir(filepath
): dirs
.append(filepath
)
76 elif not re
.match(r
'\w+.py.?', file):
77 continue # Ignore things like ".#foo.py" or "a-b.py"
78 elif file[-3:] == '.py':
79 modules
[file] = os
.path
.join(dirname
, file)
80 if file == '__init__.py': found_init
= 1
81 elif file[-4:-1] == '.py':
82 modules
.setdefault(file[:-1], file)
83 if file[:-1] == '__init__.py': found_init
= 1
84 modules
= modules
.values()
86 # If there was no __init__.py, then this isn't a package
87 # directory; return nothing.
88 if not found_init
: return []
90 # Recurse to the child directories.
91 # **twisted** here's the change: commented next line out
92 #for d in dirs: modules += find_modules(d)
95 imports
.find_modules
= find_modules
99 # Now, set up the list of modules for epydoc to document
101 def addMod(arg
, path
, files
):
103 file = os
.path
.join(path
, fn
).replace('%s__init__'%os.sep
, '')
104 if file[-3:] == '.py' and not file.count('%stest%s' % (os
.sep
,os
.sep
)):
105 modName
= file[:-3].replace(os
.sep
,'.')
107 #print 'pre-loading', modName
108 reflect
.namedModule(modName
)
109 except ImportError, e
:
110 print 'import error:', modName
, e
112 print 'other error:', modName
, e
114 modnames
.append(modName
)
116 document_all
= True # are we doing a full build?
117 names
= ['buildbot/'] #default, may be overriden below
119 #get list of modules/pkgs on cmd-line
121 i
= sys
.argv
.index("--modules")
125 names
= sys
.argv
[i
+1:]
128 #sanity check on names
129 for i
in range(len(names
)):
131 j
= names
[i
].rindex('buildbot/')
133 raise SystemExit, 'You can only specify buildbot modules or packages'
135 #strip off any leading directories before the 'twisted/'
136 #dir. this makes it easy to specify full paths, such as
138 names
[i
] = names
[i
][j
:]
141 #if -o was specified, we need to change it to point to a tmp dir
142 #otherwise add our own -o option
144 i
= sys
.argv
.index('-o')
145 old_out_dir
= sys
.argv
[i
+1]
150 sys
.argv
[i
+1] = tmp_dir
152 sys
.argv
[1:1] = ['-o', tmp_dir
]
158 if name
.endswith(".py"):
159 # turn it in to a python module name
160 name
= name
[:-3].replace(os
.sep
, ".")
162 reflect
.namedModule(name
)
164 print 'import error:', name
166 print 'other error:', name
168 modnames
.append(name
)
169 else: #assume it's a dir
170 os
.path
.walk(name
, addMod
, None)
174 if 'buildbot.test' in modnames
:
175 modnames
.remove('buildbot.test')
176 ##if 'twisted' in modnames:
177 ## modnames.remove('twisted')
179 sys
.argv
.extend(modnames
)
185 '-n', 'BuildBot %s' % buildbot
.version
,
186 '-u', 'http://buildbot.sourceforge.net/', '--no-private']
188 # Make it easy to profile epyrun
191 profile
.run('cli()', 'epyrun.prof')