[Python-3000-checkins] r58224 - in python/branches/py3k-importlib: Include/pythonrun.h Modules/getpath.c NEWS

brett.cannon python-3000-checkins at python.org
Fri Sep 21 03:38:18 CEST 2007


Author: brett.cannon
Date: Fri Sep 21 03:38:17 2007
New Revision: 58224

Modified:
   python/branches/py3k-importlib/Include/pythonrun.h
   python/branches/py3k-importlib/Modules/getpath.c
   python/branches/py3k-importlib/NEWS
Log:
Added Py_GetImportlibPath() in order to get the path to _importlib easily.


Modified: python/branches/py3k-importlib/Include/pythonrun.h
==============================================================================
--- python/branches/py3k-importlib/Include/pythonrun.h	(original)
+++ python/branches/py3k-importlib/Include/pythonrun.h	Fri Sep 21 03:38:17 2007
@@ -106,6 +106,7 @@
 PyAPI_FUNC(char *) Py_GetProgramFullPath(void);
 PyAPI_FUNC(char *) Py_GetPrefix(void);
 PyAPI_FUNC(char *) Py_GetExecPrefix(void);
+PyAPI_FUNC(char *) Py_GetImportlibPath(void);
 PyAPI_FUNC(char *) Py_GetPath(void);
 
 /* In their own files */

Modified: python/branches/py3k-importlib/Modules/getpath.c
==============================================================================
--- python/branches/py3k-importlib/Modules/getpath.c	(original)
+++ python/branches/py3k-importlib/Modules/getpath.c	Fri Sep 21 03:38:17 2007
@@ -127,6 +127,7 @@
 
 static char prefix[MAXPATHLEN+1];
 static char exec_prefix[MAXPATHLEN+1];
+static char importlib_path[MAXPATHLEN+1];
 static char progpath[MAXPATHLEN+1];
 static char *module_search_path = NULL;
 static char lib_python[] = "lib/python" VERSION;
@@ -269,6 +270,10 @@
             *delim = '\0';
         joinpath(prefix, lib_python);
         joinpath(prefix, LANDMARK);
+	if (ismodule(prefix))
+		strcpy(importlib_path, prefix);
+	else
+		importlib_path[0] = '\0';
         return 1;
     }
 
@@ -282,8 +287,10 @@
         joinpath(prefix, vpath);
         joinpath(prefix, "Lib");
         joinpath(prefix, LANDMARK);
-        if (ismodule(prefix))
+        if (ismodule(prefix)) {	
+            strcpy(importlib_path, prefix);
             return -1;
+        }
     }
 
     /* Search from argv0_path, until root is found */
@@ -292,8 +299,10 @@
         n = strlen(prefix);
         joinpath(prefix, lib_python);
         joinpath(prefix, LANDMARK);
-        if (ismodule(prefix))
+        if (ismodule(prefix)) {
+            strcpy(importlib_path, prefix);
             return 1;
+        }
         prefix[n] = '\0';
         reduce(prefix);
     } while (prefix[0]);
@@ -302,10 +311,13 @@
     strncpy(prefix, PREFIX, MAXPATHLEN);
     joinpath(prefix, lib_python);
     joinpath(prefix, LANDMARK);
-    if (ismodule(prefix))
+    if (ismodule(prefix)) {
+        strcpy(importlib_path, prefix);
         return 1;
+    }
 
     /* Fail */
+    importlib_path[0] = '\0';
     return 0;
 }
 
@@ -680,6 +692,14 @@
 }
 
 char *
+Py_GetImportlibPath(void)
+{
+    if (!module_search_path)
+        calculate_path();
+    return importlib_path;
+}
+
+char *
 Py_GetProgramFullPath(void)
 {
     if (!module_search_path)

Modified: python/branches/py3k-importlib/NEWS
==============================================================================
--- python/branches/py3k-importlib/NEWS	(original)
+++ python/branches/py3k-importlib/NEWS	Fri Sep 21 03:38:17 2007
@@ -1,2 +1,4 @@
+* Add Py_GetImportlibPath() as a way to get the path to _importlib.
+
 * Have Modules/getpath.c use _importlib.py instead of os.py when searching for
   Python's stdlib directory.


More information about the Python-3000-checkins mailing list