[Python-il] Statically analyzing a Python module to find assignments

cool-RR cool-rr at cool-rr.com
Fri Apr 15 22:45:51 IDT 2011


Hello folks,

I want to let people who write GarlicSim simpacks write an `__init__.py`
module like this:

    '''
    This is the simpack's docstring.

    Bla bla bla.
    '''

    name = 'Name of the simpack'

    tags = ['list', 'of', 'simpack-tags']

    __version__ = '0.9.3'

And I want GarlicSim to be able to get all of these things: The docstring,
the name, the tags and the version. And I want to show them in this
widget<http://dl.dropbox.com/u/1927707/SimpackSelectionDialog.png>.
But I want to do it without importing the module, because `__init__.py`
might import the entire package which can be heavy. (I want to do this
process for many heavy simpacks.)

We can assume that the user doesn't do anything computationally trickier
then a simple literal assignment.

I heard that the `ast` module does things like this. But, I also want to be
able to do this process on compiled files, e.g. `__init__.pyc` or
`__init__.pyo`, and I don't know how to do this with the `ast` module.

Can the `ast` module do this on both source and compiled files? How is it
done? Otherwise, is there a more fitting tool than `ast`?


(By the way, if anyone cares, I have recently open-sourced GarlicSim's GUI,
so now GarlicSim is completely open-source.)


Thanks,
Ram.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://hamakor.org.il/pipermail/python-il/attachments/20110415/1fc37da9/attachment.htm>


More information about the Python-il mailing list