My app reads some of its core structures from a set of
RDF files. I have been keeping the RDF files in a directory
within the distribution, but it would be okay to have them in
my app's home directory, say ~/.my_app, when the package is
installed or when the user starts it up (the latter probably
making the most sense on systems that are designed to be
multi-user), but haven't yet got either way to work with
py2app.
The new setuptools' pkg_resources API looked pretty good,
so I'm using it to pull data out of the RDF files with
'resource_stream'. It works in my development environment
on Linux that has been configured with 'setup.py development',
and it also works on the Macintosh that way -- i.e.,
running the script in the development environment, where it
can find the RDF files. But it doesn't work when I make
a package using py2app.
(I fudged it on mswin by having the Innosetup
installer copy the files to the user's home directory
and then finding the home directory at startup.)
py2app's '--resources' option seems like what I need,
but I can't seem to figure out the proper incantation,
because when the app starts up I immediately get an
error message that the files can't be found.
I've attached the setup.py I'm using. Below is an
excerpt from my code that uses resource_stream, which
works fine when the files are in the place indicated.
Any suggestions? (I did give the kb directory an
__init__.py, even though there are no modules in it, and
even tried putting the files into an __all__, but it had
no effect on py2app.)
Thanks!
Steve
-----------------------------------------------------
kbres = {'pgef' : resource_stream('pangalactic', 'meta/kb/pgef.owl'),
'pgef_meta' : resource_stream(
'pangalactic', 'meta/kb/pgef_meta.owl'),
'owl' : resource_stream('pangalactic', 'meta/kb/owl.rdf'),
'rdf' : resource_stream('pangalactic', 'meta/kb/rdf.rdf'),
'rdfs' : resource_stream('pangalactic', 'meta/kb/rdfs.rdf')
}
kb = KB(kbdata=kbres)
"""
py2app/py2exe build script for PanGalaxian.
Usage (Mac OS X):
python setup.py py2app
Usage (Windows):
python setup.py py2exe
@version: $Revision: 1.8 $
"""
__version__ = '$Revision: 1.8 $'[11:-2]
from ez_setup import use_setuptools
use_setuptools()
from setuptools import setup
import datetime
import os
import sys
if sys.platform == 'win32':
import py2exe
extra_options=dict(
windows=['pangalactic/node/pangalaxian.py'],
setup_requires=['py2exe'],
options=dict(
py2exe=dict(
includes=[
# need this because rdflib plugin stuff confuses py2exe
'rdflib.*',
'rdflib.store.*',
'rdflib.store.FOPLRelationalModel.*',
'rdflib.syntax.*',
'rdflib.syntax.parsers.*',
'rdflib.syntax.parsers.n3p.*',
'rdflib.syntax.serializers.*'
],
ignores=[
'wx.BitmapFromImage',
'wx.EmptyIcon',
'MySQLdb',
'mx',
'mxDateTime',
'Parser',
'Persistence',
'RDF',
'_pybsddb',
'pydot',
'pysqlite2',
'rdflib.backends.Sleepycat',
'sqlobject'
],
packages=['encodings']
)
)
)
elif sys.platform == 'darwin':
extra_options=dict(
setup_requires=['py2app'],
app=['pangalactic/node/pangalaxian.py'],
options=dict(
py2app=dict(
argv_emulation=True,
includes=[
# need this because rdflib plugin stuff confuses py2exe
'rdflib.*',
'rdflib.store.*',
'rdflib.store.FOPLRelationalModel.*',
'rdflib.syntax.*',
'rdflib.syntax.parsers.*',
'rdflib.syntax.parsers.n3p.*',
'rdflib.syntax.serializers.*'
],
excludes=[
'wx.BitmapFromImage',
'wx.EmptyIcon',
'MySQLdb',
'mx',
'mxDateTime',
'Parser',
'Persistence',
'RDF',
'_pybsddb',
'pydot',
'pysqlite2',
'rdflib.backends.Sleepycat',
'sqlobject'
],
packages=['encodings'],
resources=[
'pangalactic/meta/kb/pgef.owl',
'pangalactic/meta/kb/pgef_meta.owl',
'pangalactic/meta/kb/rdf.rdf',
'pangalactic/meta/kb/rdfs.rdf',
'pangalactic/meta/kb/owl.rdf'
]
))
)
else: # unix-like platforms (use "setup.py install")
extra_options=dict(
scripts=['pangalactic/node/pangalaxian.py']
)
VERSION = open('VERSION').read()
VERSION = VERSION[:-1]
dt = datetime.datetime.now()
dtstamp = ''.join([str(x) for x in (dt.year, dt.month, dt.day)])
if 'dev' not in VERSION:
version = VERSION
else:
version = '-'.join([VERSION, dtstamp])
if sys.platform == 'win32':
version = '.'.join(VERSION.split('.')[:-1])
setup(name='PanGalaxian',
version=version,
description='PanGalaxian: to infinity, and beyond!',
author='Stephen Waterbury',
author_email='[EMAIL PROTECTED]',
maintainer='Stephen Waterbury',
maintainer_email='[EMAIL PROTECTED]',
url='http://pangalactic.us',
license='MIT',
packages=[
'pangalactic',
'pangalactic.core',
'pangalactic.meta',
'pangalactic.meta.kb',
'pangalactic.node',
'pangalactic.node.gui',
'pangalactic.node.gui.dialogs',
'pangalactic.node.gui.utils',
'pangalactic.node.gui.widgets',
'pangalactic.node.images',
'pangalactic.test',
'pangalactic.utils',
'pangalactic.utils.io',
],
data_files=[('pangalactic/meta/kb', [
'pangalactic/meta/kb/pgef.owl',
'pangalactic/meta/kb/pgef_meta.owl',
'pangalactic/meta/kb/rdf.rdf',
'pangalactic/meta/kb/rdfs.rdf',
'pangalactic/meta/kb/owl.rdf'
]),
('', ['src/icons/pangalacticon.ico']),
('data', []),
('plugins/owl', [])],
**extra_options
)
_______________________________________________
Pythonmac-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/pythonmac-sig