My stumbling path through Python continues... often two steps backwards and three steps forward. I've just about stopped building personal tools in other languages (do shell scripts count?) at this point which leads to interesting problems and discoveries, not always linked one to another.
It all started with wanting to use the feed validator by Mark Pilgrim and Sam Ruby because it's got a reasonable looking model for generic feeds. With the tools history, it seems likely that it'll be extended for future purposes (Atom and others).
After playing with the bountiful included examples, I was able to make it work on a small sample of what I want to do. Cool, let's install this thing. After a bit of fishing around and eventually pulling the sources from CVS just to make sure, I realized that there wasn't a setup.py file. Some sort of licensing thing? A desire not to see it be easily installable? Hell, I didn't know and neither did google or yahoo.
But I did stumble upon a previously unknown packaging mechanism which filled me with hope (for a little while anyway). Danny O'Brien does something interesting in his Life Hacks setup log using a .zip archive. After having a .jar file flashback episode, I went searching and found PEP 273 and PEP 302, which are included in Python 2.3. and ran off to play.
First, I tried it Danny's way and it worked like a charm. Put the feedvalidator package together as an archive in the current path, push it into the path at runtime and all is good. But it has an ugly side; manually loading libraries (especially by path) is prone to failure if you want to share. It has a further drawback, you still have to load it manually to look at the documentation so it's not going to show up if you launch pydoc in server mode which I've been doing.
I hatched a new scheme. If I'd read the docs right, I should be able to put the feedvalidator.zip file in the site-python directory and it should just work. Despite a bunch of fiddling, it doesn't appear that putting an archive in the site-python directory works without some extra mojo. My best guess is that it needs to be registered somehow. Giving up on the simple dream, it seemed best to just create a setup.py file and be done with it. I did (and I'll get to that in a bit) but first I had to take a big detour elsewhere...
I looked at a couple setup.py files for pure Python code and decided that it couldn't possibly be that simple (it really is, more on that later). I looked at the distutils documentation (and found this information about modifying paths) but wasn't yet convinced it was easy. So I went looking for Mark's 'universal' feed parser (and some examples that used it). Where I wound up was reading Python development using the Eclipse IDE and Apache Ant build tool. I guess I missed it entirely the first time around, but having python code in Eclipse and being able to run (and debug it) is awfully neat. Slow, but neat none the less. If they can do some sort of dynamic pydoc thing I'll use it, a lot.
That got me thinking about XCode (2.x). If they bother to add all this stuff (and they're doing a lot of this sort of thing) then they need to be able to learn which source code is where rather than force developers to add things to projects. It's the size 10 purple thumb of XCode projects in groups which use a lot of tools. At a minimum, it needs to be easy to update projects with the twenty new files of the appropriate type that have been added in the last few weeks.
Anyway, I mentioned that creating an install file seemed pretty darned simple (too simple). You need to create a file named setup.py, import setup from distutils.core and add a wee bit of meta data.
This worked for me under Python 2.3 (and should until some major change happens).
#!/usr/bin/env python
#
from distutils.core import setup
setup(
name = 'feedvalidator',
version = '1.4.x',
description = 'Feed validator for RSS 0.9x, RSS 1.0, RSS 2.0, Atom',
long_description = """\
Feed validator
--------------
RSS 0.9x, RSS 1.0, RSS 2.0, Atom
Required: Python 2.1 or later
Recommended: Python 2.3 or later
Recommended: libxml2
""",
author='Mark Pilgrim and Sam Ruby',
url = 'http://feedvalidator.org/',
download_url = 'http://sourceforge.net/projects/feedvalidator/',
license = "Python",
platforms = ['POSIX', 'Windows'],
packages = ['feedvalidator','feedvalidator/formatter','feedvalidator/i18n']
)
Assuming you check out the code from sf.net using CVS or otherwise download it, the contents above go into a file at 'feedvalidator/src/setup.py'. Change directory down into src/ and do the usual:
python setup.py install
That should cover it.
Posted by Dave at January 12, 2005 12:00 AM