Monday, May 19, 2008

lxml on OSX -- again

Hi folks :)

Today, I've again tried to install lxml on OS X. For a project I do for a customer (migrating featurecreep CMS sites to Plone), I use the lxml parser. I get regular segfaults, this time using python 2.4 (I use macport for python 2.4).
I investigated again, and came along this post. The scoop is:
after blood, sweat, and some tears (kidding) this is *all* I needed, it seems:

export CFLAGS="-flat_namespace"

...no static builds libxml2 libs, no buildout recipe. I just set that and ran:

python setup.py bdist_egg
--with-xml2-config=/opt/local/bin/xml2-config
--with-xslt-config=/opt/local/bin/xslt-config

which uses the libxml2 and etc. installed by ports. In fact, as long
as /opt/local/bin is on my path that should work without having to set
paths (i.e. from easy_install). All my tests that were segfaulting
are now passing. This appears to be the exact same behavior I got by
setting DYLD_FORCE_FLAT_NAMESPACE at runtime but without the side
affect of applying itself to anything else running in my shell ;)

so, I'm thinking this is just two lines of code added to cflags() ...

if sys.platform in ('darwin',):
result.append('-flat_namespace')


Well. What can I say. Interesting poinst so far for OS X development:
  • no -rpath supported
  • no static libraries (Yup! No joke)

Sunday, May 18, 2008

Read This Post!

I found this post quite educating.

Thursday, May 15, 2008

Aardvark bookmarklet

Duh.

One should read on, THEN post.

Aardvark for Safari --- sort of

Well, this might be old news for you, but by dragging the "run demo" link on the Aardvark home page to the Safari bookmark bar actually allows you to inject Aardvark to the page your're currently viewing.

I think that's cool and useful :)

incredible stuff

I've just found this incredible stuff on the web. I thought I just might blog about it.

git shelves
import gitshelve

data = gitshelve.open(repository = '/tmp/data.git')

data[key] = "Hello, world!"
Data.Sync()
del data[key]
data.close()

How cool is this? Distributed CMS someone?
Original post here. Git it here,
processing on **javascript**

This guy actually ported the processing language to Javascript.
Thats f***ing awesome!

Friday, May 09, 2008

LXML on OS X (again)

It seems that building lxml on Mac OS X is still a problem. I'm trying to use buildout as in:
[libxslt]
recipe = zc.recipe.cmmi
url = http://ftp.gnome.org/pub/GNOME/sources/libxslt/1.1/libxslt-1.1.16.tar.bz2
extra_options = --with-libxml-prefix=${buildout:directory}/parts/libxml2/
--without-python

[lxml]
recipe = zc.recipe.egg:custom
egg = lxml
include-dirs = ${buildout:directory}/parts/libxml2/include/libxml2
${buildout:directory}/parts/libxslt/include
library-dirs = ${buildout:directory}/parts/libxml2/lib
${buildout:directory}/parts/libxslt/lib
rpath = ${buildout:directory}/parts/libxml2/lib
${buildout:directory}/parts/libxslt/lib


That fails when buildout tries to build the lxml egg. Looking closely at the error, I discovered that despite pointing it at the libxslt built, it still uses the one found in /usr/lib.

To be more specific: lxml tries to find xslt-config, which is in $BO/parts/libxslt/bin/xslt-config, but of course finds the one in /usr/bin first.

What I'd like to do is to add something like:

# this would be needed but zc.recipe.egg:custom doesn't allow for that
# Doh.
extra_options= --with-xslt-config=${buildout:directory}/parts/libxslt/bin/xslt-config


That option is available in zc.recipe.cmmi, but not in zc.recipe.egg. Looking at custom.py there I sadly found no obvious way to add this as it uses some version of easy_install.

D'oh.

Possible solutions:
  • build egg manually, add to egg cache (yuck-bleah)
  • build manually for OS X, add to own egg server (yuck)
  • roll-my-own recipe (work)

Thursday, May 08, 2008

Use git -- have more fun.

Following this post, I was lured into trying the git svn backend. We're using SVN at our office for hysterical reasons and this seemed a good way to use git locally and svn as a backend.

So basically what you do is:
$ mkdir somedir
$ cd somedir
$ git-svn init -s $svnurl


That will initialize the git repository. The -s tells git-svn to assume the standard directory scheme for tags and branches, that is, below the svnurl  there should be a "tags", "branches", "releases". Now fetch the repo:
$ git-svn fetch
That'll suck all svn revisions to your local git repo.
Now hack away and use the usual git commands to check in locally.

