Personal tools
You are here: Home Weblog Archive 2007

Entries For: 2007

2007-12-10

Zope 3 dependencies in Zope 2 buildout

Filed Under:

Describe a buildout recipe to avoid fetching zope 3 libraries when installing eggs with zope 3 depedencies in a zope 2 buildout

I got tired removing zope.interface, zope.component, zope.deferredimport, zope.event, ... of my eggs folder inside my buildout when installing package such as z3c.sqlalchemy in my Zope2 / Plone buildouts ...

After the discussion on Zope3-users list and thanks to Jim lights, I wrote a really simple recipe which just create egg links to zope libraries in your develop-eggs so that setuptools can see that the dependencies are already satisfied.

So if you list your zope library :

$ ls yourbuildout/parts/yourzope2/lib/python/zope

app configuration documenttemplate exceptions i18n __init__.py pagetemplate schema structuredtext testbrowser viewlet
cachedescriptors contentprovider dottedname formlib i18nmessageid interface proxy security tal testing
component deprecation event hookable index modulealias publisher server tales thread

You will get

$ ls yourbuildout/develop-eggs

zope.app.component.egg-info zope.app.security.egg-info zope.dottedname.egg-info zope.interface.egg-info zope.structuredtext.egg-info
zope.app.egg-info zope.app.testing.egg-info zope.event.egg-info zope.modulealias.egg-info zope.tal.egg-info
zope.app.event.egg-info zope.cachedescriptors.egg-info zope.exceptions.egg-info zope.pagetemplate.egg-info zope.tales.egg-info
zope.app.i18n.egg-info zope.component.egg-info zope.formlib.egg-info zope.proxy.egg-info zope.testbrowser.egg-info
zope.app.interface.egg-info zope.configuration.egg-info zope.hookable.egg-info zope.publisher.egg-info zope.testing.egg-info
zope.app.pagetemplate.egg-info zope.contentprovider.egg-info zope.i18n.egg-info zope.schema.egg-info zope.thread.egg-info
zope.app.publisher.egg-info zope.deprecation.egg-info zope.i18nmessageid.egg-info zope.security.egg-info zope.viewlet.egg-info
zope.app.schema.egg-info zope.documenttemplate.egg-info zope.index.egg-info zope.server.egg-info

Where each of these file will be seen for setuptools as an egg:

$ cat yourbuildout/develop-eggs/zope.app.component.egg-info

Metadata-Version: 1.0
Name: zope.app.component
Version: 0.0

Sure this might look like an ugly hook but I can't wait for zope 2 eggification

2007-12-06

Buildout and Virtualenv

Filed Under:

How and why use buildout with virtualenv

Buildout is this wonderful tool which helps you to automate setup and configuration of your applications.

Virtualenv is a tool which will help you to isolate your python environment

A few days ago I got stuck during a long time because I didn't see that one library I installed in my global site-packages of my favourite python 2.4 (on my ubuntu: /usr/lib/python2.4/site-packages/) was a lower version of a library I was using in my buildout. Package was sqlalchemy 0.4 in my global sites-package and my buildout based application was using sqlalchemy 0.3.8 ... Here is a simple solution to avoid this kind of things.

Idea is to start buildout with a python free of any external library. Virtualenv is the answer.


Install Virtualenv

Easy:

$ easy_install virtualenv

you will have then a file that you can run: /usr/bin/virtualenv

Let's say you have a buildout configuration go into it:

$ cd myApp.buildout
$ ls -l
bootstrap.py
buildout.cfg

Now you just have to create the python environment without any access to the global site-packages with virtualenv:
$ virtualenv --no-site-packages .
You will have then your new python in the bin folder :
$ ls -l bin
activate
easy_install
easy_install-2.4
python2.4

You can now run the buildout configuration with your new python:
$ ./bin/python2.4 bootstrap.py
$ ./bin/buildout
This will create you a nice and totally isolated environment ...

2007-04-28

Write nicer Python code

Filed Under:

Starting from the basic facts:

  • you can't always code in pair
  • you don't want to compile & tests to check that is fine in the last few line you have just written
  • you want to write nice python code
  • you want to improve the way you write python

It exists a few very interesting softwares that can help you.

Here is a list of the one I am using really often:

PyFlakes - http://www.divmod.org/projects/pyflakes

PyLint - http://www.logilab.org/view?rql=Any%20X%20WHERE%20X%20eid%20857

These two are nice also but not as good as the previous one:

PyMetrics - http://sourceforge.net/projects/pymetrics

PyChecker - http://pychecker.sourceforge.net/
 
These tool are directly linked to my favourite editor VI:

command Pyflakes :call Pyflakes()
function! Pyflakes()
    let tmpfile = tempname()
    execute "w" tmpfile
    execute "set makeprg=(pyflakes\\ " . tmpfile . "\\\\\\|sed\\ s@" . tmpfile ."@%@)"
    make
    cw
endfunction


command Pylint :call Pylint()
function! Pylint()
setlocal makeprg=(echo\ '[%]';\ pylint\ %)
setlocal efm=%+P[%f],%t:\ %#%l:%m
silent make
cwindow
endfunction


And better each time you save your python file in vim , I check for wrong imports with Pyflakes with:

autocmd BufWrite *.{py} :call Pyflakes()



Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: