From: <th...@us...> - 2003-10-10 19:23:57
|
Update of /cvsroot/py2exe/py2exe/sandbox/source In directory sc8-pr-cvs1:/tmp/cvs-serv25849 Modified Files: start.c Log Message: Clean up the use of env vars. Now, the built exe shouldn't depend on any of the standard Python environment variables anymore at the start. The exe can, howevere, set PYTHONINSPECT, and an interactive interpreter will be run when the script finishes. Also, there's a PY2EXEVERBOSE variable which corresponds to the PYTHONVERBOSE Python variable. Reformatted some code from Mark to my own style <wink>. Index: start.c =================================================================== RCS file: /cvsroot/py2exe/py2exe/sandbox/source/start.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** start.c 16 Sep 2003 08:29:04 -0000 1.8 --- start.c 10 Oct 2003 19:23:50 -0000 1.9 *************** *** 135,143 **** _putenv ("PYTHONSTARTUP="); _putenv ("PYTHONOPTIMIZE="); ! if (getenv("PY2EXEVERBOSE")) _putenv ("PYTHONVERBOSE=1"); else ! _putenv ("PYTHONVERBOSE"); if (p_script_info->unbuffered) --- 135,145 ---- _putenv ("PYTHONSTARTUP="); _putenv ("PYTHONOPTIMIZE="); + _putenv ("PYTHONDEBUG="); + _putenv("PYTHONINSPECT="); ! if (getenv("PY2EXEVERBOSE")) _putenv ("PYTHONVERBOSE=1"); else ! _putenv ("PYTHONVERBOSE="); if (p_script_info->unbuffered) *************** *** 145,150 **** else _putenv ("PYTHONUNBUFFERED="); - - _putenv ("PYTHONDEBUG="); } --- 147,150 ---- *************** *** 152,157 **** Py_OptimizeFlag = p_script_info->optimize; - // Py_VerboseFlag = p_script_info->verbose; - /* XXX Is this correct? For the dll server code? */ /* And we should probably change all the above code if Python is already --- 152,155 ---- *************** *** 164,175 **** /* cause python to calculate the path */ Py_GetPath(); ! /* Set sys.frozen so apps that care can tell. Custom environments may */ ! /* set this later to a 'better' value (eg, COM dlls get 'dll') */ ! PySys_SetObject("frozen", Py_True); /* clean up the environment so that os.system and os.popen processes can run python the normal way */ ! _putenv( "PYTHONPATH=" ); ! _putenv ("PYTHONUNBUFFERED="); ! return 0; } --- 162,175 ---- /* cause python to calculate the path */ Py_GetPath(); ! /* Set sys.frozen so apps that care can tell. Custom environments may */ ! /* set this later to a 'better' value (eg, COM dlls get 'dll') */ ! PySys_SetObject("frozen", Py_True); /* clean up the environment so that os.system and os.popen processes can run python the normal way */ ! /* Hm, actually it would be better to set them to values saved before ! changing them ;-) */ ! _putenv("PYTHONPATH="); ! _putenv("PYTHONUNBUFFERED="); ! _putenv("PYTHONVERBOSE="); return 0; } *************** *** 182,185 **** --- 182,190 ---- void fini(void) { + /* The standard Python 2.3 does also allow this: Set PYTHONINSPECT + in the script and examine it afterwards + */ + if (getenv("PYTHONINSPECT") && Py_FdIsInteractive(stdin, "<stdin>")) + PyRun_InteractiveLoop(stdin, "<stdin>"); /* Clean up */ Py_Finalize(); *************** *** 208,232 **** rc = PyRun_SimpleString(buffer); if (rc == 0) { ! /* load the code objects to execute */ ! PyObject *m=NULL, *d=NULL, *seq=NULL; ! /* We execute then in the context of '__main__' */ ! m = PyImport_AddModule("__main__"); ! if (m) d = PyModule_GetDict(m); ! if (d) seq = PyMarshal_ReadObjectFromString(pScript, numScriptBytes); ! if (seq) { ! int i, max = PySequence_Length(seq); ! for (i=0;i<max;i++) { ! PyObject *sub = PySequence_GetItem(seq, i); ! if (sub && PyCode_Check(sub)) { ! PyObject *discard = PyEval_EvalCode((PyCodeObject *)sub, ! d, d); ! if (!discard) ! PyErr_Print(); ! Py_XDECREF(discard); ! /* keep going even if we fail */ ! } ! Py_XDECREF(sub); ! } } } return rc; --- 213,237 ---- rc = PyRun_SimpleString(buffer); if (rc == 0) { ! /* load the code objects to execute */ ! PyObject *m=NULL, *d=NULL, *seq=NULL; ! /* We execute then in the context of '__main__' */ ! m = PyImport_AddModule("__main__"); ! if (m) d = PyModule_GetDict(m); ! if (d) seq = PyMarshal_ReadObjectFromString(pScript, numScriptBytes); ! if (seq) { ! int i, max = PySequence_Length(seq); ! for (i=0;i<max;i++) { ! PyObject *sub = PySequence_GetItem(seq, i); ! if (sub && PyCode_Check(sub)) { ! PyObject *discard = PyEval_EvalCode((PyCodeObject *)sub, ! d, d); ! if (!discard) ! PyErr_Print(); ! Py_XDECREF(discard); ! /* keep going even if we fail */ } + Py_XDECREF(sub); + } + } } return rc; |
From: Mark H. <mha...@sk...> - 2003-10-13 03:30:59
|
> Reformatted some code from Mark to my own style <wink>. ... > *************** > *** 208,232 **** > rc = PyRun_SimpleString(buffer); > if (rc == 0) { > ! /* load the code objects to execute */ ... > --- 213,237 ---- > rc = PyRun_SimpleString(buffer); > if (rc == 0) { > ! /* load the code objects to execute */ ... Oh - I didn't realize mixing of tabs and spaces was *intentional* <wink> Mark. |