Use something like gitNub to view the repository changes.

Enjoy :)

Wednesday, May 07, 2008

git +ssh on a mac using macports

To get git installed with subversion support using macports you need to do the following:
$ sudo port install git-core +ssh
Note the +ssh.

Yo! Back from NYC vudo sprint.

I'm still a bit exhausted from the coding marathon we did at the NYC vudo sprint.

We had a great time and I enjoyed pair programming with Malthe Borch very much.

We did some sort of ZODB abstraction using SQLAlchemy called z3c.dobbin. That is, z3c.dobbin uses the z3 schemata (interfaces!) to transparently create SQL tables. Each table will map to one single interface, and dobbin will join these tables based on a dynamically created mapper. That means, that every interface is available separately for doing SQL queries. This should allow for pretty fast and intuitive queries.

We're going to use a relatively new approach to editing web pages -- it'll be more page centric in contrast to being content type centric. There simply will not be any content types in vudo.

Also the skinning will be completely different -- we'll use the designed mock-ups directly, and we'll server them unaltered. That compares a little to deliverance, but only a little. We'll call these mock ups "layouts" and each page in vudo is associated with a lay out. These layouts define "regions", where vudo inserts rendered content at run time. All this is configured using a ZCML directive -- that is w/o touching the mock up, and w/o having the designer be forced to do special markup (e.g. using class prefixes or id prefixes).

I think that's cool :)

And I can't wait to replace this crappy blogging interface with vudo ...

iPhone Developer Program

Yes! I've got a mail from Apple that I'm accepted to the iPhone developer program!

I hope I can make my ideas become real -- I want to have a native front end on my iPhone
to the web framework I'm going to use Really Soon Now (TM).

Tuesday, April 22, 2008

Time passed ....

.... and things happened:
  • I was at the Plone Conference '07
  • I was at this year's Snow Sprint
And most exiting to me, I'll visit NYC the first time in my life to get hands on some really cool stuff.

I'm really into python and web programming now, leaving my old work behind.

Other than that, I've started (again) to work for zest to help paying bills.

Wednesday, April 25, 2007

Ahhhh, new post at last.

Wohoo. A new post.

Finally we sorted out some issues at my company, where I'm partner.

And I got more into Python and Plone. I visited some Plone sprints:

I'll try to attend some more, like the sprint in Potsdam later this year.

Oh, yes, the Plone Conference and Sprint? I'll be there! 

Wednesday, November 01, 2006

Divmod.org AXIOM Ressources.

What is Axiom?

Some quotes:
"Axiom's goal is to provide an efficient, non-SQL interface to an existing relational database." here

Why ise it?

Axiom is fast.

The question for me is, how does Axiom differ from SQLObject, SQLAlchemy or TurboEntity?

AJAX links

While surfing the web I just found these ressources about AJAX and Mochikit.

Heres the website of "The Ajax Exprience" event.

Here are some slides for an Mochikt tutorial. These slides are written for S5 using rst2s5 from python docutils. Need to investigate!

Agile Development

In my current search for a development model which works better when working in a team I have these links to share:

A review of a the book "Agile Estimating and Planning" by Marc Cohen here at isotoma

A list of articles here at the Agile Alliance website.

Tuesday, October 31, 2006

p2p -> q2q

I've been playing around with divmod.org quotiont 2 quotient protocol implementation called vertex.

The q2q protocol is a p2p protocol where you can basically connect to a thing called a "resource".

