Re: [Pyobjc-dev] 0.9
Brought to you by:
ronaldoussoren
From: Tony L. <to...@lo...> - 2003-02-02 20:26:50
|
At 8:27 PM +0100 2/2/03, Just van Rossum wrote: > >I see no reason to not simply include the actual modules in Resources. >Perhaps that's handy for PB, but then again, I don't use PB. Well, I can posit a few useful scenarios for being able to use .pth files in Resources, such as including a CVS controlled directory of external Python source like I am doing with spambayes, but until there's an actual problem (and there's not) I'll shut up. Speaking of app wrappers, below is a bin-python-main.m that will load a framework build of python. It seems to load faster than using the execve methods... -Tony /* This main file runs Contents/Resource/__main__.py using a framework build of python */ #import <Foundation/Foundation.h> #import <Python/Python.h> #import <sys/param.h> #import <unistd.h> #import <stdio.h> int pyobjc_main(int argc, char * const *argv, char * const *envp) { // The autorelease pool is not released on purpose, because I don't know much // about objc memory management [[NSAutoreleasePool alloc] init]; // set up paths const char *mainPyFile = [[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @"__main__.py"] UTF8String]; printf("mainPyFile=%s\n", mainPyFile); Py_SetProgramName(mainPyFile); Py_Initialize(); argv[0] = mainPyFile; // PySys_SetArgv wants script in argv PySys_SetArgv(argc, argv); FILE *fp = fopen(mainPyFile, "r"); if (fp == NULL) { perror("Cannot open mainPyFile"); } else { PyRun_SimpleFile(fp, mainPyFile); fclose(fp); } Py_Finalize(); return 0; } int main(int argc, char * const *argv, char * const *envp) { return pyobjc_main(argc, argv, envp); } |