[Numpy-svn] r3959 - branches/1.0.3.x/numpy/distutils

numpy-svn@scip... numpy-svn@scip...
Fri Aug 10 02:57:15 CDT 2007


Author: jarrod.millman
Date: 2007-08-10 02:57:02 -0500 (Fri, 10 Aug 2007)
New Revision: 3959

Modified:
   branches/1.0.3.x/numpy/distutils/misc_util.py
Log:
adding back get_path, which is used by Lib/odr/setup.py in scipy 0.5.2


Modified: branches/1.0.3.x/numpy/distutils/misc_util.py
===================================================================
--- branches/1.0.3.x/numpy/distutils/misc_util.py	2007-08-10 06:07:55 UTC (rev 3958)
+++ branches/1.0.3.x/numpy/distutils/misc_util.py	2007-08-10 07:57:02 UTC (rev 3959)
@@ -40,6 +40,31 @@
         path = apath[len(pd)+1:]
     return path
 
+def get_path(mod_name, parent_path=None):
+    """ Return path of the module.
+
+    Returned path is relative to parent_path when given,
+    otherwise it is absolute path.
+    """
+    if mod_name == '__builtin__':
+        #builtin if/then added by Pearu for use in core.run_setup.
+        d = os.path.dirname(os.path.abspath(sys.argv[0]))
+    else:
+        __import__(mod_name)
+        mod = sys.modules[mod_name]
+        if hasattr(mod,'__file__'):
+            filename = mod.__file__
+            d = os.path.dirname(os.path.abspath(mod.__file__))
+        else:
+            # we're probably running setup.py as execfile("setup.py")
+            # (likely we're building an egg)
+            d = os.path.abspath('.')
+            # hmm, should we use sys.argv[0] like in __builtin__ case?
+
+    if parent_path is not None:
+        d = rel_path(d, parent_path)
+    return d or '.'
+
 def get_path_from_frame(frame, parent_path=None):
     """ Return path of the module given a frame object from the call stack.
 



More information about the Numpy-svn mailing list