cool-RR | 3 Apr 23:55 2011

Re: GarlicSim lecture in Givat Ram, Jerusalem on 4.4.2011

Reminder: It's Monday evening! (a.k.a. "this evening" if you're not living hacker hours.)

On Wed, Mar 30, 2011 at 12:25 PM, cool-RR <cool-rr <at> cool-rr.com> wrote:
Hello everyone.

On Monday, April 4th at 18:00, the Jerusalem Linux Club will gather to hear a talk about GarlicSim given by its creator, Ram Rachum. The talk will be held in the computer farm at Shprinzak, classroom 1, in the Givat Ram campus.

(Apologies for whoever already got this message from another source.)


## The lecture ##

GarlicSim is a Pythonic framework for computer simulations. More info about it can be found here:

http://garlicsim.org/

GarlicSim is a platform for writing, running and analyzing simulations. It is general enough to handle simulations from many fields: Physics, game theory, epidemic spread, electronics, etc. GarlicSim's goal is to let people build and run simulations with as little technical work as possible.

We're going to see a few cool simulations and speak about what simulations from different fields have in common with each other. Ram will talk about the goals and the design of GarlicSim, and his plans for the project's future.

Slides:

http://garlicsim.org/presentation.pdf

Attendance is free and everyone is invited.

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Sim Zacks | 4 Apr 13:23 2011
Picon

python job

Compulab is looking for a software developer for internal projects in 
the Haifa/Yokneam area.
Requirements:
Academic degree
At least 1 year development of database-based GUI applications.
Experience developing in multiple languages and technologies
Advantages: Python, AJAX, WxWidgets, Postgresql, Linux, Java, JQuery, PHP

Please send resumes to me:
sim <at> compulab.co.il
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il

cool-RR | 15 Apr 21:45 2011

Statically analyzing a Python module to find assignments

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. 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.
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
cool-RR | 16 Apr 11:43 2011

Re: Statically analyzing a Python module to find assignments

On Fri, Apr 15, 2011 at 9:45 PM, cool-RR <cool-rr <at> cool-rr.com> 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. 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.
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Tal Einat | 16 Apr 12:20 2011
Picon

Re: Statically analyzing a Python module to find assignments

cool-RR 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. 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.

Why on earth would you want to do this on .pyc or .pyo files? Do you want to support source-less simpacks?

If you can ensure that __init__.py is available, you can pick the lines from the file which include the doc-string and assignments quite easily, and execute them in a dummy environment to get the values. You can fall back to importing the package if this fails.

Mangling __import__ temporarily might work, sounds like a hack I would prefer to avoid. And theoretically __init__.py can include other heavy code. And you could break stuff if __init__.py assumes that the imports work in a way that returning a mock object breaks.

Do you have a really good reason not to make the writer of a simpack responsible for making __init__.py quick to import? Then you can optimize only if a real need arises.

- Tal
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
cool-RR | 16 Apr 12:26 2011

Re: Statically analyzing a Python module to find assignments

On Sat, Apr 16, 2011 at 12:20 PM, Tal Einat <taleinat <at> gmail.com> wrote:
cool-RR 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. 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.

Why on earth would you want to do this on .pyc or .pyo files? Do you want to support source-less simpacks?

Yes, definitely. For example, py2exe creates distributions with compiled files only. Some people like that in order to keep their source code somewhat secret. Some people, like me, don't like it but still use it because neither py2exe nor bbfreeze let you turn that feature off.
 

If you can ensure that __init__.py is available, you can pick the lines from the file which include the doc-string and assignments quite easily, and execute them in a dummy environment to get the values. You can fall back to importing the package if this fails.

Not good enough. I really want to support .pyc files and I really want to not import all the simpacks.
 

Mangling __import__ temporarily might work, sounds like a hack I would prefer to avoid. And theoretically __init__.py can include other heavy code. And you could break stuff if __init__.py assumes that the imports work in a way that returning a mock object breaks.

Definitely not pretty. But can you come up with an example of how it would be broken? I think most such examples would be pretty contrived and not something that's likely to be written in real life.

 

Do you have a really good reason not to make the writer of a simpack responsible for making __init__.py quick to import? Then you can optimize only if a real need arises.

I personally believe that `__init__.py` should import important stuff from the package, and not only in simpacks but in general in Python packages.


Ram.
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Tal Einat | 16 Apr 14:40 2011
Picon

Re: Statically analyzing a Python module to find assignments

Mangling __import__ temporarily might work, sounds like a hack I would prefer to avoid. And theoretically __init__.py can include other heavy code. And you could break stuff if __init__.py assumes that the imports work in a way that returning a mock object breaks.

Definitely not pretty. But can you come up with an example of how it would be broken? I think most such examples would be pretty contrived and not something that's likely to be written in real life.

Even something as simple as this would break (if not in the import statement, then later):
from some_package.some_module import some_thing
 

Do you have a really good reason not to make the writer of a simpack responsible for making __init__.py quick to import? Then you can optimize only if a real need arises.

I personally believe that `__init__.py` should import important stuff from the package, and not only in simpacks but in general in Python packages.

Then perhaps such metadata shouldn't be kept in __init__.py in the first place?

- Tal
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
cool-RR | 16 Apr 15:37 2011

Re: Statically analyzing a Python module to find assignments

On Sat, Apr 16, 2011 at 8:40 AM, Tal Einat <taleinat <at> gmail.com> wrote:
Mangling __import__ temporarily might work, sounds like a hack I would prefer to avoid. And theoretically __init__.py can include other heavy code. And you could break stuff if __init__.py assumes that the imports work in a way that returning a mock object breaks.

Definitely not pretty. But can you come up with an example of how it would be broken? I think most such examples would be pretty contrived and not something that's likely to be written in real life.

Even something as simple as this would break (if not in the import statement, then later):
from some_package.some_module import some_thing

The import line wouldn't break. What kind of stuff that uses `some_thing` will break later? I think that imports in `__init__.py` files are almost always imports for the namespace's sake, and that nothing complex is done with the imported objects. And even if the `__init__.py` file has some logic in, I think nothing too bad will happen if it will operate on mock objects.
 
Do you have a really good reason not to make the writer of a simpack responsible for making __init__.py quick to import? Then you can optimize only if a real need arises.

I personally believe that `__init__.py` should import important stuff from the package, and not only in simpacks but in general in Python packages.

Then perhaps such metadata shouldn't be kept in __init__.py in the first place? 

- Tal

That would definitely be an easy solution: Tell simpack writers to have a file "metadata.txt" or whatever. But I find it less elegant. I believe that almost every Python package (or module or function or class) should have a docstring, so if I'll have to maintain the simpack description in both places (docstring and "metadata.txt"), I'll be breaking DRY.

Also, people who are not experienced with distutils may have to spend some "quality time" with it to make it package the "metadata.txt" file with their code. As Guido said, "I'd like not to have such a newbie trap lying around."


Ram.
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Tal Einat | 16 Apr 15:50 2011
Picon

Re: Statically analyzing a Python module to find assignments


On Sat, Apr 16, 2011 at 4:37 PM, cool-RR <cool-rr <at> cool-rr.com> wrote:
On Sat, Apr 16, 2011 at 8:40 AM, Tal Einat <taleinat <at> gmail.com> wrote:

Then perhaps such metadata shouldn't be kept in __init__.py in the first place? 

That would definitely be an easy solution: Tell simpack writers to have a file "metadata.txt" or whatever. But I find it less elegant. I believe that almost every Python package (or module or function or class) should have a docstring, so if I'll have to maintain the simpack description in both places (docstring and "metadata.txt"), I'll be breaking DRY.

Also, people who are not experienced with distutils may have to spend some "quality time" with it to make it package the "metadata.txt" file with their code. As Guido said, "I'd like not to have such a newbie trap lying around."

Then perhaps have them write the metadata in a metadata.py file, and execfile it in __init__.py? Then you can just execfile the metadata.py file if you want just the metadata.

- Tal
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
cool-RR | 16 Apr 15:52 2011

Re: Statically analyzing a Python module to find assignments

On Sat, Apr 16, 2011 at 3:50 PM, Tal Einat <taleinat <at> gmail.com> wrote:

On Sat, Apr 16, 2011 at 4:37 PM, cool-RR <cool-rr <at> cool-rr.com> wrote:
On Sat, Apr 16, 2011 at 8:40 AM, Tal Einat <taleinat <at> gmail.com> wrote:

Then perhaps such metadata shouldn't be kept in __init__.py in the first place? 

That would definitely be an easy solution: Tell simpack writers to have a file "metadata.txt" or whatever. But I find it less elegant. I believe that almost every Python package (or module or function or class) should have a docstring, so if I'll have to maintain the simpack description in both places (docstring and "metadata.txt"), I'll be breaking DRY.

Also, people who are not experienced with distutils may have to spend some "quality time" with it to make it package the "metadata.txt" file with their code. As Guido said, "I'd like not to have such a newbie trap lying around."

Then perhaps have them write the metadata in a metadata.py file, and execfile it in __init__.py? Then you can just execfile the metadata.py file if you want just the metadata.

- Tal

That would solve the distutils problem, but now the main problem of DRY. Also, I'd hate to force people to do these procedures in their `__init__.py`.


Ram.
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il

Gmane