On Sat, Apr 16, 2011 at 11:43 AM, cool-RR <[email protected]> wrote:

> On Fri, Apr 15, 2011 at 9:45 PM, cool-RR <[email protected]> wrote:
>
>> 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.
>>
>
> I just thought of a crazy way to do this: Import the `__init__.py` module
> while temporarily overriding the `__import__` hook so any imports made by
> the `__init__.py` module will just return mock objects. You think it will
> work?
>
>
> Ram.
>

Okay, I implemented a basic version of it. It needs more development and
more testing in different scenarios, but I already confirmed it works on
Python 2.5-2.7 and even Pypy 1.4. I call it "module tasting."

I'll keep working on it...


Ram.
_______________________________________________
Python-il mailing list
[email protected]
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il

לענות