[Distutils] [ANN] pkgdata

Bob Ippolito bob at redivi.com
Thu Mar 25 11:11:34 EST 2004


As per the BOF last night, here is the pkgdata module that I mentioned. 
  Currently the only project using it is pygame.  The "sys.datapath" 
mechanism that I talked about *could actually be implemented* on top of 
this system, supposing an appropriate adapter was written to support 
it!  Remember:  pkgdata is *just a hook*.  It doesn't do anything other 
give the eventual option of doing something smarter than 
os.path.join(os.path.basedir(__file__), data).  When you figure out 
what something smarter is, or you change your mind about what the 
smarter solution is (inside of an app bundle vs. system wide install, 
etc.), you don't have to refactor any of the code that uses pkgdata.

The current implementation, and documentation, is here:

http://undefined.org/python/pkgdata-0.1.tgz

"""
pkgdata is a simple, extensible way for a package to acquire data file 
resources.

The implementation is lightweight, and is intended to be included 
*inside*
your Python packages.
"""

It's based on PyProtocols (but the implementation doesn't require it 
unless you want to override the default mechanism).  Basically, it's 
useful for py2exe and OS X bundlebuilder type situations.  It's a 
simple and flexible alternative to 
os.path.join(os.path.dirname(__file__), "myresource").  The source is 
simple, and has lots of examples.  Read if you're interested.

If you would like to see additional examples of its use, here are the 
interesting things to look at if you check out pygame CVS:
	pygame/lib/pkgdata.py (this is the pkgdata "client")
	pygame/lib/macosx.py (usage from python)
	pygame/src/font.c (usage from C)
	pygame/src/display.c (more usage from C)
	pygame/examples/macosx/aliens_app_example/ (this has the pkgdata "host 
adapter" for bundlebuilder type situations)

The fact that it uses PyProtocols is just personal preference.  It 
could work on top of any sort of global registry, but PyProtocols is a 
really nice global registry that made my implementation extremely 
terse.

-bob




More information about the Distutils-SIG mailing list