[Pythonmac-SIG] py2app Enforces Directory Structure?
Bob Ippolito
bob at redivi.com
Wed Dec 22 05:18:29 CET 2004
On Dec 21, 2004, at 10:29 PM, Erik Westra wrote:
> I'm in the process of converting a large wxPython application written
> for MS Windows to run on the Mac. The application itself now works,
> and I'm at the stage of trying to bundle it up using py2app for
> distribution. Unfortunately, it seems that the application's
> directory structure is causing problems for py2app, and after two days
> of mucking about I still can't get it working.
You should've asked sooner. Software that doesn't have [much]
documentation probably means the developer[s] are still working on
things and there may be a rough edge or two :)
> The application has the following overall directory structure:
>
> app/
>
> build/
> setup.py
> build-exe.bat
> ...
>
> framework/
> Framework.py
> main.py
>
> data/
> ...
>
> There are other top-level directories as well, but these are the
> important ones. As you can see the "main.py" file is in the
> "framework" sub-directory, and the application accesses its data files
> using relative paths like "../data/file.dat". All temporary files,
> scripts, etc, which are used to build standalone versions of the
> system are placed into the "build" sub-directory.
"build" sure is a dangerous name to use, considering that it's
typically the name of a scratch directory in Python terms.
> This works well under MS Windows, both for the standalone system and
> when its running in source-code form, and also works fine on the Mac
> when running the source directory -- but I haven't been able to get
> py2app to build this application at all.
You're going to need to change those paths to "data/file.dat". The
data will be inside of your application bundle in the Resources folder,
which will be the current directory on startup.
> It seems that py2app requires that the main.py file and the setup.py
> file are both stired in the top-most directory for the application,
> with other files/modules/packages in sub-directories beneath that
> topmost directory. Is this really the case? If so, it seems like a
> rather major limitation -- surely there must be lots of applications
> that put all their build-related files into a separate sub-directory,
> quite separate from the application's main source files.
setup.py assumes that it can find all of the dependencies via normal
import mechanisms. If you want it to work in your situation, you will
have to add your "frameworks" directory to sys.path before setup(...) -
see below. This sys.path modification will no longer be necessary as
of py2app 0.1.7 (fixed in svn r268).
> Because I need to be able to share one common set of source code
> across multiple platforms, I don't have much choice in terms of
> altering this directory structure -- somehow, I need to get py2app to
> build a standalone Mac application which includes the "Framework.py"
> and "main.py" modules, runs main.py on startup, and stores setup.py
> and all temporary files inside the "build" directory. I don't need to
> include anything else in the application, as the system will store the
> contents of the "data" and other directories outside of the
> application bundle itself.
Don't do that. That's bad. Include the data and any other
dependencies inside the application. Having them external and using an
installer is not the Mac way to do things and I'm not going to help you
do it. There was a similar discussion a while ago (weeks?) and I'm not
going to have it again, so search the archives and argue with the past
if you feel strongly in the other direction :)
> Here's my attempt at creating a "setup.py" file:
>
> from distutils.core import setup
> import py2app
>
> setup(
> app = ["main.py"],
> options={'py2app' :
> {'bdist_base' : "../build/build",
> 'dist_dir' : "../build/dist",
> 'includes' : "Framework"}}
> )
>
> This setup script is stored in the "build" sub-directory, and I access
> it by typing:
>
> cd framework
> python ../build/setup.py py2app
>
> This works in terms of creating a standalone wxPython app that
> includes the "main.py" file, but the "Framework.py" file isn't
> included, and the app fails at the "import Framework" statement within
> "main.py".
That's because py2app 0.1.6 didn't automatically know to look to
siblings of the scripts for additional modules. It does now.
> The only other idea I can think of would be to create aliases to the
> "main.py" and "Framework.py" files, put the aliases into the "build"
> directory, and treat the entire system as if it all resided in a
> single directory. But there must be a better solution than that!
Of course there is :)
> What I really need, I guess, is a way of specifying the source
> directory in which the modules in the "includes" list will be found.
> There doesn't seem to be any such option, though, and including a
> relative pathname in the "includes" list just generates an error when
> I try to build the app.
The includes and excludes lists are Python module identifiers, not path
names. Using a relative path name, anything that has a slash in it, or
anything that starts with a dot or has more than one dot in succession,
is of course an error because those are invalid Python module
identifiers.
----
from distutils.core import setup
import py2app
import sys
# no longer necessary in 0.1.7
sys.path.insert(0, '../framework')
setup(
app = ["../framework/main.py"],
data_files = ['../data'],
)
% cd build
% python setup.py py2app
If you check out py2app trunk
<http://svn.red-bean.com/bob/py2app/trunk> (as of revision 268), then
the sys.path.insert(0, '../framework') is no longer necessary, and
there is an example
<http://svn.red-bean.com/bob/py2app/trunk/examples/structured/setup/
setup.py> that demonstrates the given use case (minus the bad form of
having external data files).
-bob
More information about the Pythonmac-SIG
mailing list