Showing posts with label os x. Show all posts
Showing posts with label os x. Show all posts

Thursday, February 12, 2009

Static LXML builds

I've built a recipe for building LXML on OSX boxes statically -- w/o dependencies to libxslt and libxml2.

http://pypi.python.org/pypi/z3c.recipe.staticlxml

This works for quite some people -- please report back if it does'nt work for you (and if it works).

Thursday, June 05, 2008

lxml on OSX -- solved

Hi guys. I've been investigating building lxml on OSX for quite some time now.

Here's the scoop so far:
  • I want to use buildout
  • I want NOT to use Apple's libraries (libxml, libxslt)
  • On OSX there's no "--rpath" option available, thus there's no way to tell an executable on link time where to look for dynamic libraries
  • This is disgusting (do we have 2008 or what?)
Ok, that's what I've come up with. Note the z3c.recipe.egg, it allows for arguments to the setup script, which the original zc.recipe.egg does not. The version 2.0.6 of lxml has a fix for OSX in, which allows to do away with DYLD_LIBRARY_PATH, BUT you need a DYLD_FORCE_FLAT_NAMESPACE=1. Don't ask. I have no idea.
[lxml]
parts=
libxml2
libxslt
lxml-download
lxml-build

[libxml2]
recipe = zc.recipe.cmmi
url = http://ftp.gnome.org/pub/GNOME/sources/libxml2/2.6/libxml2-2.6.26.tar.gz
extra_options = --without-python

[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-download]
recipe = plone.recipe.distros
urls = http://codespeak.net/lxml/lxml-2.0.6.tgz
version-suffix-packages = lxml-2.0.6.tgz

[lxml-build]
recipe = z3c.recipe.egg:setup
setup = ${lxml-download:location}/lxml
args =
clean
build
bdist_egg
--with-xslt-config=${buildout:directory}/parts/libxslt/bin/xslt-config
develop = true

You use it like:

[buildout]
extends=
lxml.cfg
parts=
${lxml:parts}
eggs=
${lxml:eggs}

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)

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.

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 ;)