The Protocol offers resource look up (Where is X?) and authentication (Is it X I'm talking to). The most interesting bit for me is that they implemented STUN and NAT traversal.

Vertex is a demo and proof-of-concept type implementation of this protocol which uses this protocol to authenticate users and send files through the connection.

Wednesday, October 25, 2006

Success!

Yeee-haaa!

I've just connected to Skype using Python and the Skype API Framework. I get notifications, and can send commands:


seletz@yeti:~/develop/python/pyskype/test $python skypeapi-test-osx.py
2006-10-25 01:05:55.934 Python[14094] running event loop
2006-10-25 01:05:56.935 Python[14094] connecting to skype
2006-10-25 01:05:56.941 Python[14094] waiting ....
2006-10-25 01:06:00.547 Python[14094] skypeAttachResponse: 1
2006-10-25 01:06:00.576 Python[14094] skypeNotificationReceived: CONNSTATUS ONLINE
2006-10-25 01:06:00.578 Python[14094] skypeNotificationReceived: CURRENTUSERHANDLE seletz29
2006-10-25 01:06:00.578 Python[14094] skypeNotificationReceived: USERSTATUS ONLINE
2006-10-25 01:06:06.942 Python[14094] sending
2006-10-25 01:06:06.942 Python[14094] got answer: None
2006-10-25 01:06:06.943 Python[14094] skypeNotificationReceived: PROTOCOL 1



I've started a new project at Google Code, where I try to create a platform-independent Python wrapper for the Skype API.

The trick was, of course, RTFM. I just needed to use PyObjC to create a informal protocol for the delegate class I use to connect with the Skype API. It's rather byzantine how Apple encodes type information.

Tuesday, October 24, 2006

WiKi entry on Skype Devzone

I've created a WiKi entry over at the Skype Devzone WiKi about code snippets. Unfortunately, you need a Skype Account to use that WiKi. Doh.

I plan to investigate all available OS Versions of the Skype API and build a common Python wrapper for it.

Monday, October 23, 2006

Skype API on OS X

Well here's my code so far. It uses pyobjc to fetch the Skype Public API framework and then defines a class to be used as a delegate for the Skype API. Skype is supposed to call the skypeAttachResponse() callback, but that does not happen.

BTW, note the magic in the objc.loadBundle() call ....

Sending messages to the Skype API then results in a log message stating that no client is attached. Doh.

Calling isSkypeRunning() et al works, so I'm actually pretty sure that I'm talking to the Skype API ;)

Any pointers would be greatly appreciated ;)

Update: I noticed that the signature of the callback methods of my Python Delegator class is probably not correct. I'll investigate further. There are pointers to that inside the PyObjC docs.

import objc
from Foundation import *

objc.loadBundle( "SkypeAPI", globals(),
bundle_path=objc.pathForFramework( \
"
~/Library/Frameworks/Skype.framework" ) )

#objc.setSignatureForSelector( "SkypeAPI",
# "sendSkypeCommand:", "v@N^@:@" )

SkypeAPIDelegate = objc.protocolNamed( "SkypeAPIDelegate" )

class Delegate(NSObject, SkypeAPIDelegate):
def init(self, app_name):
self = super( Delegate, self).init()
if self is None:
return None

self._appname = app_name

return self

def clientApplicationName( self ):
return self._appname

def skypeAttachResponse( self, code ):
NSLog( "skypeAttachResponse: %d" % ( code ) )

def skypeNotificationReceived( self, nsstring ):
NSLog( "skypeNotificationReceivest: %s" % ( nsstring ) )

def skypeBecameAvailable( self, notification ):
NSLog( "skypeBecameAvailable: %s" % ( notification ) )

def skypeBecameUnavailable( self, notification ):
NSLog( "skypeBecameUnavailable: %s" % ( notification ) )

def do_connect():
delegate = Delegate.alloc().init( "testapp" )

NSLog( "connecting to skype" )
SkypeAPI.setSkypeDelegate_( delegate )
SkypeAPI.connect()

NSLog( "sending" )
SkypeAPI.sendSkypeCommand_( u"PROTOCOL 1" )

def main():
import sys
from PyObjCTools import AppHelper

NSLog( "running event loop" )
AppHelper.callLater( 5, do_connect )
AppHelper.runConsoleEventLoop( installInterrupt=True )

if __name__ == "__main__":
main()

# vim: set ts=4 sw=4 expandtab :


Note: I love Vim ;)

Embedding Python and Multithreading

Just found this post on comp.lang.python about an article detailing the hoops one needs to jump through when it comes to embedding python and you have a multithreaded application.

Note that all that still means that you can't have one Python interpreter running in multiple threads. If I understood things as they are, Python currently needs a 1:1 relationship between Python interpreters and threads. That is, you can have more than one Python interpreter per process but only one per thread. You can have more than one interpreter per process if you really want, but these threads then compete against the same GIL.

This is due to the fact that the standard CPython implementation uses a so-called global interpreter lock (GIL) to serialize access to the internal Python API. There's one GIL per interpreter.

Also note that there's hidden pitfall here: The interpreter periodically (every n byte code instructions) yields execution and releases the GIL. That means if other threads pend on the GIL they might get runnable, which is perhaps not what one might expect.

Calling C extension is another common way to release the GIL, such that a expensive calculation in does not block other threads.