Update of /cvsroot/py2exe/py2exe/source
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18740/source
Modified Files:
import-tab.c import-tab.h mktab.py start.c
Log Message:
Index: import-tab.c
===================================================================
RCS file: /cvsroot/py2exe/py2exe/source/import-tab.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** import-tab.c 7 Sep 2005 06:16:18 -0000 1.4
--- import-tab.c 13 Feb 2006 13:17:22 -0000 1.5
***************
*** 54,55 ****
--- 54,56 ----
{ "Py_NoSiteFlag", NULL },
{ "Py_OptimizeFlag", NULL },
+ { "Py_IgnoreEnvironmentFlag", NULL },
Index: start.c
===================================================================
RCS file: /cvsroot/py2exe/py2exe/source/start.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** start.c 2 Dec 2005 05:46:16 -0000 1.30
--- start.c 13 Feb 2006 13:17:22 -0000 1.31
***************
*** 241,244 ****
--- 241,295 ----
}
+ static int set_path()
+ {
+ /* If the zip path has any path component, then build our Python
+ home directory from that.
+ */
+ char *fname;
+ int lib_dir_len;
+ char *ppath;
+ pZipBaseName = pScript - 1;
+ /* let pZipBaseName point to the basename of the zippath */
+ while (pZipBaseName > p_script_info->zippath && \
+ *(pZipBaseName-1) != '\\')
+ pZipBaseName--;
+ /* dirname is the directory of the executable */
+ strcpy(libdirname, dirname);
+ /* length of lib director name */
+ lib_dir_len = pZipBaseName-p_script_info->zippath; /* incl. tail slash */
+ if (lib_dir_len) {
+ char *p = libdirname+strlen(libdirname);
+ *p++ = '\\';
+ strncpy(p, p_script_info->zippath, lib_dir_len-1);
+ p += lib_dir_len-1;
+ *p++ = '\0';
+ }
+ /* Fully-qualify it */
+ GetFullPathName(libdirname, sizeof(libdirname), libdirname, &fname);
+
+ Py_SetPythonHome(libdirname);
+ /* Let Python calculate its initial path, according to the
+ builtin rules */
+ ppath = Py_GetPath();
+ // printf("Initial path: %s\n", ppath);
+
+ /* HACK: We don't like so rules.
+ We know that Py_GetPath points to writeable memory,
+ so we copy our own path into it.
+ */
+ if (strlen(ppath) <= strlen(libdirname) + strlen(pZipBaseName) + 1) {
+ /* Um. Not enough space. What now? */
+ fprintf(stderr, "NOT ENOUGH SPACE for PATH\n");
+ return -1;
+ }
+
+ strcpy(ppath, libdirname);
+ strcat(ppath, "\\");
+ strcat(ppath, pZipBaseName);
+ return 0;
+ }
+
+
+
/*
* returns an error code if initialization fails
***************
*** 246,249 ****
--- 297,301 ----
int init_with_instance(HMODULE hmod, char *frozen)
{
+ int rc;
if (!_LocateScript(hmod))
return 255;
***************
*** 251,308 ****
if (!_LoadPythonDLL(hmod))
return 255;
- if (getenv("PY2EXE_VERBOSE")) {
- Py_VerboseFlag = atoi(getenv("PY2EXE_VERBOSE"));
- } else
- Py_VerboseFlag = 0;
-
- {
- /* If the zip path has any path component, then build our Python
- home directory from that.
- */
- char *fname;
- int lib_dir_len;
- pZipBaseName = pScript - 1;
- /* let pZipBaseName point to the basename of the zippath */
- while (pZipBaseName > p_script_info->zippath && \
- *(pZipBaseName-1) != '\\')
- pZipBaseName--;
- /* dirname is the directory of the executable */
- strcpy(libdirname, dirname);
- /* length of lib director name */
- lib_dir_len = pZipBaseName-p_script_info->zippath; /* incl. tail slash */
- if (lib_dir_len) {
- char *p = libdirname+strlen(libdirname);
- *p++ = '\\';
- strncpy(p, p_script_info->zippath, lib_dir_len-1);
- p += lib_dir_len-1;
- *p++ = '\0';
- }
- /* Fully-qualify it */
- GetFullPathName(libdirname, sizeof(libdirname), libdirname, &fname);
- }
- /* From Barry Scott */
- /* Must not set the PYTHONHOME env var as this prevents
- python being used in os.system or os.popen */
- Py_SetPythonHome(libdirname);
-
- /*
- * PYTHONPATH entries will be inserted in front of the
- * standard python path.
- */
- /*
- * We need the module's directory, because zipimport needs zlib.pyd.
- * And, of course, the zipfile itself.
- */
- {
- char buffer[_MAX_PATH * 3 + 256];
- sprintf(buffer, "PYTHONPATH=%s;%s\\%s",
- libdirname, libdirname, pZipBaseName);
- _putenv (buffer);
- }
- _putenv ("PYTHONSTARTUP=");
- _putenv ("PYTHONOPTIMIZE=");
- _putenv ("PYTHONDEBUG=");
- _putenv("PYTHONINSPECT=");
-
if (p_script_info->unbuffered) {
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
--- 303,306 ----
***************
*** 321,338 ****
}
Py_NoSiteFlag = 1;
Py_OptimizeFlag = p_script_info->optimize;
- /* XXX Is this correct? For the dll server code? */
- /* And we should probably change all the above code if Python is already
- * initialized */
Py_SetProgramName(modulename);
! Py_Initialize();
! /* From Barry Scott */
! /* cause python to calculate the path */
! Py_GetPath();
/* Set sys.frozen so apps that care can tell.
If the caller did pass NULL, sys.frozen will be set zo True.
--- 319,341 ----
}
+ if (getenv("PY2EXE_VERBOSE"))
+ Py_VerboseFlag = atoi(getenv("PY2EXE_VERBOSE"));
+ else
+ Py_VerboseFlag = 0;
+ Py_IgnoreEnvironmentFlag = 1;
Py_NoSiteFlag = 1;
Py_OptimizeFlag = p_script_info->optimize;
Py_SetProgramName(modulename);
! rc = set_path();
! if (rc != 0)
! return rc;
! // printf("Path before Py_Initialize(): %s\n", Py_GetPath());
!
! Py_Initialize();
! // printf("Path after Py_Initialize(): %s\n", Py_GetPath());
/* Set sys.frozen so apps that care can tell.
If the caller did pass NULL, sys.frozen will be set zo True.
***************
*** 353,362 ****
_TryLoadZlib(hmod);
- /* 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("PYTHONVERBOSE=");
return 0;
}
--- 356,359 ----
***************
*** 389,421 ****
int run_script(void)
{
! int rc;
char buffer[_MAX_PATH * 3];
! snprintf(buffer, sizeof(buffer),
! "import sys; sys.path=[r\"\"\"%s\\%s\"\"\"]; del sys",
! libdirname, pZipBaseName);
! 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();
! rc = 255;
! }
! Py_XDECREF(discard);
! /* keep going even if we fail */
}
! Py_XDECREF(sub);
}
}
}
--- 386,413 ----
int run_script(void)
{
! int rc = 0;
char buffer[_MAX_PATH * 3];
!
! /* 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();
! rc = 255;
}
! Py_XDECREF(discard);
! /* keep going even if we fail */
}
+ Py_XDECREF(sub);
}
}
Index: mktab.py
===================================================================
RCS file: /cvsroot/py2exe/py2exe/source/mktab.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** mktab.py 7 Sep 2005 06:16:18 -0000 1.4
--- mktab.py 13 Feb 2006 13:17:22 -0000 1.5
***************
*** 57,60 ****
--- 57,61 ----
int, Py_NoSiteFlag
int, Py_OptimizeFlag
+ int, Py_IgnoreEnvironmentFlag
'''.strip().splitlines()
Index: import-tab.h
===================================================================
RCS file: /cvsroot/py2exe/py2exe/source/import-tab.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** import-tab.h 6 Sep 2005 19:26:41 -0000 1.3
--- import-tab.h 13 Feb 2006 13:17:22 -0000 1.4
***************
*** 50,51 ****
--- 50,52 ----
#define Py_NoSiteFlag (*(int(*))imports[49].proc)
#define Py_OptimizeFlag (*(int(*))imports[50].proc)
+ #define Py_IgnoreEnvironmentFlag (*(int(*))imports[51].proc)
|