This is a quick, simple and dirty script to extract the contents of a Python module and store it in a QScintilla/Eric4 API file.
#!/usr/bin/env python
"""
api-gen 0.1
-----------
This is a quick, simple and dirty script to extract the contents of a
Python module and store it in a QScintilla/Eric4 API file.
Replace all instances of "mymodule" with your module name.
Written by Raoul Snyman [raoul.snyman AT saturnlaboratories DOT co DOT za]
License:
--------
Copyright (c) 2009 Raoul Snyman. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
import inspect
# Put your module here
import mymodule
# These Python core modules are often imported into modules, and due
# to the way this script works, all extra modules are pulled in as
# well. This is a list of modules you want to exclude from your API
# file. Append any modules you don't want in your API file.
exclude = ['os', 'sys', 're', 'logging', 'types', 'pkg_resources',
'warnings', 'inspect']
def get_members(mod, hierarchy, filehandle=None):
"""
This function runs through a given module and pulls out all the
classes, methods, and attributes. It then calls itself recursively
in order to pull out the sub-modules, -classes and -attributes.
"""
for mname, mobject in inspect.getmembers(mod):
if mname in exclude:
continue
object_path = '%s.%s' % (hierarchy, mname)
if filehandle is not None:
filehandle.write(object_path + '\n')
else:
print object_path
if (not (mname.startswith('_') or inspect.isbuiltin(mobject))) and \
(inspect.ismodule(mobject) or inspect.isclass(mobject)) and \
mname not in hierarchy.split('.'):
get_members(mobject, object_path, filehandle)
if __name__ == '__main__':
# Put your api file name here
filehandle = open('mymodule.api', 'w')
# Put your module here
get_members(mymodule, 'mymodule', filehandle)
filehandle.close()







Comments
Re: api-gen.py
Direct download: api-gen.py